PrintBYTE

Purpose: Print a string, in decimal format with the numeric value of a BYTE.
Assumes:   Leading zeros should be suppressed.
Passed: R24   BYTE   bValue   the BYTE value to print; output: "0" to "255"
Returns: R24 BYTE bValue   the same BYTE value that was passed, unchanged
Alters: Only the FLAGs (SREG) and the COM1 Transmit buffer
 

PrintHexBYTE

Purpose: Print a string, in hexadecimal format with the numeric value of a BYTE.
Assumes:   Do not suppress a leading zero; print two (2) characters
Passed: R24   BYTE   bValue   the BYTE value to print; output: "00" to "FF"
Returns: Nothing.
Alters: R24, the FLAGs (SREG) and the COM1 Transmit buffer
 

Print0xHexBYTE

Purpose: Print the 2-BYTE string "0x" then the 2-BYTE string created by PrintHexBYTE.
Notes: Everything else is as documented in PrintHexBYTE above, since this routine uses it.

Example:  
.ORG  0x1000
PrintBYTEDemo:
   ADIW    R26, 0                 ; If there is no command tail, don't try to
   BREQ    ASaveBYTEToR18         ;  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
;  SBRS    R21, BIT_PV_VALID      ; Usually check validity; no need this time
   MOV     R24, R22               ; Use parsed value's LSByte (or 0) to R24

SaveBYTEToR18:
   MOV     R18, R24               ; Save the parsed LSByte or zero in R18
   CALL    APrintBYTE             ; Print R24 in decimal format
   RCALL   APrintEqualString      ; Print the first " = "
   CALL    APrintHexBYTE          ; Print R24 in hexadecimal format
   RCALL   APrintEqualString      ; Print the second " = "
   CALL    APrint0xHexBYTE        ; Print R24 in standard hex notation
   JMP     APrintNewLine          ; Exit with a Carriage Return & Line Feed

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

PrintEqualString:
   LDI     R25, CSZ_SpaceEqualSpace >> 8     ; Point to the string already
   LDI     R24, CSZ_SpaceEqualSpace & 0xFF   ;  in the FLASH memory
   LDI     R22, 3                 ; Since the string length is known, use it
   CALL    APrintFLASHString
   MOV     R24, R18               ; Restore the parsed BYTE before returning
   RET
Test it:
m>@ 0x1000    ; With only this string, R24 = 0
0 = 00 = 0x00
m>@ 0x1000   0
0 = 00 = 0x00
m>@ 0x1000 42
42 = 2A = 0x2A
m>@ 4096   100
100 = 64 = 0x64
m>@ 4096   -1
255 = FF = 0xFF
m>@ 4096 16
16 = 10 = 0x10
m>@ 4096 -16
240 = F0 = 0xF0
m>@ 4096  14
14 = 0E = 0x0E
m>                                                                                        
Notes: The Operating System handles the COM1 Transmit buffer as a circular FIFO (First In, First Out) queue.
Dropin: 
(setup
code)
;   Setup for the PrintBYTE() call:
; Passed:  R24 BYTE bValue to print in decimal format
; Returns: R24 BYTE bValue returned as passed
; Alters:  the FLAGs and the COM1 Transmit Buffer
; Notes:   Any leading zeros are suppressed

;   Setup for the PrintHexBYTE() or Print0xHexBYTE() calls:
; Passed:  R24 BYTE bValue to print in hexadecimal format
; Returns: Nothing.
; Alters:  R24, the FLAGs and the COM1 Transmit Buffer
; Notes:   If there is a leading zero, print it
Also see: The System Functions PrintBINARY, PrintCHAR, Print0xPrefix, and the PrintWORD family.