1) Using the subset of X86 assembly language we have seen so far, a) Write the a
ID: 3753068 • Letter: 1
Question
1) Using the subset of X86 assembly language we have seen so far,
a) Write the assembly language lines that would perform the C++ line of code: a[5] += -65. Assume the following information:
i. The base address for ‘a’ is currently stored in the register %edi
ii. Use the register %eax to store the value of a[5]
iii. Use immediate for any constants.
b) Write the assembly language lines that would perform the C++ line of code: if (x < y) y=x; else y= y*2; Include the lines of code to:
i. read the values required from memory (i.e. read the variables into registers),
ii. perform the operations needed, and
iii. write it back out to memory (i.e. write the registers back into the variables).
Assume all words are 32-bits. Assume the following information:
i. Assume ‘x’ and ‘y’ addresses are stored in %ecx and %edx.
ii. Use registers %eax and %ebx to store the values for ‘x’ and ‘y’ when you load them into the machine
iii. Use immediate for any constants.
Explanation / Answer
a)
main:
push rbp
mov rbp, rsp
mov eax, DWORD PTR [rbp-12]
sub eax, 65
mov DWORD PTR [rbp-12], eax
mov eax, 0
pop rbp
ret
b)
main:
push rbp
mov rbp, rsp
mov eax, DWORD PTR [rbp-4]
cmp eax, DWORD PTR [rbp-8]
jge .L2
mov eax, DWORD PTR [rbp-4]
mov DWORD PTR [rbp-8], eax
jmp .L3
.L2:
sal DWORD PTR [rbp-8]
.L3:
mov eax, 0
pop rbp
ret
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.