33 lines
910 B
Plaintext
33 lines
910 B
Plaintext
bdos: equ 5h ; CP/M system call
|
|
puts: equ 9h ; Print string
|
|
org 100h
|
|
lxi h,5 ; Print value for 5
|
|
call prbin
|
|
lxi h,50 ; Print value for 50
|
|
call prbin
|
|
lxi h,9000 ; Print value for 9000
|
|
prbin: call bindgt ; Make binary representation of HL
|
|
mvi c,puts ; Print it
|
|
jmp bdos
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;;; Return the binary representation of the 16-bit number in HL
|
|
;;; as a string starting at [DE].
|
|
bindgt: lxi d,binend ; End of binary string
|
|
ana a ; Clear carry flag
|
|
binlp: dcx d ; Previous digit
|
|
mov a,h ; Shift HL left, LSB into carry flag
|
|
rar
|
|
mov h,a
|
|
mov a,l
|
|
rar
|
|
mov l,a
|
|
mvi a,'0' ; Digit '0' or '1' depending on
|
|
aci 0 ; status of carry flag.
|
|
stax d
|
|
mov a,h ; Is HL 0 now?
|
|
ora l
|
|
rz ; Then stop
|
|
jmp binlp ; Otherwise, do next bit
|
|
binstr: db '0000000000000000' ; Placeholder for string
|
|
binend: db 13,10,'$' ; end with \r\n
|