Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.13 KB | None | 0 0
  1. // Starter source code program for ECE 2504
  2. // Project 4
  3. //
  4. // The on-line assembler is experimental and minimal.
  5. // No guarantees are made about its correctness.
  6. //
  7. // Add your header comments (name, date, etc.) here.
  8. //
  9. // Do not change the following segment of code from here
  10. // to the comment "CHANGE HERE" below.
  11. ldi r0, 3
  12. shl r0, r0
  13. shl r0, r0
  14. inc r0, r0
  15. shl r0, r0
  16. jmp r0
  17. // The following set of load instructions read the final values of the variables in
  18. // memory locations into r1-r7 so that we can see them on the LEDs.
  19. // Your code must jump to this point after it has stored the results in data memory.
  20. // You should jump to location 6.
  21. // address 0x06
  22. xor r0, r0, r0
  23. ld r1, r0 //r1<-M[0x00]
  24. ldi r0, 2
  25. ld r2, r0 //r2<-M[0x02]
  26. inc r0, r0
  27. ld r3, r0 //r3<-M[0x03]
  28. inc r0, r0
  29. ld r4, r0 //r4<-M[0x04]
  30. inc r0, r0
  31. ld r5, r0 //r5<-M[0x05]
  32. adi r0, r0, 7
  33. shl r0, r0
  34. adi r0, r0, 7
  35. inc r0, r0
  36. inc r0, r0
  37. ld r6, r0 //r6<-M[0x21]
  38. inc r0, r0
  39. ld r7, r0 //r7<-M[0x22]
  40. // Now loop forever
  41. ldi r0, 0
  42. // The address of this brz is the one used in validation: Address 0x19.
  43. brz r0, 0
  44.  
  45.  
  46. // You are permitted to add code after this point
  47. // CHANGE HERE and beyond
  48.  
  49.  
  50.  
  51.  
  52.  
  53. // Last 4 Digits of Student ID
  54.  
  55. ldi r0, 3 // 0011
  56. shl r0, r0 // 0011 0
  57. shl r0, r0 // 0011 00
  58. shl r0, r0 // 0011 000
  59. shl r0, r0 // 0011 0000
  60.  
  61. adi r0, r0, 3 // 0011 0011
  62. shl r0, r0 // 0011 0011 0
  63. shl r0, r0 // 0011 0011 00
  64. shl r0, r0 // 0011 0011 000
  65. shl r0, r0 // 0011 0011 0000
  66.  
  67. adi r0, r0, 7 // 0011 0011 0111
  68. adi r0, r0, 2 // 0011 0011 1001
  69.  
  70. shl r0, r0 // 0011 0011 1001 0
  71. shl r0, r0 // 0011 0011 1001 00
  72. shl r0, r0 // 0011 0011 1001 000
  73. shl r0, r0 // 0011 0011 1001 0000
  74.  
  75. adi r0, r0, 4 // 0011 0011 1001 0100
  76.  
  77. ldi r1, 0 // Creates register 1 and stores 0
  78. st r1, r0 // Stores the Last 4 Digits of Student ID in Register 1
  79.  
  80.  
  81.  
  82. // Stores hex value of 30 to find the ascii value
  83.  
  84. ldi r5, 3 // 0011
  85. shl r5, r5 // 0011 0
  86. shl r5, r5 // 0011 00
  87. shl r5, r5 // 0011 000
  88. shl r5, r5 // 0011 0000
  89.  
  90.  
  91.  
  92.  
  93. // To get the length of the zipcode plus check digit
  94.  
  95. ldi r2, 2 // Stores the value 2 into register 2
  96. shl r2, r2 // 0010 0
  97. shl r2, r2 // 0010 00
  98. shl r2, r2 // 0010 000
  99. shl r2, r2 // 0010 0000 (20 in hex)
  100.  
  101. ld r2, r2 // Loads the length into register 2 (7)
  102.  
  103.  
  104.  
  105.  
  106. // All the code above works
  107.  
  108. // Runs through a for loop to get the zipcodes
  109.  
  110. ldi r7, 0 // Used to loop the code back to the wanted spot
  111.  
  112.  
  113. ldi r3, 1 // Stores the value 1 into r3
  114. ld r3, r3 // Gets the memory location at r3 (0x21)
  115. ldi r6, 4 // Creates memory address 4
  116. shl r6, r6 // Creates memory address 8 from 4 by shifting left
  117.  
  118.  
  119.  
  120. dec r2, r2 // Decreases the length of the zipcode by 1
  121. ld r4, r3 // loads memory location at r4 (0x36)
  122. sub r4, r4, r5 // Subtracts the ascii contents by 30 to get the value
  123. st r6, r4 // Stores the digit from r4 into memory location of r6
  124.  
  125.  
  126. inc r3, r3 // Moves to the next memory location
  127. inc r6, r6 // Creates another memory address to store the digit
  128.  
  129.  
  130. brz r2, 2 // If the value of r2 is 0, exit the for loop, else move onto the next line
  131. brz r7, -7 // This will always remain true so it will loop the code back into the line 121 (ld r4, r3)
  132.  
  133.  
  134.  
  135.  
  136. // Creates POSTNET code and stores it into memory locations
  137.  
  138.  
  139. // This is for POSTNET code 0
  140.  
  141. ldi r1, 5 // starts memory location 20 (101)
  142. shl r1, r1 // Shifts one unit to the right (1010)
  143. shl r1, r1 // Shifts one unit to the right. Stored in Memory location 20 (10100)
  144.  
  145. ldi r3, 6 // Starts the POSTNET code (110)
  146. shl r3, r3 // Shifts one unit to the left (1100)
  147. shl r3, r3 // Shifts one unit to the left (11000)
  148.  
  149. st r1, r3 // Stores POSTNET code 0 into memory location 20
  150.  
  151.  
  152.  
  153.  
  154. // This is for POSTNET code 1
  155.  
  156. ldi r1, 5 // Starts memory location 21 (101)
  157. shl r1, r1 // Shifts one unit to the left (1010)
  158. shl r1, r1 // Shifts one unit to the left (10100)
  159. adi r1, r1, 1 // Adds one to the memory location (10101). Stored in Memory location 21 (10101)
  160.  
  161. ldi r3, 0 // Starts the POSTNET code (000)
  162. shl r3, r3 // Shifts one unit to the left (0000)
  163. shl r3, r3 // Shifts one unit to the left (00000)
  164. adi r3, r3, 3 // Adds 3 to the POSTNET code (00011)
  165.  
  166. st r1, r3 // Stores POSTNET code 1 into memory location 21
  167.  
  168.  
  169.  
  170.  
  171. // This is for POSTNET code 2
  172.  
  173.  
  174. ldi r1, 5 // Starts memory location 22 (101)
  175. shl r1, r1 // Shifts one unit to the left (1010)
  176. shl r1, r1 // Shifts one unit to the left (10100)
  177. adi r1, r1, 2 // Adds 2 to the memory location (10110). Stored in Memory location 22 (10110)
  178.  
  179. ldi r3, 1 // Starts the POSTNET code (001)
  180. shl r3, r3 // Shifts one unit to the left (0010)
  181. shl r2, r3 // Shifts one unit to the left (00100)
  182. adi r3, r3, 1 // Adds 1 to the POSTNET code (00101)
  183.  
  184. st r1, r3 // Stores POSTNET code 2 into memory location 22
  185.  
  186.  
  187.  
  188.  
  189. // This is for POSTNET code 3
  190.  
  191.  
  192. ldi r1, 5 // Starts memory location 23 (101)
  193. shl r1, r1 // Shifts one unit to the left (1010)
  194. shl r1, r1 // Shifts one unit to the left (10100)
  195. adi r1, r1, 3 // Adds 3 to the memory location (10110). Stored in Memory location 23 (10111)
  196.  
  197. ldi r1, 1 // Starts the POStNET code (001)
  198. shl r1, r1 // Shifts one unit to the left (0010)
  199. shl r1, r1 // Shifts one unit to the left (00100)
  200. adi r1, r1, 2 // Adds 2 to the POSTNET code (00110)
  201.  
  202. st r1, r3 // Stores POSTNET code into memory location 23
  203.  
  204.  
  205.  
  206.  
  207. // This is for POSTNET code 4
  208.  
  209.  
  210. ldi r1, 5 // Starts memory location 24 (101)
  211. shl r1, r1 // Shifts one unit to the left (1010)
  212. shl r1, r1 // Shifts one unit to the left (10100)
  213. adi r1, r1, 4 // Adds 4 to the memory location (11000). Stored in Memory location 24 (11000)
  214.  
  215. ldi r1, 2 // Starts the POSTNET code (010)
  216. shl r1, r1 // Shifts one unit to the left (0100)
  217. shl r1, r1 // Shifts one unit to the left (01000)
  218. adi r1, r1, 1 // Adds 1 to the POSTNET code (01001)
  219.  
  220. st r1, r3 // Stores POSTNET code into memory location 24
  221.  
  222.  
  223.  
  224.  
  225. // THis is for POSTNET code 5
  226.  
  227.  
  228. ldi r1, 5 // Starts memory location 25 (101)
  229. shl r1, r1 // Shifts one unit to the left (1010)
  230. shl r1, r1 // Shifts one unit to the left (10100)
  231. adi r1, r1, 5 // Adds 5 to the memory location (11001). Stored in Memory location 25 (11001)
  232.  
  233. ldi r1, 2 // Starts the POSTNET code (010)
  234. shl r1, r1 // Shifts one unit to the left (0100)
  235. shl r1, r1 // Shifts one unit to the left (01000)
  236. adi r1, r1, 2 // Adds 2 to the POSTNET code (01010)
  237.  
  238. st r1, r3 // Stores POSTNET code into memory location 25
  239.  
  240.  
  241.  
  242.  
  243. // This is for POSTNET code 6
  244.  
  245. ldi r1, 5 // Starts memory location 26 (101)
  246. shl r1, r1 // Shifts one unit to the left (1010)
  247. shl r1, r1 // Shifts one unit to the left (10100)
  248. adi r1, r1, 6 // Adds 6 to the memory location (11010). Stored in Memory location 26 (11010)
  249.  
  250. ldi r1, 2 // Starts the POSTNET code (010)
  251. shl r1, r1 // Shifts one unit to the left (0100)
  252. shl r1, r1 // Shifts one unit to the left (01000)
  253. adi r1, r1, 4 // Adds 4 to the POSTNET code (01100)
  254.  
  255. st r1, r3 // Stores POSTNET code into memory location 26
  256.  
  257.  
  258.  
  259.  
  260. // This is for POSTNET code 7
  261.  
  262. ldi r1, 5 // Starts memory location 27 (101)
  263. shl r1, r1 // Shifts one unit to the right (1010)
  264. shl r1, r1 // Shifts one unit to the right (10100)
  265. adi r1, r1, 7 // Adds 7 to the memory location (11011). Stored in Memory location 27 (11011)
  266.  
  267. ldi r1, 4 // Starts the POSTNET code (100)
  268. shl r1, r1 // Shifts one unit to the left (1000)
  269. shl r1, r1 // Shifts one unit to the left (10000)
  270. adi r1, r1, 1 // Adds 1 to the POSTNET code (10001)
  271.  
  272. st r1, r3 // Stores POSTNET code into memory location 27
  273.  
  274.  
  275.  
  276.  
  277. // This is for POSTNET code 8
  278.  
  279. ldi r1, 5 // Starts memory location 28 (101)
  280. shl r1, r1 // Shifts one unit to the right (1010)
  281. shl r1, r1 // Shifts one unit to the right (10100)
  282. adi r1, r1, 4 // Adds 4 to the memory location (11100). Stored in Memory location 28 (11000)
  283. adi r1, r1, 4 // Adds 4 to the memory location (10100). Stored in Memory location 28 (11000)
  284.  
  285. ldi r1, 4 // Starts the POSTNET code (100)
  286. shl r1, r1 // Shifts one unit to the left (1000)
  287. shl r1, r1 // Shifts one unit to the left (10000)
  288. adi r1, r1, 2 // Adds 2 to the POSTNET code (10010)
  289.  
  290. st r1, r3 // Stores POSTNET code into memory location 28
  291.  
  292.  
  293.  
  294.  
  295. // This is for POSTNET code 9
  296.  
  297. ldi r1, 5 // Starts memory location 29 (101)
  298. shl r1, r1 // Shifts one unit to the right (1010)
  299. shl r1, r1 // Shifts one unit to the right (10100)
  300. adi r1, r1, 5 // Adds 5 to the memory location (11101). Stored in Memory location 29 (11101)
  301. adi r1, r1, 4 // Adds 4 to the memory location (11101). Stored in Memory location 29 (11101)
  302.  
  303. ldi r1, 4 // Starts the POSTNET code (100)
  304. shl r1, r1 // Shifts one unit to the left (1000)
  305. shl r1, r1 // Shifts one unit to the left (10000)
  306. adi r1, r1, 4 // Adds 4 to the POSTNET code (10100)
  307.  
  308. st r1, r3 // Stores POSTNET code into memory location 29
  309.  
  310.  
  311.  
  312.  
  313. // Store memory addresses in memory addresses 02-05
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320. // Your last instruction should be a jump to location 6
  321. // in order to read the variables into registers r1-r7.
  322. // address 0x1A
  323. ldi r0, 6
  324. jmp r0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement