Skip to content

Instantly share code, notes, and snippets.

@Loevland
Created January 21, 2024 14:40
Show Gist options
  • Save Loevland/ef9a60c1d8c403616b7ed59fa2831a32 to your computer and use it in GitHub Desktop.
Save Loevland/ef9a60c1d8c403616b7ed59fa2831a32 to your computer and use it in GitHub Desktop.
% STD
!ICO ? NIP <- #HLT
loop:
; Read one word into RES
RES <- IDA
; Print the 4 hex digits of RES
NIP <- #rotate_and_print_digit
NIP <- #rotate_and_print_digit
NIP <- #rotate_and_print_digit
NIP <- #rotate_and_print_digit
counter <- INC <- counter
; Stop if there is no more input
!ICO ? NIP <- #stop
DBG <- counter
ALX <- counter
ALY <- #16
EQU ? NIP <- #reset
PRN <- #' '
NIP <- #loop
reset:
counter <- #0
PRN <- #10 ; Print newline
NIP <- #loop
stop:
PRN <- #10 ; Print newline at the end
NIP <- #HLT
rotate_and_print_digit:
; Rotate RES 4 times to the left
RES <- LRO <- LRO <- LRO <- LRO <- RES
; Add the lower 4 bits to the address of
; hex_chars and print the character
ALX <- RES
ALY <- #$000F
ALX <- AND
ALY <- #hex_chars
PRN <- *SUM
; Return to the caller
NIP <- PIP
hex_chars:
"0123456789ABCDEF"
counter: 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment