BOISE STATE ECE 332L - Exploring Assembly Language & Memor

Unformatted text preview:

ECE 332L Microprocessors Lab Lab 1 Spring 2008 Exploring Assembly Language & Memory Page 1 of 7 C:\ece332\labs\lab1\Lab1_text.doc Part 1: Start up Power on the DE2 (Lab 0 showed you how), and begin the project by doing the following: • Create new project directory • Copy lab1.sof and lab1.ptf to the new directory • Copy code provided (lab01?.s) to the new directory • Configure the DE2 in Quartus II (Reference Lab 0 for instructions) • Start the Altera Debug Client • Create a new configuration • Configure system with lab1.ptf • Configure program with lab1a.s Part 2: Add Instruction Enter the code below into a file (lab01a.s). [Save your work to the D drive! If you save to the C drive, it will disappear at the next reboot or when the computer crashes!]. Then compile and load it into the Debug Client. Utilize your ISR to understand the add instruction. You may notice that there appear to be other instructions after the add instruction. You might be wondering what good an add instruction is if it has no data to work on. For this module you can enter the values into the registers directly. Try enough different entries to cover all the special cases (positive + positive, negative + positive, etc) and run a test for each set of these values to see if you get the resulting values that you expect. Single step please. (If you just run the code, who knows where you will end up!) Do you know how to re-execute the single instruction without re-compiling and re-loading the same program? You might look at changing the value of the pc register (pc does not stand for politically correct). # lab01a.s – Your Name .text .global _start _start: add r2,r3,r4 .end Part 3: Another way to get data into a register Enter the code below into a file (lab01b.s). Modify the configuration program to point at the new code. Run (single step) the code and observe the results of each instruction. The addi instruction can be used to load numbers into a register. What is the difference between 1234 and 0x1234? You might try right clicking on the register values. Note that the data values are actually buried in the assembler instructions. Is this a problem? # lab01b.s – Your Name .text .global _start _start: movi r2,1234 movi r3,0x1234 add r4,r2,r3 .endECE 332L Microprocessors Lab Lab 1 Spring 2008 Exploring Assembly Language & Memory Page 2 of 7 C:\ece332\labs\lab1\Lab1_text.doc Now replace “movi r2, 1234” with “addi r2, r0, 1234” and “movi r3, 0x1234” with “addi r3, r0, 0x1234”. What’s the difference between these instructions? Part 4: Possibly a better add routine Enter the code below into a file (lab01c.s). Now single step through the code and observe results. What’s wrong with hardcoding values into your assembly program? Are there reasons to do the code this way? Is there a limit on the range of values that can be entered into a register with this method? The data values in this case are stored exactly the same way as in Part 3. # lab01c.s – Your Name .equ NBR1,45 .equ NBR2,0x56 .text .global _start _start: movi r3,NBR1 movi r4,NBR2 add r2,r3,r4 .end Part 5: Is this any better? Enter the code below into a file (lab01d.s). Now single step through the code and observe results. Is there a limit on the range of values that can be entered into a register with this method? In this case the data values are stored separately from the program code. You should be able to see the data values in the disassembled region just after the stw instruction. Note that the value for NBR3 displays the same value of all f’s even after executing the stw instruction. You need to go to the memory tab and display memory starting at 0; refresh memory to see the value change. # lab01d.s – Your Name .text .global _start _start: movia r5,NBR1 ldw r3,0(r5) movia r6,NBR2 ldw r4,0(r6) add r2,r3,r4 movia r7,NBR3 stw r2,0(r7) .data NBR1: .word 0x12345678 NBR2: .word 0x87654321 NBR3: .word 0xffffffff .endECE 332L Microprocessors Lab Lab 1 Spring 2008 Exploring Assembly Language & Memory Page 3 of 7 C:\ece332\labs\lab1\Lab1_text.doc Part 6: Halt Program Controlling the program counter to make sure that we always know what instruction is going be executed next is very important. But what do you do at the end of a program? How do you affectively stop the processor? You can cause the program to go into a very tight loop of one instruction, and that way you can make sure that the program will not do anything unwanted. But you have also rendered the system useless until it is reset. Load and run the following program. Hit the “Run” button and pause a few seconds later. Can you catch the program counter at any value other than 0? Does placing the branch instruction on the same line as the all_done label make the execution any faster? # lab01e.s – Your Name .text .global _start _start: all_done: br all_done .end Part 7: Simple Loop The process of writing code with a step-wise refinement approach can sometimes lead to a solution much faster than you might assume. So we will begin by adding one more operation to our list of instructions that we can use, and that is the br instruction. We will also expand on the concept of a label or symbol followed by a colon “:”. The _start label is a label that was made visible outside of the current partial program module with the .global directive. You can use other labels without making them global as in the case of the loop: and loop_end: labels. The following code will just loop forever. Using the debugger, watch the value of the r2 register. Labels do not take up space in the executable code produced, so adding the loop_end: label only marks the end of the loop structure and visually identifies the end of the loop code. Do we need to worry about end of program situation here? # lab01f.s – Your Name .text .global _start _start: movi r2,0 loop: addi r2,r2,1 br loop loop_end: .endECE 332L Microprocessors Lab Lab 1 Spring 2008 Exploring Assembly Language & Memory Page 4 of 7 C:\ece332\labs\lab1\Lab1_text.doc Part 8: Slightly more intelligent loop We could do something useful by adding a sum register (r4) that just summed the values of the counter register (r2). However,


View Full Document

BOISE STATE ECE 332L - Exploring Assembly Language & Memor

Documents in this Course
lab81

lab81

3 pages

Lab 5

Lab 5

9 pages

Lab 3

Lab 3

6 pages

Load more
Download Exploring Assembly Language & Memor
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Exploring Assembly Language & Memor and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Exploring Assembly Language & Memor 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?