Lecture5
Lecture5
Announcements
• Programming Assignment 1 is due on Monday!
• Details:
https://www.cs.rochester.edu/courses/252/spring2021/la
bs/assignment1.html
• Due on Sep. 16th, 11:59 PM
• You have 3 slip days
2
Carnegie Mellon
1 8-bit 23-bit
1 11-bit 52-bit
• In C language
•float single precision
•double double precision
3
Carnegie Mellon
{
char 8 27 - 1 127
short 16 215 - 1 32767
Fixed point
int 32 231 - 1 2147483647
(implicit binary point)
long 64 263 - 1 ~9.2 × 1018
4
Carnegie Mellon
{
char 8 27 - 1 127
short 16 215 - 1 32767
Fixed point
int 32 231 - 1 2147483647
(implicit binary point)
long 64 263 - 1 ~9.2 × 1018
5
Carnegie Mellon
•int → float
•
s exp frac
1 8-bit 23-bit
5
Carnegie Mellon
•int → float
• Can’t guarantee exact casting. Will round according to rounding mode
s exp frac
1 8-bit 23-bit
5
Carnegie Mellon
•int → float
• Can’t guarantee exact casting. Will round according to rounding mode
s exp frac
1 8-bit 23-bit
• int → double
•
s exp frac
1 11-bit 52-bit
5
Carnegie Mellon
•int → float
• Can’t guarantee exact casting. Will round according to rounding mode
s exp frac
1 8-bit 23-bit
• int → double
• Exact conversion
s exp frac
1 11-bit 52-bit
5
Carnegie Mellon
So far in 252…
int, float
C Program if, else
+, -, >>
6
Carnegie Mellon
So far in 252…
int, float
C Program if, else
+, -, >>
00001111
Machine
01010101
Code 11110000
6
Carnegie Mellon
So far in 252…
int, float
C Program if, else
+, -, >>
Compiler
ret, call
Assembly fadd, add
Program jmp, jne
00001111
Machine
01010101
Code 11110000
6
Carnegie Mellon
So far in 252…
int, float
C Program if, else
+, -, >>
Semantically
Compiler Equivalent
ret, call
Assembly fadd, add
Program jmp, jne
00001111
Machine
01010101
Code 11110000
6
Carnegie Mellon
So far in 252…
int, float
C Program if, else
+, -, >>
Semantically
Compiler Equivalent
ret, call
Assembly fadd, add
Program jmp, jne
Assembler
00001111
Machine
01010101
Code 11110000
6
Carnegie Mellon
So far in 252…
int, float
C Program if, else
+, -, >>
Semantically
Compiler Equivalent
ret, call
Assembly fadd, add
Program jmp, jne
Semantically
Assembler Equivalent
00001111
Machine
01010101
Code 11110000
6
Carnegie Mellon
So far in 252…
int, float
C Program if, else
+, -, >>
Semantically
Compiler Equivalent
ret, call
Assembly fadd, add
Program jmp, jne
Semantically
Assembler Equivalent
00001111
Machine
01010101
Code 11110000
Fixed-point adder
Processor (e.g., ripple carry),
Floating-point adder
6
Carnegie Mellon
So far in 252…
int, float
C Program if, else
+, -, >>
Semantically
Compiler Equivalent
ret, call
Assembly fadd, add
Program jmp, jne
Semantically
Assembler Equivalent
00001111
Machine
01010101
Code 11110000
Fixed-point adder
Processor (e.g., ripple carry),
Floating-point adder
NAND Gate
Transistor
NOR Gate
6
Carnegie Mellon
So far in 252…
High-Level
C Program
Language
Assembly
Program
Machine
Code
Processor
Transistor
7
Carnegie Mellon
So far in 252…
High-Level
C Program • ISA: Software programmers’
Language view of a computer
• Provide all info for someone wants
to write assembly/machine code
Assembly • “Contract” between
Instruction Set Program assembly/machine code and
processor
Architecture
(ISA) Machine
Code
Processor
Transistor
7
Carnegie Mellon
So far in 252…
High-Level
C Program • ISA: Software programmers’
Language view of a computer
• Provide all info for someone wants
to write assembly/machine code
Assembly • “Contract” between
Instruction Set Program assembly/machine code and
processor
Architecture
(ISA)
• Processors execute machine
Machine code (binary). Assembly
Code program is merely a text
representation of machine
code
Processor
Transistor
7
Carnegie Mellon
So far in 252…
High-Level
C Program • ISA: Software programmers’
Language view of a computer
• Provide all info for someone wants
to write assembly/machine code
Assembly • “Contract” between
Instruction Set Program assembly/machine code and
processor
Architecture
(ISA)
• Processors execute machine
Machine code (binary). Assembly
Code program is merely a text
representation of machine
code
Microarchitecture Processor • Microarchitecture: Hardware
implementation of the ISA (with
the help of circuit technologies)
Circuit Transistor
7
Carnegie Mellon
Circuit Transistor
8
Today: Assembly Programming I: Basics
9
Instruction Set Architecture
• There used to be many ISAs
• x86, ARM, Power/PowerPC, Sparc, MIPS, IA64, z
• Very consolidated today: ARM and x86
10
Instruction Set Architecture
• There used to be many ISAs
• x86, ARM, Power/PowerPC, Sparc, MIPS, IA64, z
• Very consolidated today: ARM and x86
• There are even more microarchitectures
• Apple/Samsung/Qualcomm have their own microarchitecture
(implementation) of the ARM ISA
• Intel and AMD have different microarchitectures for x86
10
Instruction Set Architecture
• There used to be many ISAs
• x86, ARM, Power/PowerPC, Sparc, MIPS, IA64, z
• Very consolidated today: ARM and x86
• There are even more microarchitectures
• Apple/Samsung/Qualcomm have their own microarchitecture
(implementation) of the ARM ISA
• Intel and AMD have different microarchitectures for x86
• ISA is lucrative business: ARM’s Business Model
• Patent the ISA, and then license the ISA
• Every implementer pays a royalty to ARM
• Apple/Samsung pays ARM whenever they sell a smartphone
11
Intel x86 ISA
• Dominate laptop/desktop/cloud market
11
Intel x86 ISA
• Dominate laptop/desktop/cloud market
11
Intel x86 ISA Evolution (Milestones)
• Evolutionary design: Added more features as time goes on
12
Intel x86 ISA Evolution (Milestones)
• Evolutionary design: Added more features as time goes on
Notable
Date Feature
Implementation
13
x86 Clones: Advanced Micro Devices (AMD)
• Historically
• AMD build processors for x86 ISA
• A little bit slower, a lot cheaper
• Then
• Recruited top circuit designers from Digital Equipment Corp. and
other downward trending companies
• Developed x86-64, their own 64-bit x86 extension to IA32
• Built first 1 GHz CPU
14
x86 Clones: Advanced Micro Devices (AMD)
15
x86 Clones: Advanced Micro Devices (AMD)
15
Our Coverage
• IA32
• The traditional x86
• 2nd edition of the textbook
• x86-64
• The standard
• CSUG machine
• 3rd edition of the textbook
• Our focus
16
Moore’s Law
• More instructions typically require more transistors to
implement
17
Moore’s Law
• More instructions typically require more transistors to
implement
17
Moore’s Law
• More instructions typically require more transistors to
implement
17
Moore’s Law
• More instructions require more transistors to implement
18
Moore’s Law
• More instructions require more transistors to implement
• Gordon Moore in 1965 predicted that the number of
transistors doubles every year
18
Moore’s Law
• More instructions require more transistors to implement
• Gordon Moore in 1965 predicted that the number of
transistors doubles every year
18
Moore’s Law
• More instructions require more transistors to implement
• Gordon Moore in 1965 predicted that the number of
transistors doubles every year
18
Moore’s Law
• More instructions require more transistors to implement
• Gordon Moore in 1965 predicted that the number of
transistors doubles every year
18
Moore’s Law
• More instructions require more transistors to implement
• Gordon Moore in 1965 predicted that the number of
transistors doubles every year
• In 1975 he revised the prediction to doubling every 2 years
18
Moore’s Law
• More instructions require more transistors to implement
• Gordon Moore in 1965 predicted that the number of
transistors doubles every year
• In 1975 he revised the prediction to doubling every 2 years
• Today’s widely-known Moore’s Law: number of transistors
double about every 18 months
• Moore never used the number 18…
18
Moore’s Law
• Question: why is transistor count increasing but computers
are becoming smaller?
19
Moore’s Law
• Question: why is transistor count increasing but computers
are becoming smaller?
• Because transistors are becoming smaller
19
Moore’s Law
• Question: why is transistor count increasing but computers
are becoming smaller?
• Because transistors are becoming smaller
• ~1.4x smaller each dimension(1.42 ~ 2)
19
Moore’s Law
• Question: why is transistor count increasing but computers
are becoming smaller?
• Because transistors are becoming smaller
• ~1.4x smaller each dimension(1.42 ~ 2)
• Moore’s Law is:
19
Moore’s Law
• Question: why is transistor count increasing but computers
are becoming smaller?
• Because transistors are becoming smaller
• ~1.4x smaller each dimension(1.42 ~ 2)
• Moore’s Law is:
• A law of physics?
19
Moore’s Law
• Question: why is transistor count increasing but computers
are becoming smaller?
• Because transistors are becoming smaller
• ~1.4x smaller each dimension(1.42 ~ 2)
• Moore’s Law is:
• A law of physics? No
19
Moore’s Law
• Question: why is transistor count increasing but computers
are becoming smaller?
• Because transistors are becoming smaller
• ~1.4x smaller each dimension(1.42 ~ 2)
• Moore’s Law is:
• A law of physics? No
• A law of circuits?
19
Moore’s Law
• Question: why is transistor count increasing but computers
are becoming smaller?
• Because transistors are becoming smaller
• ~1.4x smaller each dimension(1.42 ~ 2)
• Moore’s Law is:
• A law of physics? No
• A law of circuits? No
19
Moore’s Law
• Question: why is transistor count increasing but computers
are becoming smaller?
• Because transistors are becoming smaller
• ~1.4x smaller each dimension(1.42 ~ 2)
• Moore’s Law is:
• A law of physics? No
• A law of circuits? No
• A law of economy?
19
Moore’s Law
• Question: why is transistor count increasing but computers
are becoming smaller?
• Because transistors are becoming smaller
• ~1.4x smaller each dimension(1.42 ~ 2)
• Moore’s Law is:
• A law of physics? No
• A law of circuits? No
• A law of economy? Yes
19
Moore’s Law
• Question: why is transistor count increasing but computers
are becoming smaller?
• Because transistors are becoming smaller
• ~1.4x smaller each dimension(1.42 ~ 2)
• Moore’s Law is:
• A law of physics? No
• A law of circuits? No
• A law of economy? Yes
19
Moore’s Law
• Question: why is transistor count increasing but computers
are becoming smaller?
• Because transistors are becoming smaller
• ~1.4x smaller each dimension(1.42 ~ 2)
• Moore’s Law is:
• A law of physics? No
• A law of circuits? No
• A law of economy? Yes
19
Moore’s Law
• Question: why is transistor count increasing but computers
are becoming smaller?
• Because transistors are becoming smaller
• ~1.4x smaller each dimension(1.42 ~ 2)
• Moore’s Law is:
• A law of physics? No
• A law of circuits? No
• A law of economy? Yes
• A law of psychology?
19
Moore’s Law
• Question: why is transistor count increasing but computers
are becoming smaller?
• Because transistors are becoming smaller
• ~1.4x smaller each dimension(1.42 ~ 2)
• Moore’s Law is:
• A law of physics? No
• A law of circuits? No
• A law of economy? Yes
• A law of psychology? Yes
19
Today: Assembly Programming I: Basics
20
Carnegie Mellon
21
How Does Pointer Work in C???
char a = 4;
char b = 3;
char* c;
c = &a;
b += (*c);
22
How Does Pointer Work in C???
char a = 4; Memory Memory
char b = 3; Content Address
char* c; 0x10
c = &a; 0x11
b += (*c);
…
0x16
22
How Does Pointer Work in C???
char a = 4; Memory Memory
char b = 3; Content Address
char* c; 0x10
c = &a; 0x11
b += (*c);
…
0x16
22
How Does Pointer Work in C???
char a = 4; C Memory Memory
char b = 3; Variable Content Address
char* c; a 4 0x10
c = &a; 0x11
b += (*c);
…
0x16
22
How Does Pointer Work in C???
char a = 4; C Memory Memory
char b = 3; Variable Content Address
char* c; a 4 0x10
c = &a; 0x11
b += (*c);
…
0x16
22
How Does Pointer Work in C???
char a = 4; C Memory Memory
char b = 3; Variable Content Address
char* c; a 4 0x10
c = &a; b 3 0x11
b += (*c);
…
0x16
22
How Does Pointer Work in C???
char a = 4; C Memory Memory
char b = 3; Variable Content Address
char* c; a 4 0x10
c = &a; b 3 0x11
b += (*c);
…
0x16
22
How Does Pointer Work in C???
char a = 4; C Memory Memory
char b = 3; Variable Content Address
char* c; a 4 0x10
c = &a; b 3 0x11
b += (*c);
• The content of a pointer …
variable is memory address.
0x16
22
How Does Pointer Work in C???
char a = 4; C Memory Memory
char b = 3; Variable Content Address
char* c; a 4 0x10
c = &a; b 3 0x11
b += (*c);
• The content of a pointer …
variable is memory address.
c random 0x16
22
How Does Pointer Work in C???
char a = 4; C Memory Memory
char b = 3; Variable Content Address
char* c; a 4 0x10
c = &a; b 3 0x11
b += (*c);
• The content of a pointer …
variable is memory address.
c random 0x16
22
How Does Pointer Work in C???
char a = 4; C Memory Memory
char b = 3; Variable Content Address
char* c; a 4 0x10
c = &a; b 3 0x11
b += (*c);
• The content of a pointer …
variable is memory address.
• The ‘&’ operator (address-of
operator) returns the memory c random 0x16
address of a variable.
…
22
How Does Pointer Work in C???
char a = 4; C Memory Memory
char b = 3; Variable Content Address
char* c; a 4 0x10
c = &a; b 3 0x11
b += (*c);
• The content of a pointer …
variable is memory address.
• The ‘&’ operator (address-of
operator) returns the memory c random
0x10 0x16
address of a variable.
…
22
How Does Pointer Work in C???
char a = 4; C Memory Memory
char b = 3; Variable Content Address
char* c; a 4 0x10
c = &a; b 3 0x11
b += (*c);
• The content of a pointer …
variable is memory address.
• The ‘&’ operator (address-of
operator) returns the memory c random
0x10 0x16
address of a variable.
…
22
How Does Pointer Work in C???
char a = 4; C Memory Memory
char b = 3; Variable Content Address
char* c; a 4 0x10
c = &a; b 3 0x11
b += (*c);
• The content of a pointer …
variable is memory address.
• The ‘&’ operator (address-of
operator) returns the memory c random
0x10 0x16
address of a variable.
• The ‘*’ operator returns the
…
content stored at the memory
location pointed by the pointer
variable (dereferencing)
22
How Does Pointer Work in C???
char a = 4; C Memory Memory
char b = 3; Variable Content Address
char* c; a 4 0x10
c = &a; b 3
7 0x11
b += (*c);
• The content of a pointer …
variable is memory address.
• The ‘&’ operator (address-of
operator) returns the memory c random
0x10 0x16
address of a variable.
• The ‘*’ operator returns the
…
content stored at the memory
location pointed by the pointer
variable (dereferencing)
22
Assembly Code’s View of Computer
23
Assembly Code’s View of Computer
CPU Memory
Assembly
Programmer’s
Perspective
of a Computer
23
Assembly Code’s View of Computer
CPU Memory
Assembly
Programmer’s Code
Data
Perspective Stack
of a Computer
23
Assembly Code’s View of Computer
CPU Memory
Assembly
Programmer’s Code
Data
Perspective Stack
of a Computer
23
Assembly Code’s View of Computer
CPU Memory
Assembly
Programmer’s Code
Data
Perspective Stack
of a Computer
0x53
0x48
0x89
0xd3
23
Assembly Code’s View of Computer
CPU Memory
Assembly
Programmer’s Code
Data
Perspective Stack
of a Computer
0x53
0x48
0x89
0xd3
23
Assembly Code’s View of Computer
CPU Memory
Assembly Register
Programmer’s File Code
Data
Perspective Stack
of a Computer
23
x86-64 Integer Register File
8 Bytes
%rax %r8
%rbx %r9
%rcx %r10
%rdx %r11
%rsi %r12
%rdi %r13
%rsp %r14
%rbp %r15
24
x86-64 Integer Register File
• Lower-half of each register can be independently
addressed (until 1 bytes)
26
x86-64 Integer Register File
• Lower-half of each register can be independently
addressed (until 1 bytes)
%rax
8 Bytes
26
x86-64 Integer Register File
• Lower-half of each register can be independently
addressed (until 1 bytes)
%rax %eax
8 Bytes
4 Bytes
26
x86-64 Integer Register File
• Lower-half of each register can be independently
addressed (until 1 bytes)
8 Bytes
4 Bytes
2 Bytes
26
x86-64 Integer Register File
• Lower-half of each register can be independently
addressed (until 1 bytes)
8 Bytes
4 Bytes
2 Bytes
1B
26
x86-64 Integer Register File
• Lower-half of each register can be independently
addressed (until 1 bytes)
8 Bytes
4 Bytes
C Data Type Size (Bytes)
2 Bytes
char 1
1B
short 2
int 4
long 8
Pointer 8
26
x86-64 Integer Register File
• Lower-half of each register can be independently
addressed (until 1 bytes)
8 Bytes
4 Bytes
C Data Type Size (Bytes)
2 Bytes
char 1
1B
short 2
int 4
Floating point data is stored
long 8 in a separate set of register
Pointer 8 file
26
Assembly Code’s View of Computer
CPU Memory
Assembly Register
Programmer’s File Code
Data
Perspective Stack
of a Computer
27
Assembly Code’s View of Computer
CPU Memory
Assembly Register
Programmer’s PC File Code
Data
Perspective Stack
of a Computer
• Register file
• Faster memory (e.g., 0.5 ns vs. 15 ns)
• Small memory (e.g., 128 B vs. 16 GB)
• Heavily used program data
27
Assembly Code’s View of Computer
CPU Addresses Memory
Assembly Register
Programmer’s PC File Code
Data
Perspective Stack
of a Computer
• Register file
• Faster memory (e.g., 0.5 ns vs. 15 ns)
• Small memory (e.g., 128 B vs. 16 GB)
• Heavily used program data
27
Assembly Code’s View of Computer
CPU Addresses Memory
Assembly Register
Programmer’s PC File Code
Data
Perspective Stack
of a Computer Instructions
• Register file
• Faster memory (e.g., 0.5 ns vs. 15 ns)
• Small memory (e.g., 128 B vs. 16 GB)
• Heavily used program data
27
Assembly Code’s View of Computer
CPU Addresses Memory
Assembly Register
Programmer’s PC File Code
Data Data
Perspective Stack
of a Computer Instructions
• Register file
• Faster memory (e.g., 0.5 ns vs. 15 ns)
• Small memory (e.g., 128 B vs. 16 GB)
• Heavily used program data
27
Assembly Code’s View of Computer
CPU Addresses Memory
Assembly Register
Programmer’s PC File Code
Data Data
Perspective Stack
of a Computer ALU Instructions
27
Assembly Code’s View of Computer
CPU Addresses Memory
Assembly Register
Programmer’s PC File Code
Data Data
Perspective Condition Stack
of a Computer ALU Instructions
Codes
28
Assembly Program Instructions
CPU Addresses Memory
Assembly Register
Programmer’s PC File Code
Data Data
Perspective Condition Stack
of a Computer ALU Instructions
Codes Heap
28
Assembly Program Instructions
CPU Addresses Memory
Assembly Register
Programmer’s PC File Code
Data Data
Perspective Condition Stack
of a Computer ALU Instructions
Codes Heap
28
Assembly Program Instructions
CPU Addresses Memory
Assembly Register
Programmer’s PC File Code
Data Data
Perspective Condition Stack
of a Computer ALU Instructions
Codes Heap
29
Turning C into Object Code
C Code (sum.c) Generated x86-64 Assembly
long plus(long x, long y);
sumstore:
pushq %rbx
void sumstore(long x, long y,
movq %rdx, %rbx
long *dest)
call plus
{
movq %rax, (%rbx)
long t = plus(x, y);
popq %rbx
*dest = t;
ret
}
29
Turning C into Object Code
C Code (sum.c) Generated x86-64 Assembly
long plus(long x, long y);
sumstore:
pushq %rbx
void sumstore(long x, long y,
movq %rdx, %rbx
long *dest)
call plus
{
movq %rax, (%rbx)
long t = plus(x, y);
popq %rbx
*dest = t;
ret
}
29
Turning C into Object Code
Generated x86-64 Assembly Binary Code for sumstore
sumstore: Memory
pushq %rbx
movq %rdx, %rbx 0x53
call plus 0x48
movq %rax, (%rbx) 0x89
popq %rbx 0xd3
ret 0xe8
0xf2
0xff
0xff
0xff
0x48
0x89
0x03
0x5b
0xc3
30
Turning C into Object Code
Generated x86-64 Assembly Binary Code for sumstore
sumstore: Address Memory
pushq %rbx
movq %rdx, %rbx 0x0400595 0x53
call plus 0x48
movq %rax, (%rbx) 0x89
popq %rbx 0xd3
ret 0xe8
0xf2
0xff
0xff
0xff
0x48
0x89
0x03
0x5b
0xc3
30
Turning C into Object Code
Generated x86-64 Assembly Binary Code for sumstore
sumstore: Address Memory
pushq %rbx
movq %rdx, %rbx 0x0400595 0x53
call plus 0x48
movq %rax, (%rbx) 0x89
popq %rbx 0xd3
ret 0xe8
0xf2
Obtain (on CSUG machine) with command 0xff
gcc –c sum.s -o sum.o 0xff
0xff
0x48
0x89
0x03
0x5b
0xc3
30
Turning C into Object Code
Generated x86-64 Assembly Binary Code for sumstore
sumstore: Address Memory
pushq %rbx
movq %rdx, %rbx 0x0400595 0x53
call plus 0x48
movq %rax, (%rbx) 0x89
popq %rbx 0xd3
ret 0xe8
0xf2
Obtain (on CSUG machine) with command 0xff
gcc –c sum.s -o sum.o 0xff
0xff
• Total of 14 bytes 0x48
• Instructions have variable 0x89
0x03
lengths: e.g., 1, 3, or 5 bytes
0x5b
• Code starts at memory address 0xc3
0x0400595
30
Instruction Processing Sequence
CPU Addresses Memory
Assembly Register
Programmer’s PC File Code
Data Data
Perspective Condition Stack
of a Computer ALU Instructions
Codes
Fetch Instruction
(According to PC)
31
Instruction Processing Sequence
CPU Addresses Memory
Assembly Register
Programmer’s PC File Code
Data Data
Perspective Condition Stack
of a Computer ALU Instructions
Codes
Fetch Instruction
(According to PC)
0x4801d8
31
Instruction Processing Sequence
CPU Addresses Memory
Assembly Register
Programmer’s PC File Code
Data Data
Perspective Condition Stack
of a Computer ALU Instructions
Codes
addq %rax,(%rbx)
31
Instruction Processing Sequence
CPU Addresses Memory
Assembly Register
Programmer’s PC File Code
Data Data
Perspective Condition Stack
of a Computer ALU Instructions
Codes
31
Instruction Processing Sequence
CPU Addresses Memory
Assembly Register
Programmer’s PC File Code
Data Data
Perspective Condition Stack
of a Computer ALU Instructions
Codes
31
Instruction Processing Sequence
CPU Addresses Memory
Assembly Register
Programmer’s PC File Code
Data Data
Perspective Condition Stack
of a Computer ALU Instructions
Codes
Update
Condition
Codes
31
Instruction Processing Sequence
CPU Addresses Memory
Assembly Register
Programmer’s PC File Code
Data Data
Perspective Condition Stack
of a Computer ALU Instructions
Codes
Update
Condition
Codes
31
Instruction Processing Sequence
CPU Addresses Memory
Assembly Register
Programmer’s PC File Code
Data Data
Perspective Condition Stack
of a Computer ALU Instructions
Codes
Update
Condition
Codes Adjust
PC
31
Instruction Processing Sequence
CPU Addresses Memory
Assembly Register
Programmer’s PC File Code
Data Data
Perspective Condition Stack
of a Computer ALU Instructions
Codes
Update
Condition
Codes Adjust
PC
31
Today: Assembly Programming I: Basics
32
Data Movement Instruction Example
• Semantics:
• Move (really, copy) data in register %rdx to memory location
whose address is the value stored in %rdi
• Pointer dereferencing
34
Data Movement Instruction Example
address
• Semantics:
• Move (really, copy) data in register %rdx to memory location
whose address is the value stored in %rdi
• Pointer dereferencing
34
Data Movement Instruction Example
address
• Semantics:
• Move (really, copy) data in register %rdx to memory location
whose address is the value stored in %rdi
• Pointer dereferencing
34
Data Movement Instruction Example
address
• Semantics:
• Move (really, copy) data in register %rdx to memory location
whose address is the value stored in %rdi
• Pointer dereferencing
34
Data Movement Instructions
movq Source, Dest
35
Data Movement Instructions
movq Source, Dest
Operator Operands
35
Data Movement Instructions
movq Source, Dest
Operator Operands
• Memory:
• Simplest example: (%rax)
• How to obtain the address is called “addressing mode”
35
Data Movement Instructions
movq Source, Dest
Operator Operands
• Memory:
• Simplest example: (%rax)
• How to obtain the address is called “addressing mode”
• Register:
• Example: %rax, %r13
• But %rsp reserved for special use
35
Data Movement Instructions
movq Source, Dest
Operator Operands
• Memory:
• Simplest example: (%rax)
• How to obtain the address is called “addressing mode”
• Register:
• Example: %rax, %r13
• But %rsp reserved for special use
• Immediate: Constant integer data
• Example: $0x400, $-533; like C constant, but prefixed with ‘$’
• Encoded with 1, 2, or 4 bytes; can only be source
35
movq Operand Combinations
Mem Reg
Reg Reg
movq
Mem
Reg
Imm
Mem
Cannot do memory-memory transfer
with a single instruction in x86.
36
movq Operand Combinations
Reg Reg
movq
Mem
Reg
Imm
Mem
Cannot do memory-memory transfer
with a single instruction in x86.
36
movq Operand Combinations
Reg Reg
movq
Mem
Reg
Imm
Mem
Cannot do memory-memory transfer
with a single instruction in x86.
36
movq Operand Combinations
Reg
Imm
Mem
Cannot do memory-memory transfer
with a single instruction in x86.
36
movq Operand Combinations
Reg
Imm
Mem
Cannot do memory-memory transfer
with a single instruction in x86.
36
movq Operand Combinations
Reg
Imm
Mem
Cannot do memory-memory transfer
with a single instruction in x86.
36
movq Operand Combinations
Reg
Imm
Mem
Cannot do memory-memory transfer
with a single instruction in x86.
36
movq Operand Combinations