mirror of
https://github.com/DoctorWkt/pdp7-unix.git
synced 2026-04-26 04:07:14 +00:00
I wrote a simple routine to print out numbers in decimal.
This commit is contained in:
36
src/other/decimal_out.s
Normal file
36
src/other/decimal_out.s
Normal file
@@ -0,0 +1,36 @@
|
||||
" Subroutine to print out the number in AC as a decimal value.
|
||||
|
||||
lac num
|
||||
jms decprnt
|
||||
sys exit
|
||||
|
||||
decprnt: 0
|
||||
cll
|
||||
idiv; 10 " Divide AC by 10
|
||||
sna
|
||||
jmp 1f " No remainder, stop
|
||||
tad o60 " Add ASCII '0'
|
||||
dac dbufptr i " and save the character into the buffer
|
||||
-1 " Move pointer back a word
|
||||
tad dbufptr
|
||||
dac dbufptr
|
||||
isz count " Bump up the count of characters
|
||||
lacq " and move the quotient into AC
|
||||
jmp decprnt+1 " Loop back for the next digit
|
||||
|
||||
1: isz dbufptr " Restore the pointer to the first digit
|
||||
lac d1 " Print as a string on stdout
|
||||
sys write; dbufptr:dbufend; count:0
|
||||
jmp decprnt i " and return from the routine
|
||||
|
||||
|
||||
" We set aside 5 words to buffer the characters, and we write
|
||||
" from the end backwards to the front
|
||||
dbuf: .=.+4 " First 4 words in the buffer
|
||||
dbufend: .=.+1 " and the last word
|
||||
|
||||
d1: 1
|
||||
d10: 10
|
||||
o60: 060
|
||||
|
||||
num: 1234 " Test number
|
||||
Reference in New Issue
Block a user