Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

blem 6 (22 points. Suggested time: 20 mins) Consider the can easily refer to an

ID: 3709168 • Letter: B

Question

blem 6 (22 points. Suggested time: 20 mins) Consider the can easily refer to an instruction; they are not part of the program) the following assembly code (.Li is a label. 1 17 are just notati can custy tefe 11: movq $0, %rax L1: 12: 13: 14: 15: 16: 17: movq %rdi, %rdx andq $1, %rdx addq %rdx, %rax shrq $1, %rdi jne .Li ret Assume that %rdi is loaded with oxoF before the program starts. Part a (3 points): What is the value of %rax after the code returns? Part b (3 points): In a single-cyele, sequential microarchitecture, how many oyeles does this program take to finish? Part e (9 points): There are 4 pairs of read-after-write data dependencies. One of them is cti, 142 because h writes to %rax and 14 reads from %rax, what are the other three pairs? write the answers in the form of (3 points) Pair 1 (3 points): Pair 2 (3 points): Pair 3

Explanation / Answer

movq $0,%rax => rax =0
.L1
movq %rdi,%rdx => rdx = 0x0F
andq $1,$rdx => rdx = rdx & 0x1 = 0xF & 0x1 = 0x1
addq %rdx,%rax => rax = rax + rdx = 0 + 0x1 = 0x1
shrq $1,%rdi => rdi = rdi >> 1 = 0xF >> 1 = 0x7
jne .L1
ret


So, accordinly we can see that the function is counting the number of ones in rdi .

So, accordingly, at the end the value of eax when the program ends is 0x4

The no. of cycles used :-

movq = 1 cycle
andq = 1 cycle
addq = 1 cycle
shrq = 1 cycle
jne = 1 cycle

So,
movq $0,%rax = 1 cycle

This block is executed 4 times.On whole ;5 cycles * 4 = 20 cycles

movq %rdi,%rdx
andq $1,$rdx
addq %rdx,%rax
shrq $1,%rdi
jne .L1

Therefore,total cycles before returning = 21 cycles