Question

Write the following code in ARM 32 *AND* 64 bit assembly. Be sure to follow C calling conventions. char *strcpy(char *dst, ch

Please provide comments for each line, to make it easier to understand.

Thank you!

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

Here is your C Code:

char *strcpy(char *dst,char *src) {

char *dst_copy=dst; // character pointer declaration

while(*src) // loop to traverse the src

{

(*dst)=(*src);

++dst;

++src;

}

(*dst)=(*src);

return dst_copy; // returning the copied character array

}

char *strcpy(char *dst, char *src) { char *dst_copy=dst; // character pointer declaration while(*src) // loop to traverse the

Here is the converted Code:

strcpy:

push rbp

mov rbp, rsp

mov QWORD PTR [rbp-24], rdi

mov QWORD PTR [rbp-32], rsi

mov rax, QWORD PTR [rbp-24]

mov QWORD PTR [rbp-8], rax

jmp .L2

.L3:

mov rax, QWORD PTR [rbp-32]

movzx edx, BYTE PTR [rax]

mov rax, QWORD PTR [rbp-24]

mov BYTE PTR [rax], dl

add QWORD PTR [rbp-24], 1

add QWORD PTR [rbp-32], 1

.L2:

mov rax, QWORD PTR [rbp-32]

movzx eax, BYTE PTR [rax]

test al, al

jne .L3

mov rax, QWORD PTR [rbp-32]

movzx edx, BYTE PTR [rax]

mov rax, QWORD PTR [rbp-24]

mov BYTE PTR [rax], dl

mov rax, QWORD PTR [rbp-8]

pop rbp

ret

1 strcpy: push mov mov mov mov mov jmp rbp rbp, rsp QWORD PTR [rbp-24), rdi QWORD PTR (rbp-32], rsi rax, QWORD PTR (rbp-24] Q

*** If you have any doubts regarding the solution, please do ask in the comments ***

Add a comment
Know the answer?
Add Answer to:
Please provide comments for each line, to make it easier to understand. Thank you! Write the...
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
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