Created
April 27, 2012 15:42
-
-
Save dunst0/2510264 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET PC, main ; jump direkt to main function | |
;; Converts a hex number to a dec number. | |
;; | |
;; @param A hex number | |
;; @return A dec number | |
;; @pre A <= 0x270F | |
:hex2dec | |
SET PUSH, I ; Prolog | |
SET PUSH, X ; | | |
SET I, 0 | |
:loop_convert | |
SET X, A | |
MOD X, 0xA | |
SET PUSH, X | |
DIV A, 0xA | |
ADD I, 1 | |
IFN A, 0 | |
SET PC, loop_convert | |
SET A, 0 | |
:loop_get | |
SHL A, 4 | |
SET X, POP | |
BOR A, X | |
SUB I, 1 | |
IFG I, 0 | |
SET PC, loop_get | |
SET X, POP ; Epilog | |
SET I, POP ; | | |
SET PC, POP ; RETURN | |
;; Prints a number to screen. | |
;; | |
;; @param A Number to print | |
:printNumber | |
SET PUSH, X ; Prolog | |
SET PUSH, I ; | | |
SET PUSH, J ; | | |
SET I, 0 | |
SET J, 0 | |
:print_loop | |
SHL A, 4 ; shift 4 bits inti EX | |
IFE EX, 0 | |
SET PC, skip_print | |
SET X, EX | |
ADD X, 0x30 ; convert dec to ascii | |
BOR X, 0xF000 ; white color | |
SET [0x8000+I], X ; print to screen | |
ADD I, 1 | |
:skip_print | |
ADD J, 1 | |
IFN J, 4 | |
SET PC, print_loop | |
SET J, POP ; Epilog | |
SET I, POP ; | | |
SET X, POP ; | | |
SET PC, POP ; RETURN | |
;; The Main function of this code | |
:main | |
SET A, 0 | |
SET B, 0x8000 | |
HWI 0x1 | |
SET A, 0xFF | |
JSR hex2dec | |
JSR printNumber | |
:end SET PC, end ; end of programm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment