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. (20 points) 1) Assembly Programming a) Write the following C function in Assembly. You must follow the System V 64-bit calling conventionlong Catalan(long n) { long sum = 0; if (n == 0) return 1; for (int i = 0; i < n; i++) { sum += Catalan(i) * Catalan(n - i - 1); } return sum; } 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 64- bit calling convention. (16 points)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Answer for Second Question(conversoion of c program to x86-64 calling convention)

Catalan(long):

push rbp

mov rbp, rsp

push rbx

sub rsp, 40

mov QWORD PTR [rbp-40], rdi

mov QWORD PTR [rbp-24], 0

cmp QWORD PTR [rbp-40], 0

jne .L2

mov eax, 1

jmp .L3

.L2:

mov DWORD PTR [rbp-28], 0

.L5:

mov eax, DWORD PTR [rbp-28]

cdqe

cmp QWORD PTR [rbp-40], rax

jle .L4

mov eax, DWORD PTR [rbp-28]

cdqe

mov rdi, rax

call Catalan(long)

mov rbx, rax

mov eax, DWORD PTR [rbp-28]

cdqe

mov rdx, QWORD PTR [rbp-40]

sub rdx, rax

mov rax, rdx

sub rax, 1

mov rdi, rax

call Catalan(long)

imul rax, rbx

add QWORD PTR [rbp-24], rax

add DWORD PTR [rbp-28], 1

jmp .L5

.L4:

mov rax, QWORD PTR [rbp-24]

.L3:

add rsp, 40

pop rbx

pop rbp

ret

Add a comment
Know the answer?
Add Answer to:
a) Write the following C function in Assembly. You must follow the System V 64-bit calling convention and use AT&T S...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • a) Write the following C function in Assembly. You must follow the System V 64-bit calling...

    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,...

  • Assembly language 64 bit please ! An example file for set up ==========+ ;| Data Segment...

    Assembly language 64 bit please ! An example file for set up ==========+ ;| Data Segment BEGINS Here | ;+======================================================================+ segment .data ;Code this expression: sum = num1+num2 num1 dq 0 ;left operand of the addition operation num2 dq 0 ;right operand of the addition operation sum dq 0 ;will hold the computed Sum value RetVal dq 0 ;Integer value RETURNED by function calls ;can be ignored or used as determined by the programmer ;Message string prompting for the keyboard...

  • Assembly Language 64- bit system Description: You are responsible to implement several assembly functions to perform...

    Assembly Language 64- bit system Description: You are responsible to implement several assembly functions to perform the simple arithmetic calculations for 2 64-bit integers. These functions will use the C function signature but the main logic within this function should be inline assembly code using the ASM block similar to the assembly example shown in class. 1. long XOR ( long op1, long op2 )- xor will return the result of bit exclusive OR of op1 / op2- can use...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT