;demonstrate the A to H subroutine

; in THRSim11:

      org ff00

      lds #00ff

      cli

      ldaa #63

      psha

      jsr AtoH

      pula

Stop: bra Stop

AtoH:

            ; Convert 8-bit ASCII to 4-bit Hex

            ; input registers: none - 8-bit

            ;                  local variable

            ;              passed to stack

            ; output registers: none - 8-bit

            ;                   local variable

            ;                   passed to stack

            ;                   4-bits of leading

            ;                   zeros, 4-bits data

            ;

       pshx ; store old values of X and A

       psha

       tsx      ; transfer SP contents to X

       ldaa 5,x ; load ASCII char from stack

       suba #30 ; stubtract 30 from ASCII

       cmpa #a  ; check if number was less than A (10)

       blt Done ; if so, done, restore registers

       suba #27 ; if not, convert to "a" thru "f" value

Done:  staa 5,x ; put HEX number on stack

       pula     ; restore contents of A and X

       pulx

       rts