Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Lab 1
- ; assignment: develop a code to print a value stored in a register
- ; as a hexadecimal number to the monitor
- ; algorithm: turning each group of four bits into a digit
- ; calculate the corresponding ASCII character;
- ; print the character to the monitor
- ; Hint: Shift left is a multiply by 2
- ; R0 OUT Trap Register
- ; R1 Branching purposes
- ; R2 Digit Counter
- ; R3 Data
- ; R4 Digit
- ; R5 Bit Counter
- .ORIG x3000
- LD R3, REGISTER_3
- AND R2, R2, #0
- ADD R2, R2, #3
- TOP_OF_HEX_LOOP
- BRn FINISHED
- AND R4, R4, #0
- AND R5, R5, #0
- ADD R5, R5, #3
- TOP_OF_BIT_LOOP
- BRnz TOP_OF_PRINT
- ADD R4, R4, R4
- ; Is R3 < 0?
- AND R1, R1, #0
- NOT R1, R3
- BRzp SKIP_ADD
- ADD R4, R4, #1
- SKIP_ADD
- ADD R3, R3, R3
- ADD R5, R5, #-1
- BRnzp TOP_OF_BIT_LOOP
- TOP_OF_PRINT
- AND R1, R1, #0
- ADD R1, R4, #-9
- BRnz ADD_ZERO
- BRp ADD_A_MINUS_10
- ADD_ZERO
- ADD R4, R4, #15
- ADD R4, R4, #15
- ADD R4, R4, #15
- ADD R4, R4, #3
- BRnzp PRINT
- ADD_A_MINUS_10
- ADD R4, R4, #31
- ADD R4, R4, #15
- ADD R4, R4, #9
- BRnzp PRINT
- PRINT
- AND R0, R0, #0
- ADD R0, R4, #0
- OUT
- ADD R2, R2, #-1
- BRnzp TOP_OF_HEX_LOOP
- FINISHED
- ; stop the computer
- HALT
- ; program data section starts here
- REGISTER_3 .FILL x00E0
- .END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement