Pre-quiz on third week's material.
Question 1: The instruction leaq 7(%rax, %rbx, 4), %rdx does which of the following?
The textbook presents the following to implementations of factorial (in figures 3.19 and 3.20):
fact_do: fact_while:
movl $1, %eax movl $1, %eax
L2: jmp L5
imulq %rdi, %rax L6:
subq $1, %rdi imulq %rdi, %rax
cmpq $1, %rdi subq $1, %rdi
jg L2 L5:
rep cmpq $1, %rdi
ret jg L6
rep
ret
Question 2: (see above) Consider the mathematical instructions imulq, subq, and cmpq.
Let d be the number of these instructions executed by fact_do
and w be the number of these instructions executed by fact_while.
Assume both functions are invoked with the argument 3 (which is passed into the functions in %rdi).
What is the value of d - w?
Question 3: (see above) Compare the speed of fact_do and fact_while
Question 4: Figure 3.28 explains how six arguments are passed to a function in six registers. A function with seven arguments
Consider the Y86-64 instruction encodings in Figure 4.2. Assume that memory is little-endian.
Question 5: (see above) Why not encode ret, halt, and nop in just 4 bits instead of 8?
Question 6: (see above) Suppose address 0x10 contains instruction rrmovq %rsp, %r8. If we read the value in address 0x10 as a short value, it will be