CSE 2421 - Final Exam

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/203

encourage image

There are no tags or description

Looks like no tags are added yet.

204 Terms

1
New cards

%rax

Return Value

32-bit: %eax

16-bit: %ax

8-bit: %al

2
New cards

%rsp

Stack Pointer

32-bit: %esp

16-bit: %sp

8-bit: %spl

3
New cards

%rdi

1st Parameter

32-bit: %edi

16-bit: %di

8-bit: %dil

4
New cards

%rsi

2nd Parameter

32-bit: %esi

16-bit: %si

8-bit: %sil

5
New cards

%rdx

3rd Parameter

32-bit: %edx

16-bit: %dx

8-bit: %dl

6
New cards

%rcx

4th Parameter

32-bit: %ecx

16-bit: %cx

8-bit: %cl

7
New cards

%r8

5th Parameter

32-bit: %r8d

16-bit: %r8w

8-bit: %r8b

8
New cards

%r9

6th Parameter

32-bit: %r9d

16-bit: %r9w

8-bit: %r9b

9
New cards

%r10

Caller Saved

32-bit: %r10d

16-bit: %r10w

8-bit: %r10b

10
New cards

%r11

Caller Saved

32-bit: %r11d

16-bit: %r11w

8-bit: %r11b

11
New cards

%rbx

Callee Saved

32-bit: %ebx

16-bit: %bx

8-bit: %bl

12
New cards

%rbp

Callee Saved

32-bit: %ebp

16-bit: %bp

8-bit: %bpl

13
New cards

%r12

Callee Saved

32-bit: %r12d

16-bit: %r12w

8-bit: %r12b

14
New cards

%r13

Callee Saved

32-bit: %r13d

16-bit: %r13w

8-bit: %r13b

15
New cards

%r14

Callee Saved

32-bit: %r14d

16-bit: %r14w

8-bit: %r14b

16
New cards

%r15

Callee Saved

32-bit: %r15d

16-bit: %r15w

8-bit: %r15b

17
New cards

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

18
New cards

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

19
New cards

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

20
New cards

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

21
New cards

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

22
New cards

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

23
New cards

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

24
New cards

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

25
New cards

If %rax holds the value x and *x = 42, what is the value of %rdx after leaq (%rax), %rdx executes?

x

26
New cards

If %rax holds the value x and *x = 42, what is the value of %rdx after movq (%rax), %rdx executes?

42

27
New cards

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

28
New cards

What is linking?

Combining code pieces and data into a file to be executed.

29
New cards

When can linking occur?

Compile time, run time, and/or load time.

30
New cards

What is relocation?

Adjusting addresses in modules when the modules are linked.

31
New cards

What can block scope identifiers be?

Variable names.

32
New cards

True or False: During symbol resolution, each symbol reference (identifier) is linked with exactly one symbol.

True.

33
New cards

What can file scope identifiers be?

Both variable and function names.

34
New cards

Where are block scope, *initialized*, non-static C variables stored?

On the stack during execution.

35
New cards

Where are block scope, *uninitialized*, non-static C variables stored?

On the stack during execution.

36
New cards

Where are block scope, *uninitialized*, static C variables stored?

In the .bss section during compilation.

37
New cards

True or False: Any C identifier with file scope is visible to the linker.

True.

38
New cards

What is a strong symbol?

Either an initialized file scope variable or a function name.

39
New cards

What is a weak symbol?

An uninitialized file scope variable.

40
New cards

What is linker's duplicate rule number 1?

Multiple strong symbols are not allowed.

41
New cards

How does the linker act when there are two or more duplicate strong symbols?

It gives a linker error.

42
New cards

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.

43
New cards

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.

44
New cards

Is the following a weak symbol or a strong symbol:

int racer;

Weak symbol.

45
New cards

Is the following a weak symbol or a strong symbol:

double x = 3.14159;

Strong symbol.

46
New cards

Is the following a weak symbol or a strong symbol:

int main() {}

Strong symbol.

47
New cards

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

48
New cards

Convert the following binary to hexadecimal:

1100 0011 0110 1000

0xC368

49
New cards

Convert the following hexadecimal to binary:

0xFC103B

1111 1100 0001 0000 0011 1011

50
New cards

Convert the following hexadecimal to decimal:

0x31CA

12746

51
New cards

What are two more efficient ways of setting a register to 0 than movq $0, %reg?

subq %reg, %reg

xorq %reg, %reg

52
New cards

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

53
New cards

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

54
New cards

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

55
New cards

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

56
New cards

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.

57
New cards

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

58
New cards

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

59
New cards

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

60
New cards

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

61
New cards

DO STRUCTURE ALIGNMENT TABLE PRACTICE!!!

Can't really add to Quizlet effectively, so do on your own.

62
New cards

True or False: For unsigned addition, if carry out from the most significant pair of bits is 1, there is no overflow.

False.

63
New cards

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.

64
New cards

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.

65
New cards

What is the total number of distinct bit patterns that reside in a number of bits w?

2^w

66
New cards

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

67
New cards

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.

68
New cards

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.

69
New cards

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.

70
New cards

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.

71
New cards

What is the decimal value of 1101 0101 if this is a B2O representation of an integer?

-42

72
New cards

What is the decimal value of 0110 1101 if this is a B2O representation of an integer?

109

73
New cards

True or False: There are two ways of representing 0 in B2O and B2S.

True.

74
New cards

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

75
New cards

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.

76
New cards

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.

77
New cards

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.

78
New cards

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.

79
New cards

How can we perform B2T integer negation?

Invert all of the bits and add one.

80
New cards

True or False: It is possible to modify the stack in bit amounts as well as byte amounts.

False.

81
New cards

What is an additive inverse?

Given a number x the additive inverse is a number y such that x + y = 0

82
New cards

How much faster is using shifting and subtraction than multiplication?

25 times faster.

83
New cards

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.

84
New cards

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.

85
New cards

Why aren't arithmetic operations changed when computing with signed and unsigned operations?

Because the bitwise representation remains the same.

86
New cards

Logical Shift

Shift applied to a binary number where all shifted digits are filled with zeros.

87
New cards

Arithmetic Shift

Shift applied to a binary number where left shifts fill rightmost bits with zeros and right shifts preserve the most significant bit.

88
New cards

Given a biased-8 number 6 what is its true representation?

-2.

89
New cards

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.

90
New cards

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

91
New cards

Single floating point numbers

32 bits, range from +/- 2^-149 to +/- 2^127

92
New cards

Double floating point numbers

64 bits, range from +/- 2^-1074 to +/- 2^1023

93
New cards

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.

94
New cards

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.

95
New cards

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.

96
New cards

What are the biases for single and double floating precision?

For single floating precision, bias is 127, for double floating precision, bias is 1023.

97
New cards

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 ).

98
New cards

Normalized Values

These are values greater than the largest denormalized value, but small enough to fit into the representation (that is, without overflow).

99
New cards

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).

100
New cards

What does precision IEEE 754 format bring to values?

Decimal values, a larger range of values