News:

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

displaying any register on the screen

Started by williec35, May 15, 2009, 01:09:50 AM

Previous topic - Next topic

williec35

Hi, I'm new to MASM32 but I  have program in assembly before( i just know a llittle bit). I'm trying to refresh my self on how  the assembly opcode works by manipulating the general register (eax, ecx,  al, ah, ax..etc).  The  only problem  i have  is  that  i don't  know  how to display the  content  of the register.  how  do i display  eax, ah, al, ecx   ...?  I will appreciated  any help i could  get  Thanks

hutch--

Willie,

Unless you feel like writing integer to string conversions then console display procedures, use the masm32 library and macros to perform this task.

Look at the "print" macro for console display and the "str$" macro to convert the contents of the register to a displayable string. You can alternatively use the direct procedures in the masm32 library and if you want to write the whole lot yourself, the source code for those procedures is available in the m32lib directory.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

williec35

Thanks  for  the input.... :)  one  thing  i notice though is that str$ wouldn't display al or ah,  it has  to be a 32 bit  register like  eax.  What would  be the most efficent/easy way  to display just the al or ah register. I'm thinking of creating my own verion  of  the StdOut procedure,   that would some how  mask  out  the eax  register   to get  the  ax,   al  and  ah  component .  What would  be your  opinion  on this.  Again  thanks  for the input  :)

MichaelW

You could take the byte or word register and zero-extend (or sign-extend, depending on what you are doing) it into a 32-bit register. For example:

movzx eax, al
print str$(eax)

eschew obfuscation

williec35

Thanks MichaelW .. thats  actually a way better idea!!!!!!!

hutch--

Now if you want to be a real purist so that you don't modify the EAX register try this.


push eax
movzx eax, al
print str$(eax),13,10
pop eax


You push EAX before so its saved on the stack and after you have shown the result restore EAX with the POP so it has not been changed by displaying it.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

dedndave

a real purist would not use str$ at all
he would (i did) write routines to convert to decimal or hex strings and display them

UtillMasm

i like your answer!
:cheekygreen: :dance: :toothy

williec35

Thanks hutch  :) ,   Hey david  you  think  you could  post  the  code  you  wrote  for displaying the register... Just  curious  to  see  how  you wrote  it.. I know  you have a nack for  writing  very fast and efficent code, I seen some  of your  posted  comment/codes   :)

dedndave

#9
i dunno 'bout all that - lol
i like to write code - and i try to make it fast - but most of the guys in here can do better
i am new to the 32-bit world

this rountine converts eax to an ASCII hex string
it could be easily modified for smaller registers
no registers are preserved - just add push/pop as needed
i use the same buffer for 64-bit decimal so it is larger than required
if i wanted to make it faster, i suppose i could unroll the loop and plant 2 or 4 ascii bytes at a time

.data
AscBuf  db        '01234567890123456789',0 ;20 digits

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

Hex32   proc

;Convert 32-bit binary to ASCII hexidecimal
;
;Call With: EAX= DWORD value to convert
;
;  Returns: EDI= offset into AscBuf of first hexchar
;              = offset AscBuf+12

        std
        mov     edi,offset AscBuf+19
        mov     edx,eax
        mov     ecx,8

Hex32a: and     eax,0Fh
        add     eax,90h
        daa
        adc     eax,40h
        daa
        stosb
        shr     edx,4
        mov     eax,edx
        loop    Hex32a

        cld
        inc     edi
        ret

Hex32   endp

;--------------------------------------------------------

dedndave

#10
this is what an 8-bit routine might look like....


;--------------------------------------------------------

Hex08   proc

;Convert 8-bit binary to ASCII hexidecimal
;
;Call With: AL= BYTE value to convert
;
;  Returns: EDI= offset into AscBuf of first hexchar
;              = offset AscBuf+18

        mov     edi,offset AscBuf+18
        mov     edx,eax
        and     eax,0Fh
        add     eax,90h
        daa
        adc     eax,40h
        daa
        xchg    eax,edx
        shr     eax,4
        and     eax,0Fh
        add     eax,90h
        daa
        adc     eax,40h
        daa
        mov     ah,dl
        mov     [edi],ax
        ret

Hex08   endp

;--------------------------------------------------------



williec35

Hey Thanks  alot david...  I'm not sure  what "OPTION PROLOGUE:PrologueDef " and   "OPTION EPILOGUE:EpilogueDef" means.

dedndave

well - the assembler sets up stack frames by default
i don't want (or like or need) the added overhead so i tell it not to
if i want a stack frame, i will set it up myself
but - they may be used in the libraries
so - when i am done - i set the options back to default
(ty Jochen for teaching me)

Vortex


include Test.inc

printX MACRO buffer:REQ,_format:REQ,args:VARARG

    invoke  wsprintf,buffer,_format,args
    invoke  StdOut,buffer
   
ENDM

.data

format1 db '%s , X = %d , Y = %d',0
msg     db 'printX test',0

.data?

buffer  db 100 dup(?)

.code

start:

    mov     eax,49152
    mov     ecx,16384
    printX  ADDR buffer,ADDR format1,ADDR msg,eax,ecx
    invoke  ExitProcess,0
   
END start

[attachment deleted by admin]

dedndave

hey Vortex - the macro library has one that would have done what i want using wsprintf
i tried using udq$ (i think that's the one) but no luck - so i wrote my own 64-bit unsigned to ascii decimal routine
i am too much of a n00b to figure out how to use all the libraries - they aren't always documented
once i wrote that routine, started writing the other ones - they are easy
64-bit to decimal is a little tricky though - lol