News:

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

Main Menu

how to handle the array in below given case

Started by shahbaz.uol, June 04, 2013, 02:02:33 AM

Previous topic - Next topic

shahbaz.uol

include/masm32/include/masm32rt.inc

.data
a db ?
ab dd 1,2,23,24,25,28,64,32,12,11
divisor dd 2
.code
start:
mov ecx,4
mov ebx,0
mov edx,0   ; clear dividend, high

myloop:
    mov eax,ab[ebx]   ; dividend, low
    div divisor   ;
    add ebx,4
    call output
loop myloop

output proc

push offset a
push eax
call dwtoa

push 0
push 0
push offset a
push 0

call MessageBoxA
ret
output endp
end start

dedndave

the "a" array should be more than a single byte in length
a dword, when converted to unsigned decimal ascii, may yield up to 10 digits and a null string terminator
(0 to 4294967295)
so, the byte buffer should be at least 11 bytes long
make it 12 to keep everything 4-aligned   :t

a db 12 dup(?)
creates a buffer that is 12 bytes long

also, it helps to use INVOKE, rather than PUSH, PUSH, CALL
it makes the code easier to read
there are times when the other method can be better - advanced stuff

INVOKE  dwtoa,eax,offset a
INVOKE  MessageBox,0,offset a,0,0

there is one more issue, as well

before using DIV, clear the high dword
xor edx,edx   ;high dword = 0
div divisor

you should do this on each pass of the loop - not just once at the beginning

shahbaz.uol

thanks, actually i'm new to ASM, so need many things to learn.
can you tell me what is ment by this statement
xor edx,edx
edx is reminder. what is function of xor???

MichaelW

XORing a register with itself is a way of zeroing it, using an instruction with a shorter encoding than a MOV r32, 0 (in the disassembly below the first column is the address and the second is the binary encoding of the instruction, both in hexadecimal):

00401000 BA00000000             mov     edx,0
00401005 33D2                   xor     edx,edx


For the DIV instruction, with a 32-bit divisor the dividend is the 64-bit value in EDX:EAX.

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

dedndave