assembly - Incrementing integer values, output unexpected -


i working on x86 asm program part of output numbers have been incrementing @ various stages. output numbers hardly expect... having trouble tracking down error.

initialized like:

section .data     ...     numinc: db 0     numdec: db 0     numsum: db 0 

incremented like:

    inc     dword [numinc]     inc     dword [numsum]     push    stringopt3     call    printf     add     esp, 4 

printed like:

    push    dword [numinc]     push    dword [sum]     push    dword [numdec]     push    dword [sum]     push    outputstring     call    printf     add     esp,20 

where outputstring is: (also in .data section, naturally)

    outputstring: db `\nset{1}: %5d/%d\nset{2}: %5d/%d\n`,10,0 

and output like:

set{1}: 134521233/514 set{2}: 134521233/131584 

so, i'm expecting results in neighborhood of 0/3 1/3 ... ! also, expect denominators same considering right==>left push pattern printf.

i'm on linux x86 processor using nasm assemble , gcc link.

change

numinc: db 0 numdec: db 0 numsum: db 0 

to

numinc: dd 0 numdec: dd 0 numsum: dd 0 

if you're going increment them with:

inc     dword [numinc] 

by changing db dd make numinc , friends take 4 bytes instead of one. when later inc or push data dwords (4 bytes) size of operations , size of data must match.

otherwise, when increment numinc takes 1 byte dword you'd clobber bytes following if numinc 255. when push 1 byte numinc dword, in fact pushing 3 bytes follows well.

when printing result, c code:

printf(outputstring, numdec, sum, numinc, sum); 

should translated to:

push    dword [sum] push    dword [numinc] push    dword [sum] push    dword [numdec] push    outputstring call    printf add     esp,20 

i assume that's how expecting 0/3, 1/3 output since 2 "3" sum.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -