This is my code:
init:
; expected to go in "zero" part
mvi a, 0ah
mvi e, 05h
; content of reg b is "251"
; expected to go in "zero" part
;mvi a, 0ah
;mvi e, 0ah
; if followed two are commented out content of reg b is "254"
; expected to go in "minus" part
;mvi a, 0ah
;mvi e, 03h
; if followed two are commented out content of reg b is "254"
; expected to go in "minus" part
;mvi a,0ah
;mvi e,0bh
; if followed two are commented out content of reg b is "255"
subtractionLoop:
sub e
jp subtractionLoop
jz zero
jm minus
minus:
mvi b, 0ffh
; print value as 255 to see it comes within "minus" part
; the part means last result is minus, so we can get remainder by adding
; content of reg E only one time
hlt
zero:
mvi b, 0bh
; print value as 11 to see it comes within "zero" part
hlt
I simply try to achieve simple division, but I get different and interesting results as you read on comments(;
).
My idea is as following:
So long as the dividend is positive, subtractionLoop
goes on subtraction. If it hits to 0
, go to the zero part. Otherwise, go to the minus part.
Where is/are my mistake/s?
The jumps don't seem right.