Exploring Microprocessors Lab 1: Assembly Language and Memory, Lab Reports of Microprocessors

A lab guide for ece 332l microprocessors course, focusing on exploring assembly language & memory. It includes instructions on setting up the de2 board, entering and testing assembly code, and working with registers and memory. Students are encouraged to experiment with different instruction sets and observe the results.

Typology: Lab Reports

Pre 2010

Uploaded on 09/17/2009

koofers-user-bzr-2
koofers-user-bzr-2 🇺🇸

10 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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
.end
pf3
pf4
pf5

Partial preview of the text

Download Exploring Microprocessors Lab 1: Assembly Language and Memory and more Lab Reports Microprocessors in PDF only on Docsity!

Spring 2008 Exploring Assembly Language & Memory

Page 1 of 7

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,r .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, movi r3,0x add r4,r2,r .end

Spring 2008 Exploring Assembly Language & Memory

Page 2 of 7

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, .equ NBR2,0x

.text .global _start

_start: movi r3,NBR movi r4,NBR add r2,r3,r .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 NBR

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,NBR ldw r3,0(r5) movia r6,NBR ldw r4,0(r6)

add r2,r3,r

movia r7,NBR stw r2,0(r7) .data

NBR1: .word 0x NBR2: .word 0x NBR3: .word 0xffffffff

.end

Spring 2008 Exploring Assembly Language & Memory

Page 4 of 7

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, this is still not really satisfying as it doesn’t really do anything in a

general manner. It would be nice to sum up any list of numbers. (In the debugger, you’ll see that

addresses beyond the end of the loop contain unknown values or instructions.)

lab01g.s – Your Name

.equ MAX_LOOPS,

.text

.global _start _start:

movi r3,MAX_LOOPS movi r2, movi r4, loop: beq r2,r3,loop_end addi r2,r2, add r4,r4,r br loop loop_end:

all_done: br all_done

.end

Spring 2008 Exploring Assembly Language & Memory

Page 5 of 7

Part 9: Loop with initialized data from memory

This time we will get a count of the number of values to sum, and sum those numbers. As we did

in lab01d.s, we will get the count and values from memory and store the results back into memory.

For this version we will stick with the numbers that produce a result that we already know from

previous results.

lab01h.s – Your Name

.text

.global _start _start:

movia r5,VCOUNT # address of value count ldw r3,0(r5) # value count

movia r7,VALUES # address of values

movi r2,0 # zero counter movi r4,0 # zero sum

loop:

beq r2,r3,loop_end

ldw r6,0(r7) # get value add r4,r4,r6 # add to sum addi r7,r7,4 # position to next value

addi r2,r2, br loop

loop_end:

movia r7,SUM # address of SUM stw r4,0(r7) # store SUM

all_done: br all_done

.data

VCOUNT: .word 5 VALUES: .word 1,2,3,4, SUM: .word 0

.end

Spring 2008 Exploring Assembly Language & Memory

Page 7 of 7

Now let’s integrate the display functions into our summation code. This only requires two new

instructions to be added. Place a break at the second stwio instruction, and instead of using the single

step button try using the run (or continue program execution …) button.

lab01i.s – Your Name

.equ LEDR,0x .equ HEX,0x

.text

.global _start _start:

movia r5,VCOUNT # address of value count ldw r3,0(r5) # value count

movia r7,VALUES # address of values

movi r2,0 # zero counter movi r4,0 # zero sum

movia r8,LEDR # address red LED port movia r9,HEX # address 7 segment port

loop: stwio r2,0(r8) # *** NEW INSTRUCTION *** beq r2,r3,loop_end ldw r6,0(r7) # get value add r4,r4,r6 # add to sum stwio r4,0(r9) # *** NEW INSTRUCTION *** addi r7,r7,4 # position to next value

addi r2,r2, br loop loop_end:

movia r7,SUM # address of SUM stw r4,0(r7) # store SUM

all_done: br all_done

.data

VCOUNT: .word 8 VALUES: .word 2,3,5,7,11,13,17, SUM: .word 0

.end

This completes the code for this lab by using the stepwise refinement approach. You have

learned a lot of new instructions and produced some working code. Now, complete the practical

assignment listed as a deliverable on the lab cover sheet.

Move your project directory to team? drive.