Author Topic: why print str$(eax), 10,13 will generate 2  (Read 1768 times)

aki

  • Guest
why print str$(eax), 10,13 will generate 2
« on: February 13, 2014, 01:47:10 PM »
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

  • Member
  • *****
  • Posts: 8752
  • Still using Abacus 2.0
    • DednDave
Re: why print str$(eax), 10,13 will generate 2
« Reply #1 on: February 13, 2014, 02:40:28 PM »
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--

  • Administrator
  • Member
  • ******
  • Posts: 4935
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: why print str$(eax), 10,13 will generate 2
« Reply #2 on: February 13, 2014, 03:32:33 PM »
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$()".

Code: [Select]

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
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

Oliver Scantleberry

  • Guest
Re: why print str$(eax), 10,13 will generate 2
« Reply #3 on: April 09, 2016, 01:53:50 PM »
Where does one look for info on stuff like  "ustr$() or sstr$()"? I don't recall seeing this stuff in my MASM32 help.

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4935
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: why print str$(eax), 10,13 will generate 2
« Reply #4 on: April 09, 2016, 03:26:12 PM »
Look in the "macros.asm" file.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin: