Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Another ASM question.....
#1
Is there a way to divide a 16 bit number such as FFFF FFFFh by an 8 bit number such as 000Ah without getting a divide overflow? :???: This is my code.....

Code:
MOV DX,FFFF
MOV AX,FFFF      ;DX:AX = FFFF FFFFh
MOV BX,000A
DIV BX           ;DX:AX/BX

The answer should be 1999 9999h. When I do this I get a divide overflow error. Sad

I can't use extended registers becaues I am using DEBUG.EXE.

Thanks for your help.
Reply
#2
Can you post the DIV instruction here? I Don't memorize stuuf and I don't have WEG right now.

But I as far as I could remember.... Divides the source by the accumulator. and returns the result on the accumulator itself but I may be wrong since its been a while since I last made ASM stuff.

:*)

And forget DEBUG as you can use DEBUG95 which supports 386 instructions.

As an alternative you could use Idiv.

But in ending, MUL multplies the AX by the source and Return the value in DX: AX so DIV would "prolly" Divide DX:AX by the source(BX in this case) and return the value in AX)
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#3
Here's something to do that:

Code:
; This divides DX:AX by BX and puts the result in DX:AX
; It does not give the remainder
PUSH DX
MOV AX, DX
XOR DX, DX
DIV BX
MOV CX, AX
POP AX
DIV BX
MOV DX, CX
Reply
#4
THANK YOU, It works! Big Grin Do you know if there is a fast way to caculate the remainder? I think the MUL command is to slow.
_____________________________________________________
The DIV command works like this......

DX = The higher word
AX = The lower word

"DIV BX" would divide DX:AX by BX.

The result would go in AX and The remainder would go in DX.
Reply
#5
I figured it out. Smile Thanks again.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)