0

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
Michael Petch
  • 46,082
  • 8
  • 107
  • 198
Mercyful
  • 107
  • 1
  • 7
  • Are you using an 8085 simulator for this ? Does it have a debugger ? – Paul R Nov 30 '17 at 09:07
  • I am, i'm using j8058, Not the best emulator but its what were using in class. The shifting seems to follow well. but i feel like something is getting lost with the carry bits and the preceding 4 extra since each register is 8 bits. – Mercyful Nov 30 '17 at 09:15
  • Do you mean [j8085sim](https://sourceforge.net/projects/j8085sim/) ? It looks like this has the ability to step through the code and examine registers etc ? This is an important debugging technique which should help you to see what's wrong with your code. – Paul R Nov 30 '17 at 09:18
  • Thats correct, it's a bit buggy though, the highlighting gets all messed up when stepping through. But again i've been working on it for 2 days re-writing over and over. Figured i should ask for some help if anyone notices any issues with how i'm doing it, or if there is a way to handle 4 bits at a time instead of 8. – Mercyful Nov 30 '17 at 09:30
  • All I can suggest is to make sure you know what to expect in each register as the code iterates (write it out on paper to be 100% certain), then step through the code and compare the actual register contents in the simulator with your expectations. When they differ then you have found your bug. – Paul R Nov 30 '17 at 09:39

1 Answers1

1

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
Michael Petch
  • 46,082
  • 8
  • 107
  • 198