NASM Forum > Programming with NASM

Using idiv

(1/3) > >>

JohnG:
Hi all,

It seems simple enough, but what am I doing wrong, just trying things at the moment with no luck.

I did read somewhere that the divisor had to be a smaller data size than the dividend ?

start:
        and     rsp,    -16  ;stack align
       
       
        mov     rax,    [a]    ; a = 100  dividend
        xor     rdx,    rdx
        mov     r8,    [sum]  ; sum = 4
        idiv    dword[r8]       
        mov     rcx,    fmt
        mov     rdx,    [r8]   ; value to print
        sub     rsp,    32      ; shadow space
        call    printf
        add     rsp,    32

I may be stomping on registers ?

John

Frank Kotler:
Here you are moving the number 4 into r8

--- Code: ---mov     r8,    [sum]  ; sum = 4

--- End code ---

Here you are dividing by the number at address 4!

--- Code: ---        idiv    dword[r8]       
 
--- End code ---

Try:

--- Code: ---idiv r8

--- End code ---

Warning: untested!

Best,
Frank



debs3759:
idiv dword[r8] divides rax by the value stored at the memory address pointed to by r8. You want


--- Code: ---idiv    r8
--- End code ---

I also don't think using dword (32-bits) with a 64-bit register would be right, and am sure you don't need it anyway.

JohnG:
Hi Frank,

I tried that, and I get a message   "operation size not specified"



Anyway to avoid that damn Anti-spam task ?

JohnG:
hi,

Made the other changes and program just crashes, no errors showing when compiling.

Navigation

[0] Message Index

[#] Next page

Go to full version