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 so the revision need to work in visual studio 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:
ebxStr BYTE "EBX:
ecxStr BYTE "ECX:
edxStr BYTE "EDX:
esiStr BYTE "ESI:
ediStr BYTE "EDI:
ebpStr BYTE "EBP:
espStr BYTE "ESP:
eipStr BYTE "EIP:
eflStr BYTE "EFL:
newlineStr BYTE
tabStr BYTE
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, L
data
flagStr BYTE flagName,
flagVal BYTE
code
push eax
push edx
mov eax, eflags
mov flagVal,
shr eax, shiftCount
jc L
mov flagVal,
L:
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 ; Adjust for pushad pushfd
call showRegister
lea edx, ebxStr
mov eax, esp
call showRegister
lea edx, ecxStr
mov eax, esp
call showRegister
lea edx, edxStr
mov eax, esp
call showRegister
lea edx, newlineStr
call writeString
lea edx, esiStr
mov eax, esp
call showRegister
lea edx, ediStr
mov eax, esp
call showRegister
lea edx, ebpStr
mov eax, esp
call showRegister
lea edx, espStr
mov eax, esp
call showRegister
lea edx, newlineStr
call writeString
lea edx, eipStr
; Here we simulate EIP normally obtained through context in a real scenario
call geteip
call showRegister
lea edx, eflStr
mov eax, eflags
call showRegister
; Display flags using the eflags value
ShowFlag CF
ShowFlag PF
ShowFlag AF
ShowFlag ZF
ShowFlag SF
ShowFlag OF
lea edx, newlineStr
call writeString
popad
ret
dumpRegisters ENDP
; Procedure to get the current EIP
geteip PROC
push eax
mov eax, esp
pop eax
ret
geteip ENDP
main PROC
call dumpRegisters
exit
main ENDP
END main
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
