Advertisement
arealloudbird

asdf

Jan 24th, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. ; Lab 1
  2. ; assignment: develop a code to print a value stored in a register
  3. ; as a hexadecimal number to the monitor
  4. ; algorithm: turning each group of four bits into a digit
  5. ; calculate the corresponding ASCII character;
  6. ; print the character to the monitor
  7. ; Hint: Shift left is a multiply by 2
  8.  
  9. ; R0 OUT Trap Register
  10. ; R1 Branching purposes
  11. ; R2 Digit Counter
  12. ; R3 Data
  13. ; R4 Digit
  14. ; R5 Bit Counter
  15.  
  16. .ORIG x3000
  17.  
  18. LD R3, REGISTER_3
  19.  
  20. AND R2, R2, #0
  21. ADD R2, R2, #3
  22. TOP_OF_HEX_LOOP
  23. BRn FINISHED
  24. AND R4, R4, #0
  25. AND R5, R5, #0
  26. ADD R5, R5, #3
  27.  
  28. TOP_OF_BIT_LOOP
  29. BRnz TOP_OF_PRINT
  30. ADD R4, R4, R4
  31. ; Is R3 < 0?
  32. AND R1, R1, #0
  33. NOT R1, R3
  34. BRzp SKIP_ADD
  35. ADD R4, R4, #1
  36.  
  37. SKIP_ADD
  38. ADD R3, R3, R3
  39. ADD R5, R5, #-1
  40. BRnzp TOP_OF_BIT_LOOP
  41.  
  42. TOP_OF_PRINT
  43. AND R1, R1, #0
  44. ADD R1, R4, #-9
  45. BRnz ADD_ZERO
  46. BRp ADD_A_MINUS_10
  47.  
  48. ADD_ZERO
  49. ADD R4, R4, #15
  50. ADD R4, R4, #15
  51. ADD R4, R4, #15
  52. ADD R4, R4, #3
  53. BRnzp PRINT
  54.  
  55. ADD_A_MINUS_10
  56. ADD R4, R4, #31
  57. ADD R4, R4, #15
  58. ADD R4, R4, #9
  59. BRnzp PRINT
  60.  
  61. PRINT
  62. AND R0, R0, #0
  63. ADD R0, R4, #0
  64. OUT
  65. ADD R2, R2, #-1
  66. BRnzp TOP_OF_HEX_LOOP
  67.  
  68. FINISHED
  69. ; stop the computer
  70. HALT
  71.  
  72. ; program data section starts here
  73.  
  74. REGISTER_3 .FILL x00E0
  75.  
  76. .END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement