Jump to content

Programming:Display a 8-bit number in binary: Difference between revisions

From CPCWiki - THE Amstrad CPC encyclopedia!
CPCLER (talk | contribs)
No edit summary
 
CPCLER (talk | contribs)
No edit summary
Line 1: Line 1:
From the '''The Unofficial Amstrad WWW Resource''':
This routine uses [[Firmware]]
<pre>
<pre>
;; A useful procedure to display a 8-bit number in binary
;; A useful procedure to display a 8-bit number in binary

Revision as of 15:43, 12 March 2007

From the The Unofficial Amstrad WWW Resource:

This routine uses Firmware

;; A useful procedure to display a 8-bit number in binary
;;

.txt_output equ &bb5a

;;------------------------------
;; DISPLAY A BYTE IN BINARY FORM 
;;
;; Enter:
;; A = 8-bit value
;;
;; Exit:
;; AF corrupt.
;; B corrupt. 
;; All other registers preserved

.display_binary
ld b,8                    ;number of bits to display

.get_bit
rlca                      ;rotate current top bit into carry

                          ;if the bit was 1, the carry is set. (i.e. carry=1)
                          ;if the bit was 0, the carry is reset. (i.e carry=0)

push af
ld a,"0"                  ;ASCII character for bit value
adc a,0                   ;add carry, if carry is set A="1", otherwise A="0"
call txt_output           ;display character onscreen
pop af

djnz get_bit              ;loop, until all bits have been displayed
ret