Question: I need help with an assembly code using the asmlib.inc library I already have a code I just can't get it to compile correctly the

I need help with an assembly code using the asmlib.inc library I already have a code I just can't get it to compile correctly the output is wrong. AlsoI only code using visual studio 2022 so the revision need to work in visual studio 2022(Instuctions) One of the things missing from asmLib is the ability to display the values of all of the registers and the flags to the screen. In this assignment you are going to get a chance to do exactly that for me.
You are to create a procedure called dumpRegisters that will dump the contents of each register to the screen. This includes the flags register and each independent flag. The output of your dumpRegisters procedure should look like the attached image
(MY CODE)
INCLUDE asmlib.inc
.data
eaxStr BYTE "EAX: ",0
ebxStr BYTE "EBX: ",0
ecxStr BYTE "ECX: ",0
edxStr BYTE "EDX: ",0
esiStr BYTE "ESI: ",0
ediStr BYTE "EDI: ",0
ebpStr BYTE "EBP: ",0
espStr BYTE "ESP: ",0
eipStr BYTE "EIP: ",0
eflStr BYTE "EFL: ",0
newlineStr BYTE 13,10,0
tabStr BYTE "",0
eflags DWORD ? ; Declare eflags to store the flags register
.code
; Show a register name and value
showRegister PROC regName:PTR BYTE, regValue:DWORD
pushad
mov edx, regName
call writeString
mov eax, regValue
call writeHex
lea edx, tabStr
call writeString
popad
ret
showRegister ENDP
; Macro to show a flag
ShowFlag MACRO flagName, shiftCount
LOCAL flagStr, flagVal, L1
.data
flagStr BYTE "", flagName, "=",0
flagVal BYTE ?,0
.code
push eax
push edx
mov eax, eflags
mov flagVal, '1'
shr eax, shiftCount
jc L1
mov flagVal, '0'
L1:
mov edx, OFFSET flagStr
call writeString
mov al, flagVal
call writeChar
pop edx
pop eax
ENDM
; Dump all registers and flags
dumpRegisters PROC
pushad
pushfd
pop eflags
lea edx, eaxStr
mov eax, [esp +32+4] ; Adjust for pushad + pushfd
call showRegister
lea edx, ebxStr
mov eax, [esp +28+4]
call showRegister
lea edx, ecxStr
mov eax, [esp +24+4]
call showRegister
lea edx, edxStr
mov eax, [esp +20+4]
call showRegister
lea edx, newlineStr
call writeString
lea edx, esiStr
mov eax, [esp +16+4]
call showRegister
lea edx, ediStr
mov eax, [esp +12+4]
call showRegister
lea edx, ebpStr
mov eax, [esp +8+4]
call showRegister
lea edx, espStr
mov eax, [esp +4+4]
call showRegister
lea edx, newlineStr
call writeString
lea edx, eipStr
; Here we simulate EIP - normally obtained through context in a real scenario
call get_eip
call showRegister
lea edx, eflStr
mov eax, eflags
call showRegister
; Display flags using the eflags value
ShowFlag "CF",0
ShowFlag "PF",2
ShowFlag "AF",4
ShowFlag "ZF",6
ShowFlag "SF",7
ShowFlag "OF",11
lea edx, newlineStr
call writeString
popad
ret
dumpRegisters ENDP
; Procedure to get the current EIP
get_eip PROC
push eax
mov eax, [esp +4]
pop eax
ret
get_eip ENDP
main PROC
call dumpRegisters
exit
main ENDP
END main
I need help with an assembly code using the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!