Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Division Help

Status
Not open for further replies.

JimBo3108

MIS
Dec 20, 2006
1
0
0
US
Working on a programming exercise... and having a brain fart of sorts. Could someone please help me correct this division syntax?

Thanks!!

>>>>>>

Divi cjbe Input2Hi,#0,Zerocheck
Zerocheck cjbe Input2Lo,#0,ZeroDiv
clr quotient ;initializes quotient to zero
Divloop cjbe Input1Hi,Input2Hi,donedivhi ;checks if highbit of dividend LT or = to highbit of divisor

mov DiffLo,Input1Lo
mov DiffHi,Input1Hi
clc
sub DiffLo,Input2Lo
jc DecHi2 ;if no carry occurs in previous subtraction, must decrement high bit to account for a borrow
dec DiffHi ;decrement highbit
DecHi2 Sub DiffHi,Input2Hi
mov Input1Lo,DiffLo
mov Input1Hi,DiffHi
inc quotient
jmp Divloop

donedivhi
divlooplo cjb Input1lo,Input2lo,Donediv

mov DiffLo,Input1Lo
clc
sub DiffLo,Input2Lo ;subtracts second low num from DiffLo
mov Input1Lo,DiffLo
inc quotient
jmp divlooplo

Donediv mov X,quotient
call Output
mov remainder,Input1Lo
mov X,remainder
call Output
mov remainder,DiffHi
mov X,remainder
call Output
jmp Mainloop

ZeroDiv mov rb,#$00000000
call delay
mov rb,#$ff
call delay
mov rb,#$00000000
call delay
mov rb,#$ff
call delay
mov rb,#$00000000
call delay
mov rb,#$ff
call delay
mov rb,#$00000000
call delay
mov rb,#$ff
jmp Mainloop
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top