1/203
Looks like no tags are added yet.
%rax
Return Value
32-bit: %eax
16-bit: %ax
8-bit: %al
%rsp
Stack Pointer
32-bit: %esp
16-bit: %sp
8-bit: %spl
%rdi
1st Parameter
32-bit: %edi
16-bit: %di
8-bit: %dil
%rsi
2nd Parameter
32-bit: %esi
16-bit: %si
8-bit: %sil
%rdx
3rd Parameter
32-bit: %edx
16-bit: %dx
8-bit: %dl
%rcx
4th Parameter
32-bit: %ecx
16-bit: %cx
8-bit: %cl
%r8
5th Parameter
32-bit: %r8d
16-bit: %r8w
8-bit: %r8b
%r9
6th Parameter
32-bit: %r9d
16-bit: %r9w
8-bit: %r9b
%r10
Caller Saved
32-bit: %r10d
16-bit: %r10w
8-bit: %r10b
%r11
Caller Saved
32-bit: %r11d
16-bit: %r11w
8-bit: %r11b
%rbx
Callee Saved
32-bit: %ebx
16-bit: %bx
8-bit: %bl
%rbp
Callee Saved
32-bit: %ebp
16-bit: %bp
8-bit: %bpl
%r12
Callee Saved
32-bit: %r12d
16-bit: %r12w
8-bit: %r12b
%r13
Callee Saved
32-bit: %r13d
16-bit: %r13w
8-bit: %r13b
%r14
Callee Saved
32-bit: %r14d
16-bit: %r14w
8-bit: %r14b
%r15
Callee Saved
32-bit: %r15d
16-bit: %r15w
8-bit: %r15b
If %rax holds the value x and %rcx holds the value y, what is the value of %rdx after leaq 6(%rax), %rdx
executes?
x + 6
If %rax holds the value x and %rcx holds the value y,
what is the value of %rdx after leaq (%rax, %rcx), %rdx executes?
x + y
If %rax holds the value x and %rcx holds the value y,
what is the value of %rdx after leaq (%rax, %rcx, 4), %rdx executes?
x + 4y
If %rax holds the value x and %rcx holds the value y,
what is the value of %rdx after leaq 7(%rax, %rax, 8), %rdx executes?
9x + 7
If %rax holds the value x and %rcx holds the value y, what is the value of %rdx after leaq 0xA(,%rcx, 4), %rdx executes?
4y + 0xA
If %rax holds the value x and %rcx holds the value y,
what is the value of %rdx after leaq 9(%rax, %rcx, 2), %rdx executes?
x + 2y + 9
If %rax holds the value x and %rcx holds the value y,
what is the value of %rdx after shlq $3, %rcx #shifts %rcx 3 left leaq 6(%rcx), %rdx executes?
8y + 6
If %rax holds the value x and %rcx holds the value y,
what is the value of %rdx after shlq $2, %rcx #shifts %rcx 2 left leaq 5(%rax, %rcx), %rdx executes?
x + 4y + 5
If %rax holds the value x and *x = 42, what is the value of %rdx after leaq (%rax), %rdx executes?
x
If %rax holds the value x and *x = 42, what is the value of %rdx after movq (%rax), %rdx executes?
42
Modify the assembly code shown below for signed division to implement this function (unsigned division).
void remdiv(long x, long y, long *qp, long *rp);
x(5) in %rdi, y(2) in %rsi, qp in %rdx, rp in %rcx
remdiv:
movq %rdx, %r8 #Copy qp
movq %rdi, %rax #Move x to lower 8 bytes
cqto #sign-extend to upper 8 bytes of dividend
idivq %rsi #Divide by y
movq %rax, (%r8) #Store quotient at qp
movq %rdx, (%rcx) #Store remainder at rp
ret
remdiv:
movq %rdx, %r8 #Copy qp
movq %rdi, %rax #X to lower 8 bytes
movq $0, %rdx #clear upper 8 bytes
divq %rsi #Divide by y
movq %rax, (%r8) #Store quotient
movq %rdx, (%rcx) #Store remainder
ret
What is linking?
Combining code pieces and data into a file to be executed.
When can linking occur?
Compile time, run time, and/or load time.
What is relocation?
Adjusting addresses in modules when the modules are linked.
What can block scope identifiers be?
Variable names.
True or False: During symbol resolution, each symbol reference (identifier) is linked with exactly one symbol.
True.
What can file scope identifiers be?
Both variable and function names.
Where are block scope, *initialized*, non-static C variables stored?
On the stack during execution.
Where are block scope, *uninitialized*, non-static C variables stored?
On the stack during execution.
Where are block scope, *uninitialized*, static C variables stored?
In the .bss section during compilation.
True or False: Any C identifier with file scope is visible to the linker.
True.
What is a strong symbol?
Either an initialized file scope variable or a function name.
What is a weak symbol?
An uninitialized file scope variable.
What is linker's duplicate rule number 1?
Multiple strong symbols are not allowed.
How does the linker act when there are two or more duplicate strong symbols?
It gives a linker error.
What is linker's duplicate rule number 2?
When there is one strong symbol and multiple duplicate weak ones, linker picks strong one, all weak ones are resolved to strong.
What is linker's duplicate rule number 3?
When there are multiple duplicate weak symbols, the linker picks a weak one and all other weak ones resolve to that one.
Is the following a weak symbol or a strong symbol:
int racer;
Weak symbol.
Is the following a weak symbol or a strong symbol:
double x = 3.14159;
Strong symbol.
Is the following a weak symbol or a strong symbol:
int main() {}
Strong symbol.
Consider the following symbol resolution puzzle:
p1.c p2.c
int x; int x;
int z=5; int z;
p1() {} p2(){}
Which of the following best represents the outcome of these symbol declarations?
A. x references will go to the uninitialized int x in p1.c
B. x references will go to the uninitialized int x in p2.c
C. z references will go to the uninitialized int z in p2.c
D. z references will go to the initialized int z in p1.c
E. A and C
F. A and D
G. B and C
H. B and D
I. (A or B) and C
J. (A or B) and D
K. (A or B) and (C or D)
L. Linker will throw an error.
J. (A or B) and D
Convert the following binary to hexadecimal:
1100 0011 0110 1000
0xC368
Convert the following hexadecimal to binary:
0xFC103B
1111 1100 0001 0000 0011 1011
Convert the following hexadecimal to decimal:
0x31CA
12746
What are two more efficient ways of setting a register to 0 than movq $0, %reg?
subq %reg, %reg
xorq %reg, %reg
The LEA instruction can perform computations of the form (a << k) + b, where k is either 0, 1, 2, or 3, and b is either 0 or some program value. The compiler often uses this instruction to perform multiplications by constant factors. For example, we can compute 3 ∗ a as (a << 1) + a. Considering cases where b is either 0 or equal to a, and all possible values of k, what multiples of a can be computed with a single LEA instruction?
1, 2, 3, 4, 5, 8, 9
Consider a function that has prototype void decode1(long *xp, long *yp, long *zp); that is compiled from assembly code yielding the following:
decode1:
movq (%rdi), %r8
movq (%rsi), %rcx
movq (%rdx), %rax
subq $3, %rcx
addq $5, %r8
subq $7, %rax
movq %r8, (%rdi)
movq %rcx, (%rsi)
movq %rax, (%rdx)
ret
If we have a C program such that:
long a = 16; b = 32; c = 50;
decode1(&a, &b, &c);
What are the values of a, b and c after the call to decode1()?
a = 21
b = 29
c = 43
Consider:
struct S7 {
int m1;
int m2;
short m3;
int m4[12];
struct S7*next;
};
int find_m4(struct S7*p, int i) {
return(p->m4[i]);
}
If we wrote find_m4() in x86-64 assembler, which instruction returns the correct value?
movl 12(%rdi, %rsi,4), %eax
Consider:
struct S7 {
int m1;
int m2;
short m3;
int m4[12];
struct S7*next;
};
int find_m4(struct S7*p, int i) {
return(&(p->m4[i]));
}
If we wrote find_m4() in x86-64 assembler, which instruction returns the correct value?
leaq 12(%rdi, %rsi,4), %rax
Write an x86-64 function that has the following prototype:
unsigned char add_three(unsigned char a, unsigned char b, unsigned char c);
This function adds a + b + c together and returns the result. If the sum of the 3 values causes overflow, the function returns 0.
When you test your program with a=100, b=21, c=16, does overflow occur?
When you test your program with a=210, b=60, c=30, does overflow occur?
Did you use CF to determine if overflow occurred?
Did you use OF to determine if overflow occurred?
What suffix did you use for the x86-64 add instructions?
No, Yes, Yes, No, b.
Consider the following:
1. an 8-bit register, %al, contains the bits 1011 1111.
2. 8-bit register, %dl, contains the bits 0100 0010.
3. the instruction addb %al, %dl is executed.
What are the values of the four condition flags Z, S, C, and O directly afterwards?
Z = 0
S = 0
C = 1
O = 0
Consider the following:
1. an 8-bit register, %al, contains the bits 1010 1011.
2. 8-bit register, %dl, contains the bits 1010 0111.
3. the instruction addb %al, %dl is executed.
What are the values of the four condition flags Z, S, C, and O directly afterwards?
Z = 0
S = 0
C = 1
O = 1
Consider the following:
1. %rax = 0x300
2. %rdx = 0x08
3. Memory address at 0x300 has 8-byte value 0x747
4. Memory address at 0x308 has 8-byte value 0x644
5. Memory address at 0x310 has 8-byte value 0x935
6. Memory address at 0x318 has 8-byte value 0xACD
After leaq 8(%rax, %rdx,2), %rcx executes, the value in %rcx is: (Answer must be in hexadecimal form)
0x318
Consider the following:
1. %rax = 0x300
2. %rdx = 0x08
3. Memory address at 0x300 has 8-byte value 0x747
4. Memory address at 0x308 has 8-byte value 0x644
5. Memory address at 0x310 has 8-byte value 0x935
6. Memory address at 0x318 has 8-byte value 0xACD
After movq (%rax, %rdx,2), %rcx executes, the value in %rcx is: (Answer must be in hexadecimal form)
0x935
DO STRUCTURE ALIGNMENT TABLE PRACTICE!!!
Can't really add to Quizlet effectively, so do on your own.
True or False: For unsigned addition, if carry out from the most significant pair of bits is 1, there is no overflow.
False.
What is the carry in bit?
The carry in bit is the 1 carried over from the previous column of addition when that column adds up to more than 9.
What is the carry out bit?
The carry out bit is the 10 that is left over when adding two numbers together that sum to over 9.
What is the total number of distinct bit patterns that reside in a number of bits w?
2^w
What are the min and the max for signed and unsigned representations of integers of w bits?
Unsigned: min = 0, max = (2^w) - 1
Signed: min = -2^(w-1), max = 2^(w-1) - 1
B2U
Binary to unsigned. Each bit represents 2^n value depending on the location of the bit, and all of these are added up to get the decimal value. There are no negatives.
B2T
Binary to twos complement. The most significant bit is the sign bit, and if the sign bit is one and is the nth bit, you treat that as a -2^n and each other bit is a positive value which you add to this -2^n value.
B2O
Binary to ones complement. Most significant bit represents the sign bit, and if the sign bit is one, you flip all of the bits and add a negative sign to get the value.
B2S
Binary to signed. Most significant bit represents the sign bit, and if the sign bit is one, you read all of the bits on the right of the sign bit as though they were a regular bitwise representation and simply add a negative sign.
What is the decimal value of 1101 0101 if this is a B2O representation of an integer?
-42
What is the decimal value of 0110 1101 if this is a B2O representation of an integer?
109
True or False: There are two ways of representing 0 in B2O and B2S.
True.
What is the hierarchy of each data type in regards to promotion?
char
short
int
unsigned int
long
unsigned long
long long
unsigned long long
float
double
long double
What is sign extension?
Representing a number using more bits while preserving its decimal value. For unsigned numbers the leftmost bits are filled with zeros, for signed numbers the leftmost bits are filled with ones.
What is truncation?
When leftmost bits are removed due to a mismatch in size or to preserve memory. Can sometimes result in a change of value.
When does truncation occur?
When casting larger data types to smaller ones, can result in a change of value if operands are signed and the bit representation leads to a change in sign.
What is overflow and when does it occur?
Occurs when x + y > (2^w) - 1 or for signed numbers x + y < -(2^w-1). Overflow results in an incorrect answer when carry in != carry out.
How can we perform B2T integer negation?
Invert all of the bits and add one.
True or False: It is possible to modify the stack in bit amounts as well as byte amounts.
False.
What is an additive inverse?
Given a number x the additive inverse is a number y such that x + y = 0
How much faster is using shifting and subtraction than multiplication?
25 times faster.
When an operation is performed where one operand is signed and one is unsigned what happens?
C implicitly casts the signed value to unsigned then performs the operations.
Where can computing operations with signed and unsigned operands become an issue?
When doing relational operations, since negative numbers are cast to unsigned, the leading bits filled with ones will create a large positive number.
Why aren't arithmetic operations changed when computing with signed and unsigned operations?
Because the bitwise representation remains the same.
Logical Shift
Shift applied to a binary number where all shifted digits are filled with zeros.
Arithmetic Shift
Shift applied to a binary number where left shifts fill rightmost bits with zeros and right shifts preserve the most significant bit.
Given a biased-8 number 6 what is its true representation?
-2.
What are the three fields the bits in the encoding of a real number are divided into?
S - Sign field, encodes the sign of the number.
E - Exponent field, encodes the exponent of a real number in bias form.
F - The mantissa, encodes a number greater than or equal to 0, and less than 2, to which the exponent is raised to obtain the real value encoded by the entire IEEE 754 representation.
How is a real number decimal value represented?
(-1) ^ S * (f) * (2^e)
For 32-bit, n = 23, bias = 127, and for 64-bit, n = 52, and bias = 1023.
e = E - bias
E = e + bias
For f, b is either 0 if E is 0, or 1 otherwise.
F = (f - b) * 2^n
f = (F/(2^n)) + b
Single floating point numbers
32 bits, range from +/- 2^-149 to +/- 2^127
Double floating point numbers
64 bits, range from +/- 2^-1074 to +/- 2^1023
What is overflow with respect to floating point range?
Values have grown too large for the representation, much in the same way that you can have integer overflow.
What is underflow with respect to floating point range?
(a value too small to be represented) is a less serious problem because it just denotes a loss of precision, which is guaranteed to be closely approximated by zero.
What is the hidden bit?
In floating point values, it is the bit to the left of the binary point. It is called hidden because it does not appear in encoding, however it is implied by the value of the exponent.
What are the biases for single and double floating precision?
For single floating precision, bias is 127, for double floating precision, bias is 1023.
Denormalized Values
These are extremely small values, very close to 0, including 0. If such a value becomes too small, it can cause underflow ( the largest denormalized value is approximately +/-1.18×10 −38 ).
Normalized Values
These are values greater than the largest denormalized value, but small enough to fit into the representation (that is, without overflow).
Special Values
These are values which are either +/- infinity (created by overflow) or NaN (not a number - values which are not real numbers, possibly caused by invalid operations, such as division by 0).
What does precision IEEE 754 format bring to values?
Decimal values, a larger range of values