a) Write the following C function in Assembly. You must follow the System V 64-b
ID: 3846790 • Letter: A
Question
a) Write the following C function in Assembly. You must follow the System V 64-bit calling convention and use AT&T; Syntax notation. Note: You cannot change the algorithm in any way so your assembly function must still be recursive. long fibonacci (long n) { if (n = = 0) return 0; else if (n = = 1) return 1;else return (fibonacci (n-1) + fibonacci (n-2)); } b) The Windows x86-64 calling convention passes function parameters in the registers RCX, RDX, R8 and R9 and returns values on register RAX. Caller saved registers are: RAX, RCX, RDX, R8, R9, R10 and R11, while callee-saved registers are RBX RBP, RDI, RSI, RSP, R12, R13, R14, and R15. Rewrite the assembly function from Part A using the Windows x86-64 calling convention instead of the System v 4- bit calling convention.Explanation / Answer
1)
a)
Code:
include Irvine32.inc
.code
main PROC
mov ecx,0
push 10
call fabonacci
add esp, 4
main ENDP
fabonacci PROC C
add ecx,1
push ebp
mov ebp,esp
sub esp, 4
mov eax,[ebp+8]
cmp eax,2
je interrupt
cmp eax,1
je interrupt
dec eax
push eax
call fabonacci
mov [ebp-4], eax
dec dword ptr [esp]
call fabonacci
add esp, 4
add eax, [ebp-4]
jmp Exit
interrupt:
mov eax, 1 ; start values 1,1
; dec eax ; start values 0,1
Exit:
mov esp, ebp
pop ebp
ret
fabonacci ENDP
END main
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.