News:

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

Can help me solve this ques?? Error A2022...

Started by nick, May 11, 2012, 02:43:16 PM

Previous topic - Next topic

Ryan

#15
Can I upload and embed images directly?  For now I'll upload it with my post.

EDIT: I'm testing an embed...

dedndave

thanks - you can remove it, now   :U

i was missing the INI and QSC files   :P

dedndave

big difference - lol
now - if i can just get right-click/copy and right-click/paste down to 2 steps   :P

Ryan - i have been using ImageShack for an image host
but - they won't host animated GIF's anymore
so - i just now signed up for PhotoBucket - let's see how it goes...

there is an icon above the smileys
or, you can add tags...
[img][/img]

Ryan

Yeah.  I saw the img tags.  I've just never gotten into using an image hosting account.  Maybe it's time I jump on the bandwagon  :lol

nick

Dedndave.. thanksss.. i done d ADDITION method.. if now i wan to switch to DIVISION method.. izit onli change the ADD to DIV??

dedndave

#20
no - DIV is a bit different   :P

to understand how DIV works, it is easiest to first understand MUL

when you multiply two 32-bit values, you may get a result that is as large as 64 bits
when we use the MUL instruction, the operand is multiplied by the contents of EAX
when you are done, the result is in EDX:EAX - forming a single 64-bit number

        mov     eax,4000000000
        mov     ecx,3000000000
        mul     ecx

;EDX:EAX = 3000000000 x 4000000000 = 12000000000000000000 = 0A688906BD8B00000h
;EDX = 0A688906Bh (high 32 bits) and EAX = 0D8B00000h (low 32 bits)


DIV works just the opposite of MUL
when you divide by a 32-bit operand, EDX:EAX are treated as a single 64-bit number

        mov     edx,0A688906Bh
        mov     eax,0D8B00000h
        mov     ecx,3000000000
        div     ecx

;EAX = quotient = 4000000000
;EDX = remainder which, in this case, happens to be 0


so - if you are going to divide a 32-bit value by another 32-bit value, you need to set EDX to 0, first

        mov     eax,13
        mov     edx,0     ;set the high dword to 0
        mov     ecx,3
        div     ecx

;EAX = 4 (quotient)
;EDX = 1 (remainder)

jj2007

Negative numbers can produce nice effects:
mov eax, -100
mov ecx, 10
cdq
div ecx

nick


dedndave

Quote from: dedndave on May 12, 2012, 05:48:20 PM
to understand how DIV works, it is easiest to first understand MUL

if you learn about MUL first, learning about DIV will be easier

dedndave

       include \masm32\include\masm32rt.inc

       .data?

var1    dd ?
var2    dd ?

       .code

start:
       mov     var1,sval(input("  Dividend: "))
       mov     var2,sval(input("   Divisor: "))

       mov     eax,var1
       mov     edx,0
       div     var2

       push    edx
       push    eax
       print   chr$(13,10," Quotient = ")
       pop     eax
       print   ustr$(eax),13,10
       print   chr$("Remainder = ")
       pop     edx
       print   ustr$(edx),13,10

       inkey
       exit

       end     start


don't try to divide by 0 !   :red

jj2007

Quote from: dedndave on May 13, 2012, 03:57:39 AM
don't try to divide by 0 !   :red

Try!

include \masm32\MasmBasic\MasmBasic.inc   ; download
  Init tc
  inc MbFlags[4]
  .Repeat
   push Val(Input$("\tDividend: ", "1000"))
   mov ecx, Val(Input$("\tDivisor: ", "0"))
   pop eax
   cdq
   Try
      div ecx
   Catch only
      invoke RaiseException, 195948557, EXCEPTION_NONCONTINUABLE, 0, 0
   Finally
   Inkey Str$("The result is %i. One more (n)?", eax)
  .Until eax=="n"
  Exit
  TryCatchEnd
end start

P.S.: Attached exe works only from the commandline :wink

nick


jj2007

Quote from: minsiong on May 13, 2012, 06:55:19 AM
How about multiplication??

You should read \masm32\help\opcodes.chm, especially
div
idiv
mul
imul

dedndave

a little mod to avoid divisor = 0   :bg
       include \masm32\include\masm32rt.inc

       .data?

var1    dd ?
var2    dd ?

       .code

start:
       mov     var1,sval(input("  Dividend: "))

retry:
       mov     var2,sval(input("   Divisor: "))
       cmp     var2,0
       jz      retry

       mov     eax,var1
       mov     edx,0
       div     var2

       push    edx
       push    eax
       print   chr$(13,10," Quotient = ")
       pop     eax
       print   ustr$(eax),13,10
       print   chr$("Remainder = ")
       pop     edx
       print   ustr$(edx),13,10

       inkey
       exit

       end     start


for MUL...
no need to retry for 0
change the prompt text's - EDX will have the high dword, not the remainder - for many numbers, just show EAX
remove the "mov edx,0" line
change DIV to MUL

dedndave

nice Jochen   :bg
        Dividend: 1000
        Divisor: 0


Exception (line ??):
Code    0BADF00D
EIP     7C812AFB