mov w, #$C3 ;try 50,000 / 256 against Hi
call nextHi
mov w, #$50
snc ;if that wasn't too big
call nextLo ;try 50,000 mod 256 against Lo
mov w, #5
snc ;and if both of those were not too big
add digit, w ;we know the first digit is at least 5
mov w, #$75 ;try 30,000 / 256 against Hi
call nextHi
mov w, #$30
snc ;if that wasn't too big
call nextLo ;try 30,000 mod 256 against Lo
mov w, #3
snc ;and if both of those were not too big
add digit, w ;we know the first digit is at least 3 more
mov w, #$27 ;try 10,000 / 256 against Hi
call nextHi
mov w, #$10
snc ;if that wasn't too big
call nextLo ;try 10,000 mod 256 against Lo
mov w, #1
snc ;and if both of those were not too big
add digit, w ;we know the first digit is at least 1 more
call SerOut ;get rid of the digit.
clr digit
mov w, #$13 ;try 5,000 / 256 against Hi
call nextHi
mov w, #$88
snc ;if that wasn't too big
call nextLo ;try 5,000 mod 256 against Lo
mov w, #5
snc ;and if both of those were not too big
add digit, w ;we know the first digit is at least 5
mov w, #$0B ;try 3,000 / 256 against Hi
call nextHi
mov w, #$B8
snc ;if that wasn't too big
call nextLo ;try 3,000 mod 256 against Lo
mov w, #3
snc ;and if both of those were not too big
add digit, w ;we know the first digit is at least 3 more
mov w, #$03 ;try 1,000 / 256 against Hi
call nextHi
mov w, #$E8
snc ;if that wasn't too big
call nextLo ;try 1,000 mod 256 against Lo
mov w, #1
snc ;and if both of those were not too big
add digit, w ;we know the first digit is at least 1 more
call SerOut ;get rid of the digit.
clr digit
mov w, #$01 ;try 500 / 256 against Hi
call nextHi
mov w, #$F4
snc ;if that wasn't too big
call nextLo ;try 500 mod 256 against Lo
mov w, #5
snc ;and if both of those were not too big
add digit, w ;we know the first digit is at least 5
mov w, #$C8
call nextLo ;try 200 mod 256 against Lo
mov w, #2
snc ;and if both of those were not too big
add digit, w ;we know the first digit is at least 5
Loop:
smaller:
;mov w, #$C3
ret
nextHi:
mov w, Hi-w
sc
jmp smaller
;if the high byte is less than our value, the whole thing must be smaller.
;Carry not set so parent will skip nextLo and continue with nextHi
snz
mov Hi, w ;if its not zero and its not smaller, save the subtraction
;mov w, #$50 ;but in either case, get the next value
ret ;since carry is set parent will do nextLo
nextLo:
sz
jmp larger
;if the high byte was exactly equal to our value, then is the low byte smaller?
mov w, Lo-w
sc
jmp smaller
;the low byte was smaller so the whole thing was smaller after all.
;Carry not set so parent will not add this digit value to output and continue with nextHi.
clr Hi
;the low byte was larger so we are subtracting and the high byte was the same so we zero it.
mov Lo, w ;and save the subtraction from Lo
jmp Loop
;The low byte was larger but it's now smaller and since carry is set, parent will add
;this digit value to output and continue with nextHi
larger:
sub Lo, w
snc
dec Hi
stc
;The high byte was larger but now both are smaller and since carry is set, parent will add
;this digit value to output and continue with nextHi
jmp Loop
;smaller:
; clc
; jmp Loop
file: /Techref/microchip/math/radix/b2a-16b5dalzso.htm, 3KB, , updated: 2000/2/23 15:15, local time: 2024/11/19 08:27,
|
| ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://linistepper.com/techref/microchip/math/radix/b2a-16b5dalzso.htm"> microchip math radix b2a-16b5dalzso</A> |
Did you find what you needed?
|