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

a) Write the following C function in Assembly. You must follow the System V 64-b

ID: 3847420 • 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. 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, R100 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

fibonacci(long):

        addiu   $sp,$sp,-40

        sw      $31,36($sp)

        sw      $fp,32($sp)

        sw      $16,28($sp)

        move    $fp,$sp

        sw      $4,40($fp)

        lw      $2,40($fp)

        nop

        bne     $2,$0,$L2

        nop

        move    $2,$0

        b       $L3

        nop

        lw      $3,40($fp)

        li      $2,1                        # 0x1

        bne     $3,$2,$L4

        nop

        li      $2,1                        # 0x1

        b       $L3

        nop

        lw      $2,40($fp)

        nop

        addiu   $2,$2,-1

        move    $4,$2

        jal     fibonacci(long)

        nop

        move    $16,$2

        lw      $2,40($fp)

        nop

        addiu   $2,$2,-2

        move    $4,$2

        jal     fibonacci(long)

        nop

        addu    $2,$16,$2

        move    $sp,$fp

        lw      $31,36($sp)

        lw      $fp,32($sp)

        lw      $16,28($sp)

        addiu   $sp,$sp,40

        j       $31

        nop

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote