News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

(a+b)/2...

Started by nick, May 14, 2012, 03:02:21 PM

Previous topic - Next topic

nick

I try to do (a+b)/2 mathematic formula.. i try to modify dis addition code.. how??


include \masm32\include\masm32rt.inc

       .data?

var1    dd ?
var2    dd ?


       .code

start:
       mov     var1,sval(input("First Number: "))
       mov     var2,sval(input("Second Number: "))
     

       mov     eax,var1
        add eax,var2

       
        print ustr$(eax),13,10

       inkey
       exit

       end     start

clive

        mov     eax,var1
        add eax,var2
        shr  eax,1
It could be a random act of randomness. Those happen a lot as well.

dedndave

well - the next problem in the book will be to show the remainder or divide by 3 or something - lol

        mov     eax,var1
        add     eax,var2
        mov     ecx,2
        mov     edx,0
        div     ecx

;EAX = quotient, EDX = remainder

xiahan

Quote from: dedndave on May 14, 2012, 05:05:58 PM
well - the next problem in the book will be to show the remainder or divide by 3 or something - lol

        mov     eax,var1
        add     eax,var2
        mov     ecx,2
        mov     edx,0
        div     ecx

;EAX = quotient, EDX = remainder


should the edx always be initial to 0 , i test

movzx eax,[ebx].xorigin
mul lPixel ;word
mov edx,eax
push edx
movzx eax,[ebx].yorigin
mul spw ;dword
pop edx
add edx,eax


if i didn't push/pop edx ,it will be flushed to 0

so if no initialization was made on edx in div,

i think the edx will also be flushed to 0 if the reminder is happen to 0

dedndave

EDX does not need to be initialized for MUL
it does need to be initialized when using DIV with a 32-bit operand

xiahan

Quote from: dedndave on May 20, 2012, 11:33:25 PM
EDX does not need to be initialized for MUL
it does need to be initialized when using DIV with a 32-bit operand

got it