The MASM Forum Archive 2004 to 2012

General Forums => The Laboratory => Topic started by: scooter4483 on February 08, 2006, 08:02:53 PM

Title: how do you display original values of registers
Post by: scooter4483 on February 08, 2006, 08:02:53 PM
I have some code that does something and I want to display the original contents of eax and ebx when i call dumpRegs at the of my code, how do i do that? because when i ran my code, it displays the new contents after i did some loop that i substituted by the dots below.

.data

x DWORD 6
y DWORD 5

;---------------------------------------------------
.code


Main PROC
    mov eax, x          ;eax <- x
    mov ebx, y          ;ebx <- y
    mov ecx, 0      ;ecx <- 0
    mov edx, 32      ;edx <- 32
.
.
.
.
call DumpRegs
exit
.
.
Title: Re: how do you display original values of registers
Post by: Mincho Georgiev on February 08, 2006, 08:25:52 PM
QuoteDumpRegs PROC valEAX:DWORD,valEBX:DWORD,valECX:DWORD,valEDX:DWORD
      LOCAL szEAX[32]:BYTE
      LOCAL szEBX[32]:BYTE
      LOCAL szECX[32]:BYTE
      LOCAL szEDX[32]:BYTE
         
         invoke wsprintf,addr szEAX,addr ctrl_str,valEAX
         invoke wsprintf,addr szEBX,addr ctrl_str,valEBX
         invoke wsprintf,addr szECX,addr ctrl_str,valECX
         invoke wsprintf,addr szEDX,addr ctrl_str,valEDX
            
            ;//print the buffers here////////
            ;////////////////////////////////
   ret
   DumpRegs ENDP
Title: Re: how do you display original values of registers
Post by: Mincho Georgiev on February 08, 2006, 08:27:19 PM
p.s.

Quote.data

   ctrl_str db "%lu",0
Title: Re: how do you display original values of registers
Post by: ramguru on February 08, 2006, 08:39:15 PM
Sorry, registers aren't backed up :)
Title: Re: how do you display original values of registers
Post by: Mincho Georgiev on February 08, 2006, 09:14:47 PM
no,no

I'm talking about this:

Quoteinvoke DumpRegs,eax,ebx,ecx,edx

Cause this is close enough to his posted code above  :wink
Title: Re: how do you display original values of registers
Post by: ramguru on February 08, 2006, 09:23:49 PM
Quote from: shaka_zulu on February 08, 2006, 09:14:47 PM
no,no
no no  :lol  :lol
I mean that if once any register is changed there is no chance to get its value back, there is no backup of it...
Title: Re: how do you display original values of registers
Post by: Mincho Georgiev on February 08, 2006, 09:28:30 PM
QuoteMain PROC
    mov eax, x          ;eax <- x
    mov ebx, y          ;ebx <- y
    mov ecx, 0      ;ecx <- 0
    mov edx, 32      ;edx <- 32
   
   invoke DumpRegs,eax,ebx,ecx,edx

   He dont need to back them up, because they are stored as a parameters of the Function.
   


Title: Re: how do you display original values of registers
Post by: ramguru on February 08, 2006, 09:33:42 PM
Let's have different opinions of what he wants, maybe one day he'll tell us that...  :wink
Title: Re: how do you display original values of registers
Post by: Mincho Georgiev on February 08, 2006, 09:38:13 PM
There is no 2 opinions about it,

as i said:

invoke DumpRegs,eax,ebx,ecx,edx

is equal to

push and call
so the registers are stored to the stack and i dont have any idea what else do you want to back up.
Title: Re: how do you display original values of registers
Post by: ramguru on February 08, 2006, 09:47:34 PM
Ok maybe my english is really worst than I thought  :red , but I think he meant:
pass some initial values to eax, ebx, ecx, then modify them in loop with god knows what number of iterations, then somehow make initial eax, ebx, ecx come back... If I get it wrong I really sorry for posting useless posts.
Title: Re: how do you display original values of registers
Post by: Mincho Georgiev on February 08, 2006, 09:53:29 PM
Ok, i got your point. Well as you saing maybe if he tell us,we will knew. :)
If the case is what you say ,you have right on 100%, i just thought that he want immediately to display them after they get the values.
But however, what i'm posting was the function to convert the values,nothing more, so you just finish the started.
BTW, dont worry about you english, i'm still fighting the language bareer as well.
Be well  :U
Title: Re: how do you display original values of registers
Post by: hutch-- on February 08, 2006, 10:21:23 PM
 :bg

What the big deal ? This is a trivial task.


.data
  _eax dd 0
  _ebx dd 0   etc ....
