Question: Help me fix this bug: ( Either Lastname or First name is not printing out correctly. ) I provided the C code and the Assembly
Help me fix this bug: Either Lastname or First name is not printing out correctly. I provided the C code and the Assembly code I written and what it outputs versus what it should output. The functionreadrecord is commented out in C code and used globl readrecord in assembly.
typedef struct
char lastname;
char firstname;
long idnumber;
RECORD;
RECORD readrecord;
This function reads in the data for a single record frod
standard input by calling scanf. If scanf succeeds in
reading the data, a new RECOfo is allocated, populated
with the data, and a pointer to the record is returned
REcoRD readrecord
char lastname firstname;
RECORD p;
long id;
int res scanfs s ld lastname, firstname, &id;
if res EOF EOF is
return NULL;
p mallocsizeofRECORD;
plastname mallocstrlenlastname;
strcpyplastname, lastname;
pfirstname mallocstrlenlastname;
strcpypfirstname, firstname;
pidnumber id;
return p;
globl readrecord
readrecord:
pushq rbp
movq rsprbp
subq $rsp
pushq rbx
Record p
movq $ Xrex
call malloc
movq rax Zbx #saving the pointer of Record into rbx
#scanf inputs
leaq formatstrrip Xrcx
leaq eXrsp Yrdx #lastname
leaq eeXrsp Xrs #firstnare
leaq esXrrsprr #id
call scanf
crp $ Xgax
je failscanf
#lastnane
leaq eXrsp Zrcx #address of lastnane in rex
call strlen #rax strlenlastnane
addq $ $rax ##ull terninator
movq rax Zrcx #allocating memory
call malloc
movq rax eYbx
leaq esXrsp Xrdx #lastnane
movq rax Zrcx #nove to destination
call strcpy
#firstname
leaq eeXrsp Yrcx #address of first in rcx
call strlen #rax strlenfirstname
addqq $rax #null terninator
movq rax Zrcx #allocating memory
call malloc
mov raxYrbx #recordfirstnane
leaq ersp Zdx #first
movq rax Zrcx #move to destination
call strcpy
id
movq esrsp Zrax
movq raxrbx
#return record pointer
movq rbx #rax
addq $rsp
popq rbx
popq
retq
failscanf:
movq $e rrax
addq $ $rsp
popq rbp
retq
fornststr:
asciz s ld
Sorted
: Vongnorkeo, Anouparb
: Koncke, Gonzalo
: Civili, Patrizio
: Enkhbold, Vorshilov
: Amrit, Deiye
: Abdelaziz, Maged
: Konfourou, Issa
: Stevanovic, Nemanja
: Niang, Cheikh
: Markova, Seid
: Ladeb, Tarek
: Turay, Alhaji
: Andriamiarisoa, Vero
: Horvath, Zsuzsanna
: Liburd, Ian
: Kontoleontos, Ifigeneia
: Valtysson, Jorundur
globl readrecord
readrecord:
pushq rbp
movq rsprbp
subq $rsp
pushq rbx
Record p
movq $ Xrcx
call malloc
movq Yrax Yrbx #saving the pointer of Record into rbx
scanf inputs
leaq eXrsp Zrdx #lastname
leaq eersp Zrs firstnare
leaq esrrp Krs id
call scanf
crp $ Ygax
jc failscanf
#lastnane
leaq eKrsp Zrcx #address of lastnane in rex
call strlen #rax strlenlastnane
addq $ $rax null terninator
movq Xrax, Zrcx #allocating menory
call malloc
movq rax eZbrx
leaq errsp Zrdx #lastnane
call strcpy
firstname
leaq eeKrsp Krcx #address of first in rcx
call strlen #rax strlenfirstname
addq $$rax ##null terninator
movq rax Yrcx #allocating memory
call malloc
mov raxrbx #recordfirstnane
leaq eKrsp $rdx #first
movq rax, #rcex #nove to destination
call strcpy
id
movq esrsp Zrax
movq raxbx
#return record painter
movq rbxrax
addq $rsp
popq rbx
popq rbp
retq
failscanf:
movq $erax
addq $ Mrsp
popq
popq rbp
retq
fornststr:
asciz Xs s xld
Sorted
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
