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

Computer Science Assembly language only please! Thank you! NO GLOBALS! 1. The Co

ID: 3827538 • Letter: C

Question

Computer Science Assembly language only please! Thank you!

NO GLOBALS!

1. The CopyString function will copy one string (src) to the destination (dest).

2. You will be required to copy the string until the byte value at the location is 0. Remember that C style strings have a terminating "NULL" character (a zero). For example, "Hello World" actually is "Hello World"0.

3. In essence, you will start with 'H' in the example above and copy it from the src to the destination. Then you will move to the 'e' and do the same. You keep looping until you hit the 0. Note: You will terminate the loop when you hit the 0, but you still must copy the 0 into the destination string!!

Explanation / Answer

.LC0:
.string "Input a string"
.LC1:
.string "%s"
.LC2:
.string "Source string: "%s" "
.LC3:
.string "Destination string: "%s" "
main:
push rbp
mov rbp, rsp
sub rsp, 2016
mov edi, OFFSET FLAT:.LC0
call puts
lea rax, [rbp-1008]
mov rsi, rax
mov edi, OFFSET FLAT:.LC1
mov eax, 0
call scanf
lea rdx, [rbp-1008]
lea rax, [rbp-2016]
mov rsi, rdx
mov rdi, rax
call copy_string(char*, char*)
lea rax, [rbp-1008]
mov rsi, rax
mov edi, OFFSET FLAT:.LC2
mov eax, 0
call printf
lea rax, [rbp-2016]
mov rsi, rax
mov edi, OFFSET FLAT:.LC3
mov eax, 0
call printf
mov eax, 0
leave
ret
copy_string(char*, char*):
push rbp
mov rbp, rsp
mov QWORD PTR [rbp-24], rdi
mov QWORD PTR [rbp-32], rsi
mov DWORD PTR [rbp-4], 0
.L5:
mov eax, DWORD PTR [rbp-4]
movsx rdx, eax
mov rax, QWORD PTR [rbp-32]
add rax, rdx
movzx eax, BYTE PTR [rax]
test al, al
jne .L6
mov eax, DWORD PTR [rbp-4]
movsx rdx, eax
mov rax, QWORD PTR [rbp-24]
add rdx, rax
mov eax, DWORD PTR [rbp-4]
movsx rcx, eax
mov rax, QWORD PTR [rbp-32]
add rax, rcx
movzx eax, BYTE PTR [rax]
mov BYTE PTR [rdx], al
add DWORD PTR [rbp-4], 1
jmp .L5
.L6:
nop
pop rbp
ret

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