Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Starter source code program for ECE 2504
- // Project 4
- //
- // The on-line assembler is experimental and minimal.
- // No guarantees are made about its correctness.
- //
- // Add your header comments (name, date, etc.) here.
- //
- // Do not change the following segment of code from here
- // to the comment "CHANGE HERE" below.
- ldi r0, 3
- shl r0, r0
- shl r0, r0
- inc r0, r0
- shl r0, r0
- jmp r0
- // The following set of load instructions read the final values of the variables in
- // memory locations into r1-r7 so that we can see them on the LEDs.
- // Your code must jump to this point after it has stored the results in data memory.
- // You should jump to location 6.
- // address 0x06
- xor r0, r0, r0
- ld r1, r0 //r1<-M[0x00]
- ldi r0, 2
- ld r2, r0 //r2<-M[0x02]
- inc r0, r0
- ld r3, r0 //r3<-M[0x03]
- inc r0, r0
- ld r4, r0 //r4<-M[0x04]
- inc r0, r0
- ld r5, r0 //r5<-M[0x05]
- adi r0, r0, 7
- shl r0, r0
- adi r0, r0, 7
- inc r0, r0
- inc r0, r0
- ld r6, r0 //r6<-M[0x21]
- inc r0, r0
- ld r7, r0 //r7<-M[0x22]
- // Now loop forever
- ldi r0, 0
- // The address of this brz is the one used in validation: Address 0x19.
- brz r0, 0
- // You are permitted to add code after this point
- // CHANGE HERE and beyond
- // Last 4 Digits of Student ID
- ldi r0, 3 // 0011
- shl r0, r0 // 0011 0
- shl r0, r0 // 0011 00
- shl r0, r0 // 0011 000
- shl r0, r0 // 0011 0000
- adi r0, r0, 3 // 0011 0011
- shl r0, r0 // 0011 0011 0
- shl r0, r0 // 0011 0011 00
- shl r0, r0 // 0011 0011 000
- shl r0, r0 // 0011 0011 0000
- adi r0, r0, 7 // 0011 0011 0111
- adi r0, r0, 2 // 0011 0011 1001
- shl r0, r0 // 0011 0011 1001 0
- shl r0, r0 // 0011 0011 1001 00
- shl r0, r0 // 0011 0011 1001 000
- shl r0, r0 // 0011 0011 1001 0000
- adi r0, r0, 4 // 0011 0011 1001 0100
- ldi r1, 0 // Creates register 1 and stores 0
- st r1, r0 // Stores the Last 4 Digits of Student ID in Register 1
- // Stores hex value of 30 to find the ascii value
- ldi r5, 3 // 0011
- shl r5, r5 // 0011 0
- shl r5, r5 // 0011 00
- shl r5, r5 // 0011 000
- shl r5, r5 // 0011 0000
- // To get the length of the zipcode plus check digit
- ldi r2, 2 // Stores the value 2 into register 2
- shl r2, r2 // 0010 0
- shl r2, r2 // 0010 00
- shl r2, r2 // 0010 000
- shl r2, r2 // 0010 0000 (20 in hex)
- ld r2, r2 // Loads the length into register 2 (7)
- // All the code above works
- // Runs through a for loop to get the zipcodes
- ldi r7, 0 // Used to loop the code back to the wanted spot
- ldi r3, 1 // Stores the value 1 into r3
- ld r3, r3 // Gets the memory location at r3 (0x21)
- ldi r6, 4 // Creates memory address 4
- shl r6, r6 // Creates memory address 8 from 4 by shifting left
- dec r2, r2 // Decreases the length of the zipcode by 1
- ld r4, r3 // loads memory location at r4 (0x36)
- sub r4, r4, r5 // Subtracts the ascii contents by 30 to get the value
- st r6, r4 // Stores the digit from r4 into memory location of r6
- inc r3, r3 // Moves to the next memory location
- inc r6, r6 // Creates another memory address to store the digit
- brz r2, 2 // If the value of r2 is 0, exit the for loop, else move onto the next line
- brz r7, -7 // This will always remain true so it will loop the code back into the line 121 (ld r4, r3)
- // Creates POSTNET code and stores it into memory locations
- // This is for POSTNET code 0
- ldi r1, 5 // starts memory location 20 (101)
- shl r1, r1 // Shifts one unit to the right (1010)
- shl r1, r1 // Shifts one unit to the right. Stored in Memory location 20 (10100)
- ldi r3, 6 // Starts the POSTNET code (110)
- shl r3, r3 // Shifts one unit to the left (1100)
- shl r3, r3 // Shifts one unit to the left (11000)
- st r1, r3 // Stores POSTNET code 0 into memory location 20
- // This is for POSTNET code 1
- ldi r1, 5 // Starts memory location 21 (101)
- shl r1, r1 // Shifts one unit to the left (1010)
- shl r1, r1 // Shifts one unit to the left (10100)
- adi r1, r1, 1 // Adds one to the memory location (10101). Stored in Memory location 21 (10101)
- ldi r3, 0 // Starts the POSTNET code (000)
- shl r3, r3 // Shifts one unit to the left (0000)
- shl r3, r3 // Shifts one unit to the left (00000)
- adi r3, r3, 3 // Adds 3 to the POSTNET code (00011)
- st r1, r3 // Stores POSTNET code 1 into memory location 21
- // This is for POSTNET code 2
- ldi r1, 5 // Starts memory location 22 (101)
- shl r1, r1 // Shifts one unit to the left (1010)
- shl r1, r1 // Shifts one unit to the left (10100)
- adi r1, r1, 2 // Adds 2 to the memory location (10110). Stored in Memory location 22 (10110)
- ldi r3, 1 // Starts the POSTNET code (001)
- shl r3, r3 // Shifts one unit to the left (0010)
- shl r2, r3 // Shifts one unit to the left (00100)
- adi r3, r3, 1 // Adds 1 to the POSTNET code (00101)
- st r1, r3 // Stores POSTNET code 2 into memory location 22
- // This is for POSTNET code 3
- ldi r1, 5 // Starts memory location 23 (101)
- shl r1, r1 // Shifts one unit to the left (1010)
- shl r1, r1 // Shifts one unit to the left (10100)
- adi r1, r1, 3 // Adds 3 to the memory location (10110). Stored in Memory location 23 (10111)
- ldi r1, 1 // Starts the POStNET code (001)
- shl r1, r1 // Shifts one unit to the left (0010)
- shl r1, r1 // Shifts one unit to the left (00100)
- adi r1, r1, 2 // Adds 2 to the POSTNET code (00110)
- st r1, r3 // Stores POSTNET code into memory location 23
- // This is for POSTNET code 4
- ldi r1, 5 // Starts memory location 24 (101)
- shl r1, r1 // Shifts one unit to the left (1010)
- shl r1, r1 // Shifts one unit to the left (10100)
- adi r1, r1, 4 // Adds 4 to the memory location (11000). Stored in Memory location 24 (11000)
- ldi r1, 2 // Starts the POSTNET code (010)
- shl r1, r1 // Shifts one unit to the left (0100)
- shl r1, r1 // Shifts one unit to the left (01000)
- adi r1, r1, 1 // Adds 1 to the POSTNET code (01001)
- st r1, r3 // Stores POSTNET code into memory location 24
- // THis is for POSTNET code 5
- ldi r1, 5 // Starts memory location 25 (101)
- shl r1, r1 // Shifts one unit to the left (1010)
- shl r1, r1 // Shifts one unit to the left (10100)
- adi r1, r1, 5 // Adds 5 to the memory location (11001). Stored in Memory location 25 (11001)
- ldi r1, 2 // Starts the POSTNET code (010)
- shl r1, r1 // Shifts one unit to the left (0100)
- shl r1, r1 // Shifts one unit to the left (01000)
- adi r1, r1, 2 // Adds 2 to the POSTNET code (01010)
- st r1, r3 // Stores POSTNET code into memory location 25
- // This is for POSTNET code 6
- ldi r1, 5 // Starts memory location 26 (101)
- shl r1, r1 // Shifts one unit to the left (1010)
- shl r1, r1 // Shifts one unit to the left (10100)
- adi r1, r1, 6 // Adds 6 to the memory location (11010). Stored in Memory location 26 (11010)
- ldi r1, 2 // Starts the POSTNET code (010)
- shl r1, r1 // Shifts one unit to the left (0100)
- shl r1, r1 // Shifts one unit to the left (01000)
- adi r1, r1, 4 // Adds 4 to the POSTNET code (01100)
- st r1, r3 // Stores POSTNET code into memory location 26
- // This is for POSTNET code 7
- ldi r1, 5 // Starts memory location 27 (101)
- shl r1, r1 // Shifts one unit to the right (1010)
- shl r1, r1 // Shifts one unit to the right (10100)
- adi r1, r1, 7 // Adds 7 to the memory location (11011). Stored in Memory location 27 (11011)
- ldi r1, 4 // Starts the POSTNET code (100)
- shl r1, r1 // Shifts one unit to the left (1000)
- shl r1, r1 // Shifts one unit to the left (10000)
- adi r1, r1, 1 // Adds 1 to the POSTNET code (10001)
- st r1, r3 // Stores POSTNET code into memory location 27
- // This is for POSTNET code 8
- ldi r1, 5 // Starts memory location 28 (101)
- shl r1, r1 // Shifts one unit to the right (1010)
- shl r1, r1 // Shifts one unit to the right (10100)
- adi r1, r1, 4 // Adds 4 to the memory location (11100). Stored in Memory location 28 (11000)
- adi r1, r1, 4 // Adds 4 to the memory location (10100). Stored in Memory location 28 (11000)
- ldi r1, 4 // Starts the POSTNET code (100)
- shl r1, r1 // Shifts one unit to the left (1000)
- shl r1, r1 // Shifts one unit to the left (10000)
- adi r1, r1, 2 // Adds 2 to the POSTNET code (10010)
- st r1, r3 // Stores POSTNET code into memory location 28
- // This is for POSTNET code 9
- ldi r1, 5 // Starts memory location 29 (101)
- shl r1, r1 // Shifts one unit to the right (1010)
- shl r1, r1 // Shifts one unit to the right (10100)
- adi r1, r1, 5 // Adds 5 to the memory location (11101). Stored in Memory location 29 (11101)
- adi r1, r1, 4 // Adds 4 to the memory location (11101). Stored in Memory location 29 (11101)
- ldi r1, 4 // Starts the POSTNET code (100)
- shl r1, r1 // Shifts one unit to the left (1000)
- shl r1, r1 // Shifts one unit to the left (10000)
- adi r1, r1, 4 // Adds 4 to the POSTNET code (10100)
- st r1, r3 // Stores POSTNET code into memory location 29
- // Store memory addresses in memory addresses 02-05
- // Your last instruction should be a jump to location 6
- // in order to read the variables into registers r1-r7.
- // address 0x1A
- ldi r0, 6
- jmp r0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement