Author Topic: how to handle the array in below given case  (Read 2907 times)

shahbaz.uol

  • Guest
how to handle the array in below given case
« on: June 04, 2013, 02:02:33 AM »
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

  • Member
  • *****
  • Posts: 8827
  • Still using Abacus 2.0
    • DednDave
Re: how to handle the array in below given case
« Reply #1 on: June 04, 2013, 02:35:52 AM »
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

Code: [Select]
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

Code: [Select]
INVOKE  dwtoa,eax,offset a
Code: [Select]
INVOKE  MessageBox,0,offset a,0,0
there is one more issue, as well

before using DIV, clear the high dword
Code: [Select]
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

  • Guest
Re: how to handle the array in below given case
« Reply #2 on: June 04, 2013, 02:26:57 PM »
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

  • Global Moderator
  • Member
  • *****
  • Posts: 1209
Re: how to handle the array in below given case
« Reply #3 on: June 04, 2013, 02:51:01 PM »
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):
Code: [Select]
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

  • Member
  • *****
  • Posts: 8827
  • Still using Abacus 2.0
    • DednDave
Re: how to handle the array in below given case
« Reply #4 on: June 04, 2013, 08:34:25 PM »
EDX is the remainder - AFTER the DIV