PrintBINARY

Purpose: Print a string, in binary format (e.g., B10101011) with the contents of a BYTE.
Assumes:   All eight (8) bits are printed; none suppressed.
Passed: R24   BYTE   bValue   the BYTE value to print; output: "B00000000" to "B11111111"
Returns: R24 BYTE bValue   the same bValue that was passed in R24, unchanged
Alters: Only the FLAGs (SREG) and the COM1 Transmit buffer

Example:  
.ORG  0x1000

CSZ_SpEqSp = 0x3AD2               ; FLASH address of the string " = ", NULL

ShowAsBinary:
   LDI     R21, 0                 ; Set BIT_PV_HEX off, in case of no parsing
   ADIW    R26, 0                 ; If there is no command tail, don't try to
   BREQ    ASaveDataBYTE          ;  parse anything starting at SRAM address 0!
   MOVW    R24, R26               ; Move the command tail pointer to R25:R24 in
   CALL    AParseValue            ;  order to parse any value found there
   MOV     R24, R22               ; Use parsed value's LSByte (or 0) to R24

SaveDataBYTE:
   MOV     R26, R24               ; Save the data value to be displayed
   SBRS    R21, BIT_PV_HEX        ; If a value was input in decimal notation,
   CALL    APrint0xHexBYTE        ;  print it in standard hex notation
   SBRC    R21, BIT_PV_HEX        ; But if it was input in hexadecimal format,
   CALL    APrintBYTE             ;  print it in decimal notation instead
   LDI     R25, CSZ_SpEqSp >> 8   ; Point to the delimiter string, which is
   LDI     R24, CSZ_SpEqSp & 0xFF ;  already in the FLASH memory
   CALL    APrintFLASHASCIIz      ; Print the NULL terminated string
   MOV     R24, R26               ; Restore the data value to be printed
   CALL    APrintBINARY
   JMP     APrintNewLine          ; Print Carriage Return, Line Feed & exit
Test it:
m>@ 0x1000          ; With no parameter passed
0x00 = B00000000
m>@ 4096    1       ; With a parameter on the command line
0x01 = B00000001
m>@ 4096  10        ; Passed as decimal, print first as hexadecimal
0x0A = B00001010
m>@ 4096  0xAB      ; Passed as hexadecimal, print first as decimal
171 = B10101011
m>@ 4096 100
0x64 = B01100100
m>@ 4096 0xDF
223 = B11011111
m>@ 4096 -1
0xFF = B11111111
m>@ 4096  0xF8
248 = B11111000
m>                                                                                        
Notes: As is the case with other Print commands, this command can block.
Dropin: 
(setup
code)
;   Setup for the PrintBINARY() call:
; Passed:  R24 BYTE bValue to print in binary format
; Returns: R24 BYTE bValue, unchanged
; Alters:  the FLAGs and the COM1 Transmit Buffer
Also see: The System Functions PrintCHAR, Print0xPrefix, the PrintBYTE family, and the PrintWORD family.