News:

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

Main Menu

why print str$(eax), 10,13 will generate 2

Started by aki, February 13, 2014, 01:47:10 PM

Previous topic - Next topic

aki

hello, i am new to MASM32 and new to assembly language too, currently i am trying to learn this language and working out with the sample program as following and the results generated was "777, 444, -2". Where the "-2" come from? i understand that neg is for negative but why "2" has been generated for eax? please help.

include \masm32\include\masm32rt.inc
include \masm32\macros\macros.asm     
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

.data
    first dd 333
    second dd 444

.code
start:
    mov eax, first   
    mov ebx, second
    add eax, ebx
    print str$(eax), 10,13
    print str$(ebx), 10,13
    neg eax
    print str$(eax), 10,13 ;this line is generating "-2" in result
    exit

end start



dedndave

the print and str$ macros destroy the contents of EAX, ECX, and EDX
many masm32 functions, macros, and windows functions will destroy the contents of those 3 registers

use PUSH and POP around calls - or store it in EBX, ESI, EDI (or even EBP in this case)

hutch--

Give this a try. Its common to try and use registers as variables but you have to be careful with how you use them as the transient registers are normally overwritten by any other procedure call, both "print" and "ustr$() or sstr$()".



include \masm32\include\masm32rt.inc

; include \masm32\macros\macros.asm     
; includelib \masm32\lib\masm32.lib
; includelib \masm32\lib\gdi32.lib
; includelib \masm32\lib\user32.lib
; includelib \masm32\lib\kernel32.lib

.data
    first dd 333
    second dd 444
    result dd 0

.code
start:
;     mov eax, first   
;     mov ebx, second
;     add eax, ebx
;     print str$(eax), 10,13
;     print str$(ebx), 10,13
;     neg eax
;     print str$(eax), 10,13 ;this line is generating "-2" in result
;     exit

    mov eax, first
    add eax, second
    mov result, eax

    print ustr$(first),13,10
    print ustr$(second),13,10
    print ustr$(result),13,10

    mov eax, result
    neg eax
    print sstr$(eax),13,10



    inkey

    exit

end start

Oliver Scantleberry

Where does one look for info on stuff like  "ustr$() or sstr$()"? I don't recall seeing this stuff in my MASM32 help.

hutch--