I'm doing some Homework getting ready for Final and i'm trying to figure out what i know on paper to work for Restorative Division with Left Shifting.
I've been playing with this for a couple nights straight and can't seem to figure out what i'm doing wrong.. other then the possibility that when i do it on paper i'm working with 4 bits for Accumulator and Quotient and all the registers here are 8 bit.
Here is what I have so far, any insight on what i'm missing would be appreciated.
The teacher wants us to use Left Shift, and not other optimized versions with right shift, or subtracting in a loop. Thanks.
; Dividend 7, Divisor 3
;---------------------------------------------------------------------
lxi d, 0007 ; This load D E 00 07, D = (A) E = (Q)
mvi b, 03 ; Divisor for A=A-M & A=A+M
mvi c, 08 ; Loop (C)ounter, 8 Bits
;
;-------------------------
; Shift Left A, then Q in DE
NEXT:mov a, e ; Copy A -> ACC
ral ; Shift LEFT
mov e, a ; Copy Back
mov a, d ; Copy Q -> ACC
ral ; Shift LEFT
mov d, a ; Copy Back
;
;-------------------------
; A=A-M
mov a, d ; Copy (A) -> ACC
sub b ; A=A-M
mov d, a ; Copy Back
ral ; Shift Left to get MSB
jc RESTORE ; Most Sig Bit == 1 (Negative), Restore.
;
;-------------------------
; ELSE NOT RESTORE Add 1 to Q Zero LSB
mov a, e
adi 01
dcr c
jnz NEXT
jmp END
;
;--------------------------
RESTORE:mov a, d
add b ; A=A+M
mov d, a
dcr c
jnz NEXT
:END hlt
I believe I found the issue in the following section
;-------------------------
; ELSE NOT RESTORE Add 1 to Q Zero LSB
mov a, e
adi 01
mov e, a <---- Forgot to save it back to e.
dcr c
jnz NEXT
jmp END