.....
.code
.....
  mov _eax, eax
  mov _ebx, ebx   etc .....


Display the DWORD variables as you like.
Title: Re: how do you display original values of registers
Post by: Mark Jones on February 08, 2006, 10:36:06 PM
Quote from: scooter4483 on February 08, 2006, 08:02:53 PM
...I want to display the [original] contents of eax and ebx [when i call dumpRegs at the of my code,] how do i do that?...

Hi Scooter. :) Look in the opcodes.hlp file for PUSH and POP. That should give you some ideas how to store data for later use.

As for actually displaying the register contents, here's one way to do it.


.data?
    szTemp    db 12 dup(?)                     ; reserve 12 bytes of RAM

.code
    mov eax,1234                               ; eax now contains 1234
    invoke dwtoa,eax,addr szTemp               ; convert EAX's contents into an ASCII string
    invoke MessageBox,0,addr szTemp,0,MB_OK    ; display string


This pops up an "error" message box with the number 1234 in its contents. Have fun!
Title: Re: how do you display original values of registers
Post by: Mincho Georgiev on February 08, 2006, 10:53:05 PM
Offcourse is not a big deal. I've just want to show wsprintf's way to convert reg's contents, nothing else, but anyway.
Title: Re: how do you display original values of registers
Post by: hutch-- on February 08, 2006, 11:16:23 PM
shaka,

The comment was not pointed at you.  :bg

Here is a quicky to show the 8 standard 32 bit registers.


; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

comment * -----------------------------------------------------
                        Build this  template with
                       "CONSOLE ASSEMBLE AND LINK"
        ----------------------------------------------------- *

    store_regs MACRO
      mov _eax, eax
      mov _ebx, ebx
      mov _ecx, ecx
      mov _edx, edx
      mov _esp, esp
      mov _ebp, ebp
      mov _esi, esi
      mov _edi, edi
    ENDM

    show_regs MACRO
      print hex$(_eax),"  EAX accumulator",13,10
      print hex$(_ecx),"  ECX counter",13,10
      print hex$(_edx),"  EDX data",13,10
      print hex$(_ebx),"  EBX base address",13,10
      print hex$(_esp),"  ESP stack pointer",13,10
      print hex$(_ebp),"  EBP base pointer",13,10
      print hex$(_esi),"  ESI source index",13,10
      print hex$(_edi),"  EDI destination index",13,10
    ENDM

    .data?
      _eax dd ?
      _ecx dd ?
      _edx dd ?
      _ebx dd ?
      _esp dd ?
      _ebp dd ?
      _esi dd ?
      _edi dd ?
    .code

start:
   
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    call main
    inkey
    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

main proc

    cls

    store_regs
    show_regs

    ret

main endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end start
Title: Re: how do you display original values of registers
Post by: zooba on February 08, 2006, 11:57:39 PM
Or you can always use PUSHAD and POPAD, as long as you don't mess up the stack in between. :U
Title: Re: how do you display original values of registers
Post by: korte on March 05, 2007, 10:56:22 AM
where to define this?
print hex$(_edi),"  EDI destination index",13,10
Title: Re: how do you display original values of registers
Post by: hutch-- on March 05, 2007, 11:53:27 AM
 :bg


; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

comment * -----------------------------------------------------
                        Build this  template with
                       "CONSOLE ASSEMBLE AND LINK"
        ----------------------------------------------------- *

    printregs MACRO
    .data?
      _eax dd ?
      _ecx dd ?
      _edx dd ?
      _ebx dd ?
      _esp dd ?
      _ebp dd ?
      _esi dd ?
      _edi dd ?
    .code
      mov _eax, eax
      mov _ebx, ebx
      mov _ecx, ecx
      mov _edx, edx
      mov _esi, esi
      mov _edi, edi
      mov _esp, esp
      mov _ebp, ebp
      pushad
      print "eax = "
      print str$(_eax),13,10
      print "ebx = "
      print str$(_ebx),13,10
      print "ecx = "
      print str$(_ecx),13,10
      print "edx = "
      print str$(_edx),13,10
      print "esi = "
      print str$(_esi),13,10
      print "edi = "
      print str$(_edi),13,10
      print "esp = "
      print str$(_esp),13,10
      print "ebp = "
      print str$(_ebp),13,10
      popad
    ENDM

    .code

start:
   
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    call main
    inkey
    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

main proc

    printregs

    ret

main endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end start


Result


eax = 0
ebx = 2147348480
ecx = 257
edx = -1
esi = 0
edi = 0
esp = 1245120
ebp = 1245168
Press any key to continue ...