News:

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

How to view the register?

Started by zhiling0229, March 03, 2007, 03:20:39 AM

Previous topic - Next topic

zhiling0229

Hi,

i would like to know how display the registers and flags before exiting the program?

  .386                   ; set processor type, another option is .686
  .model flat, stdcall   ; memory model & calling convention
  option casemap :none   ; case sensitive

  ; ----------------------------------------------
  ; Include any needed INCLUDE and LIBRARY files
  ; and procedure prototypes.
  ; ----------------------------------------------
  include \masm32\include\windows.inc
  include \masm32\include\user32.inc
  include \masm32\include\kernel32.inc

  includelib \masm32\lib\user32.lib
  includelib \masm32\lib\kernel32.lib

Main PROTO

  ; ---------------------------------------------------
  ; Include any needed global constants and variables
  ; both initialized and uninitialized
  ; ---------------------------------------------------
.const
    con_init equ 255
.data
    var_init dd 0
   
.data?
    var_unin dd ?


.code
start:

  invoke Main
  invoke ExitProcess,0

Main PROC
  mov   eax,10000h      ; EAX = 10000h
  add   eax,40000h      ; EAX = 50000h
  sub   eax,20000h      ; EAX = 30000h
                                ; What should I put here?
  ret
Main ENDP

end start

dsouza123

An example using MessageBoxes, for windowed output,
there are two nearly identical message boxes
the first shows the values in decimal,
the second in hexadecimal.

It is a takeoff on Hutch's console version.
http://www.masm32.com/board/index.php?topic=3876.msg28893#msg28895


[attachment deleted by admin]

TNick

If you want to avoid the obvious solution (using a debuger), you may
- use macros from \masm32\macros if you are building a console exe (print, chr$, ustr$, sstr$, hex$)

Main PROC
  mov   eax,10000h      ; EAX = 10000h
  add   eax,40000h      ; EAX = 50000h
  sub   eax,20000h      ; EAX = 30000h
                                ; What should I put here?
  push eax ; the print macro will mess up your eax register, so save it onto the stack
  print "EAX value at the end of the function is: " ; put a text on the console
  pop eax ; reload eax with it's saved value from stack
  print hex$(eax),13,10 ; convert numeric valkue of the eax to it's string reprezentation in hexadecimal
  ;print this string and insert a new line (13,10)
  inkey  ; will output "Push any key to continue ..." and wait for a key stroke
  ret
Main ENDP


- use dwtoa or dw2hex from masm32.lib and use OutputDebugString API function

Nick

dsouza123

The attachment is a screenshot of the hexadecimal version of the registers and flags MessageBox.



[attachment deleted by admin]

PBrennick

This is very nice and very useful. May I add this to the GeneSys project?

Paul
The GeneSys Project is available from:
The Repository or My crappy website