PrintDescAndHexBYTE

Purpose: Print a string, then a BYTE value in hexadecimal format.
Assumes:   Do not suppress a leading zero; print two (2) characters
Passed: R25:R24   CHAR *   szPtrDesc   address of the FLASH string buffer to output
R22 BYTE bValue the BYTE value to print in hexadecimal format
R19 BYTE bSpacer 0x20 (= ' ', space) prints " " in between, otherwise print " = "
Returns: Nothing.
Alters: R20, R22, R24, R25, the FLAGs (SREG) and the COM1 Transmit buffer
 

PrintDescAndHexWORD

Purpose: Print a string, then a WORD value in hexadecimal format.
Assumes:   Do not suppress any leading zeros; print four (4) characters
Passed: R25:R24 CHAR * szPtrDesc address of the FLASH string buffer to output
R23:R22 BYTE bValue the BYTE value to print in hexadecimal format
R19 BYTE bSpacer 0x20 (= ' ', space) prints " " in between, otherwise print " = "
Returns: Nothing.
Alters: R20, R22, R24, R25, the FLAGs (SREG) and the COM1 Transmit buffer

Example:  
.ORG   0x1000

PrintStringAndValue:
   ADIW    R26, 0                     ; If there was no command tail, no value
   BREQ    AEarly_Exit                ;  was passed, so there is nothing to do
   MOVW    R24, R26                   ; Try to parse a number from the string
   CALL    AParseValue                ;  passed; if unable to do that, there is
   SBRS    R21, BIT_PV_VALID          ;  again nothing to to, so just exit

Early_Exit:
   RET

   LDI     R25, ACSZ_ForHexBYTE >> 8  ; Assume identical print string MSBytes
   LD      R19, X                     ; If a space trailed the data value
   CPSE    R23, R1                    ; If the data value parsed has anything
   RJMP    AShowAsWORD                ;  in the second BYTE, take the jump

   LDI     R24, ACSZ_ForHexBYTE & 0xFF; Load the LSByte of the string address
   CALL    APrintDescAndHexBYTE       ; Call to print the BYTE string and a
   JMP     APrintNewLine              ;  BYTE value, then exit with a CR,LF

ShowAsWORD:
   LDI     R24, ACSZ_ForHexWORD & 0xFF; Load the LSByte of the string address
   CALL    APrintDescAndHexWORD       ; Print the second string and WORD; take
   RJMP    AShowAsWORD - 4            ;  the same exit (to an unnamed address!)

CSZ_ForHexBYTE:  .STRING  "BYTE value"
CSZ_ForHexWORD:  .STRING  "WORD value"
Test it:
m>@ 0x1000
m>@ 0x1000  Non-numeric first then a number, 0x4321 (prints nothing)
m>@ 0x1000  ; A comment, with correct syntax
@ 4096 123
BYTE value = 0x7B
m>@ 4096 123    ; Anything, really (the first BYTE after '3' is a space)
BYTE value 0x7B
m>
m>@ 4096 1234
WORD value = 0x04D2
m>@ 4096 1234   ; Again, notice the " = " was changed to " "
WORD value 0x04D2
m>@ 4096 M
WORD value = 0xDF97
m>@ 4096 M  ; With a comment
WORD value 0x048F
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 PrintDescAndHexBYTE() call:
; Passed:  R25:R24 CHAR * szPtrDesc pointer to the FLASH string to print first
;              R22 BYTE   bValue    BYTE to print after the delimiter
;              R19 BYTE   bSpacer   0x20 to override default " = " with " "
; Returns: Nothing.
; Alters:  R20, R22, R24, R25, the FLAGs and the COM1 Transmit Buffer
; Notes:   If there is a leading zero, print it

;   Setup for the PrintDescAndHexWORD() call:
; Passed:  R25:R24 CHAR * szPtrDesc pointer to the FLASH string to print first
;          R23:R22 WORD   wValue    WORD to print after the delimiter
;              R19 BYTE   bSpacer   0x20 to override default " = " with " "
; Returns: Nothing.
; Alters:  R20, R22, R24, R25, the FLAGs and the COM1 Transmit Buffer
; Notes:   If there are any leading zeros, print them
Also see: The System Functions Print0xPrefix, PrintBINARY, PrintCHAR, the PrintBYTE family, and the PrintWORD family.