News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

how do you display original values of registers

Started by scooter4483, February 08, 2006, 08:02:53 PM

Previous topic - Next topic

scooter4483

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
.
.

Mincho Georgiev

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

Mincho Georgiev


ramguru


Mincho Georgiev

no,no

I'm talking about this:

Quoteinvoke DumpRegs,eax,ebx,ecx,edx

Cause this is close enough to his posted code above  :wink

ramguru

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...

Mincho Georgiev

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.
   



ramguru

Let's have different opinions of what he wants, maybe one day he'll tell us that...  :wink

Mincho Georgiev

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.

ramguru

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.

Mincho Georgiev

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

hutch--

 :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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Mark Jones

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!
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Mincho Georgiev

Offcourse is not a big deal. I've just want to show wsprintf's way to convert reg's contents, nothing else, but anyway.

hutch--

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
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php