News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

MASM32 - print regsiter

Started by Farmek, April 12, 2013, 03:32:57 AM

Previous topic - Next topic

Farmek

Hello :biggrin:, i need to know how to print out a register(eax for an example). I tried to google it but i haven't found any answer yet.

RuiLoureiro

Quote from: Farmek on April 12, 2013, 03:32:57 AM
Hello :biggrin:, i need to know how to print out a register(eax for an example). I tried to google it but i haven't found any answer yet.
Is this you want ?
                print str$(eax)  or print str$(eax),13,10

dedndave

the "str$" macro will give you the signed decimal ascii string
"ustr$" will give you the unsigned decimal ascii string
"uhex$" will give you the unsigned hexidecimal ascii string - not sure that unsigned/signed is really relavant for hex   :P

Rui has also shown you one use of the "print" macro, which applies only to console apps

the masm32 library also has a dw2bin_ex function to show it as binary
i think there's a CRT function that will do that, too - i forget what it is

Farmek

this is my code i'm just trying to do something simple. i tried your code but the result was 1947533312

include \masm32\include\masm32rt.inc 

.data

msg db "Hello world",0

.code
start:

mov ecx, 5
sub ecx, 4
cls
print str$(ecx),13,10;

inkey "pause"

jmp start

ret


call ExitProcess

end start

GoneFishing

Try this:
start:
cls
mov ecx, 5
sub ecx, 4
print str$(ecx),13,10
inkey "pause"

jj2007

Quote from: Farmek on April 12, 2013, 04:26:19 AM
this is my code i'm just trying to do something simple. i tried your code but the result was 1947533312
...
mov ecx, 5
sub ecx, 4
cls
print str$(ecx),13,10;

cls is a Masm32 macro that trashes ecx. Search for preservation in this page.

This will work:
cls
mov ecx, 5
sub ecx, 4
... simply because cls (trashing ecx) comes before the mov+sub instructions.

MichaelW

#6
Why not use the printf macro?

;==============================================================================
    include \masm32\include\masm32rt.inc
;==============================================================================
bin$ MACRO DDvalue
    IFNDEF _rv_bin_string_
        .data
            _rv_bin_string_ db 36 dup(0)
        .code
    ENDIF
    invoke crt__itoa, DDvalue, ADDR _rv_bin_string_, 2
    EXITM <ADDR _rv_bin_string_>
ENDM
;==============================================================================
    .data
    .code
;==============================================================================
start:
;==============================================================================
    xor ebx, ebx
  @@:
    ;------------------------------------------------------------------
    ; Display value of EBX in hexadecimal, decimal, octal, and binary.
    ;------------------------------------------------------------------
    printf("%X\t%d\t%o\t%s\n", ebx, ebx, ebx, bin$(ebx))
    inc ebx
    cmp ebx, 256
    jb  @B
    inkey
    exit
;==============================================================================
end start


0       0       0       0
1       1       1       1
2       2       2       10
3       3       3       11
4       4       4       100
5       5       5       101
6       6       6       110
7       7       7       111
8       8       10      1000
9       9       11      1001
A       10      12      1010
B       11      13      1011
C       12      14      1100
D       13      15      1101
E       14      16      1110
F       15      17      1111
10      16      20      10000
. . .


http://msdn.microsoft.com/en-US/library/wc7014hz(v=vs.80).aspx

Well Microsoft, here's another nice mess you've gotten us into.