Qbasicnews.com
May 26, 2019, 10:44:45 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: "idiv"ing double words  (Read 2959 times)
rCX
Member
*
Posts: 32


« on: July 28, 2004, 03:45:20 PM »

I'm stuck  Sad

Awhile back I asked if there was a way to divide dx:ax by bx and get a double word anwer.  (like FFFFFFFFh / Ah = 19999999h) and I got this peice of code.....

Code:
;*dx:ax/bx; dx:ax = answer, cx = remainder*
push ax ;save ax (lower word)
mov ax,dx ;higher word into ax so it can be divided
xor dx,dx ;dx = 0
div bx ;dx:ax/bx; ax = answer dx = remainder
mov cx,ax ;save higher word
pop ax ;get ax, the lower word
div bx ;dx:ax/bx again
xchg dx,cx ;extange;dx = higher word cx = remainder


I was wondering if anyone knew how to do the same thing with the "idiv" (divide with sign) function.  Thanks.
Logged
DrV
Na_th_an
*****
Posts: 1553



WWW
« Reply #1 on: July 29, 2004, 09:29:49 AM »

If that code above is correct (too lazy to check it now), just replace div with idiv.
Logged
rCX
Member
*
Posts: 32


« Reply #2 on: July 30, 2004, 06:22:28 PM »

Sorry I took so long....
I got this piece of code to work most of the time but when I tried to divide 6 0000h by Ah or 6 0000h by FFF6  (-Ah) I get a divide overflow error.
Code:
;Register Function
;dx:ax dividend (number to be divided)
;bx divisor (number dividend is divided by)
;
;dx:ax/bx     dx:ax = answer, cx = remainder
push ax        ;save ax (lower word)
mov ax,dx    ;higher word into ax so it can be divided
cwd              ;convert dx:ax to word
idiv bx          ;dx:ax/bx; ax = answer dx = remainder
mov cx,ax    ;save higher word
pop ax         ;get ax, the lower word
idiv bx          ;dx:ax/bx again
xchg dx,cx    ;extange;dx = higher word cx = remainder
Logged
relsoft
*/-\*
*****
Posts: 3927



WWW
« Reply #3 on: August 01, 2004, 03:30:12 AM »

Why not try to do a:

Code:
Cwde
Cdq
Movsx ebx, bx
idiv ebx


instead of a

Code:
cwd
idiv bx


Dunno if you can use extended regs though. :*)
Logged

y smiley is 24 bit.


Genso's Junkyard:
http://rel.betterwebber.com/
rCX
Member
*
Posts: 32


« Reply #4 on: August 01, 2004, 08:12:27 PM »

I'm using DEBUG.exe I can't use double words...  Sad
Logged
Plasma
Na_th_an
*****
Posts: 1770


WWW
« Reply #5 on: August 01, 2004, 09:44:07 PM »

http://www.aogosoft.com/download/debug32.rar
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!