News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

division With Remainder Example

Started by hfheatherfox07, January 06, 2013, 12:51:16 AM

Previous topic - Next topic

FORTRANS


hfheatherfox07

Hello,

Quote from: hool on January 08, 2013, 11:15:03 PM
        mov     eax, 200
        mov     ecx, 100             
        mul     ecx
        mov     ecx, 31
        div     ecx
        mov     esi, eax
        mov     edi, eax
        invoke  wsprintf, addr buffer, addr Format, esi, edi
        invoke  MessageBox, 0,addr buffer, 0, MB_ICONQUESTION+MB_OK
Now you have to explain why you see "645.645"

        mov     eax, 0xffffffff
        mov     ecx, 100             
        mul     ecx
        mov     ecx, 31
        div     ecx
        mov     esi, eax
        mov     edi, eax
        invoke  wsprintf, addr buffer, addr Format, esi, edi
        invoke  MessageBox, 0,addr buffer, 0, MB_ICONQUESTION+MB_OK
Now you have to explain why it crashes

        xor     edx, edx
        mov     eax, 200
        mov     ecx, 31
        div     ecx
        mov     esi, eax
        mov     eax, edx
        imul    eax, 100
        xor     edx, edx
        div     ecx
        mov     edi, eax
        invoke  wsprintf, buffer, Format1, esi, edi
        invoke  MessageBox, 0,addr buffer, 0, MB_ICONQUESTION+MB_OK   
Now you have to explain why you see "6.45"

And only after all that do something more complex

For the record I asked , about the error I was getting with   cmovnz  edx, ecx        ; edx =5 (or =33 in previous example)  division.asm(37) : error A2085: instruction or register not accepted in current CPU mode I am not familiar with  cmovnz instruction ... Not about 0xffffffff 

Also I still Don't get were you are Going with this?
"threshold" must be minimun 100 but can be any 24bit number

if (divisor <= threshold) {
        xor     edx, edx
        mov     eax, dividend
        mov     ecx, divisor
        div     ecx
        mov     eax, edx
        imul    eax, 100
        xor     edx, edx
        div     ecx
        ; now you need to get rid of 0
        ; If your end goal is to convert o ASCII then getiing rid of zero is best done prior to the conversion
}else{
        mov     eax, dividend
        mov     ecx, 100             
        mul     ecx
        mov     ecx, divisor
        div     ecx
        ; now you need to separate the remainder and get rid of 0.
        ; If your end goal is to convert o ascii then separating(and zero elimination) is best done after conversion, probably


But to answer your question best I can

Q 1. Now you have to explain why you see "645.645"
A 1. you are dividing 200 by 31 and moving the Quotient to eax twice without dividing it by 100
Q 2.Now you have to explain why it crashes
A 2. 0xffffffff or in MASM  0FFFFFFFFh   Alternative representation  -1 as error indicator flag , also as a max unsigned Variable ( the larger of the 2 numbers ) So In this case I assume you meant it o represent a number larger than 31.
Q 3.Now you have to explain why you see "6.45"
A 3. you are properly dividing now and moving the Quotient  and remainder (to 2 decimal places) to proper registers to show it
esi = Quotient  and edi = remainder

:(
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

Dubby

division.asm(37) : error A2085: instruction or register not accepted in current CPU mode

you need to define the "cpu model" at least
.686

masm32rt.inc defined it as .486

hfheatherfox07

@Dubby
Thanks !!!!  :biggrin:
I never encountered any thing where that made a difference before
Experience says a lot ! Thank you again Dubby  :biggrin:
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.