;ASCII code printer ;Print a prompt load r0, #3e store ffff, r0 load r0, #20 store ffff, r0 ;Read a character to r0 and load it to r2 load r0, ffff xor r2, r2 xor r2, r0 ;Print a newline cleq r0, r0, newln ;Convert and print the high nibble ;Convert ror r0, 4 cleq r0, r0, n2hex ;Print store ffff, r0 ;Re-load the character to r0 xor r0, r0 xor r0, r2 ;Convert and print the low nibble ;Convert cleq r0, r0, n2hex ;Print store ffff, r0 ;Print a newline cleq r0, r0, newln ;Halt halt ;*** ;Print a newline newln: load r1, #d store ffff, r1 load r1, #a store ffff, r1 ret ;*** ;Get the hexadecimal digit of a nibble ;Extract the low nibble n2hex: load r1, #f and r0, r1 ;Locate the nibble in the table load r1, #0 breq r0, r1, dgt0 load r1, #1 breq r0, r1, dgt1 load r1, #2 breq r0, r1, dgt2 load r1, #3 breq r0, r1, dgt3 load r1, #4 breq r0, r1, dgt4 load r1, #5 breq r0, r1, dgt5 load r1, #6 breq r0, r1, dgt6 load r1, #7 breq r0, r1, dgt7 load r1, #8 breq r0, r1, dgt8 load r1, #9 breq r0, r1, dgt9 load r1, #a breq r0, r1, dgta load r1, #b breq r0, r1, dgtb load r1, #c breq r0, r1, dgtc load r1, #d breq r0, r1, dgtd load r1, #e breq r0, r1, dgte load r1, #f breq r0, r1, dgtf ;Load the hexadecimal digit of the nibble dgt0: load r0, #30 breq r0, r0, n2hend dgt1: load r0, #31 breq r0, r0, n2hend dgt2: load r0, #32 breq r0, r0, n2hend dgt3: load r0, #33 breq r0, r0, n2hend dgt4: load r0, #34 breq r0, r0, n2hend dgt5: load r0, #35 breq r0, r0, n2hend dgt6: load r0, #36 breq r0, r0, n2hend dgt7: load r0, #37 breq r0, r0, n2hend dgt8: load r0, #38 breq r0, r0, n2hend dgt9: load r0, #39 breq r0, r0, n2hend dgta: load r0, #41 breq r0, r0, n2hend dgtb: load r0, #42 breq r0, r0, n2hend dgtc: load r0, #43 breq r0, r0, n2hend dgtd: load r0, #44 breq r0, r0, n2hend dgte: load r0, #45 breq r0, r0, n2hend dgtf: load r0, #46 breq r0, r0, n2hend ;Return n2hend: ret