hi all,i want to know how can i make an arithmetic by ASM? can anyone show me an example?

for example:
  sub eax,eax
  sub ebx,ebx
  mov eax,1d
  mov ebx,2d
add eax,ebx

at last,i find out that content of eax is an address ,not 3d.
How can i make a plus and get the right result?

question 2:
        how can i display the address in register? i want to use the MessageBox function.
Posted on 2005-08-10 08:09:37 by Abuseyourdna
1) From your example, the data in the register is not an address. The value in eax is indeed 3.Take a look in a debugger if you don't believe.

2) If you are using masm32, you can find atodw in masm32.lib. Use it.
Posted on 2005-08-10 08:17:09 by roticv
my program as follow:




.586
.model flat,stdcall
option casemap:none


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

.data
limit equ 50
K32_Limit dw limit
szTitle db "Test program",0
szText db "We Get the K32 address!",0

.code


delta:
pop ebp
sub ebp,offset delta

mov esi,
and esi,0ffff0000h
call GetK32

push 00000000h
call ExitProcess


GetK32:
_1:
cmp byte ptr ,00h
jz WeFailed

cmp word ptr ,"ZM"
jz CheckPE


_2:
sub esi,10000h
dec byte ptr
jmp _1


CheckPE:
mov edi,
add edi,esi
cmp dword ptr ,"EP"
jz WeGotK32
jmp _2


WeFailed:
mov esi,0Bff70000h

WeGotK32:
xchg eax,esi

invoke MessageBox,NULL,addr szText,addr szTitle,MB_OK
ret

end delta






i want to use the messagebox function to display the address in eax,just like 0BFFF000h. How can i make it ?


ps:MASM32
Posted on 2005-08-10 08:30:05 by Abuseyourdna
Use dw2hex from the masm3.lib Check the help file for more details.
Posted on 2005-08-10 09:00:51 by roticv
.386
.model flat,stdcall
option casemap:none

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

.data
szTitle db "Arithmetic",0
deformat db "%8x",0
deformat1 db "%2d",0
.data?
outputbuffer db 8 dup(?)

.code
start:
sub eax,eax
sub ebx,ebx
mov eax,3d
mov ebx,4d
add eax,ebx
invoke wsprintf,addr outputbuffer,addr deformat1,eax
invoke MessageBox,NULL,addr outputbuffer,addr szTitle,MB_OK
invoke ExitProcess,0

end start




use the wsprintf,i solved the problem. 
Posted on 2005-08-10 09:27:35 by Abuseyourdna