Lab9_Week9
Lab9_Week9
Lab 9_Week9
Consider the following code, which draws a single red horizontal line of length 20 pixels in the
top row of the display in Low-res display mode:
MOV R1, #.red
STR R1, .Pixel0
STR R1, .Pixel1
STR R1, .Pixel2
STR R1, .Pixel3
STR R1, .Pixel4
STR R1, .Pixel5
STR R1, .Pixel6
STR R1, .Pixel7
STR R1, .Pixel8
STR R1, .Pixel9
STR R1, .Pixel10
STR R1, .Pixel11
STR R1, .Pixel12
STR R1, .Pixel13
STR R1, .Pixel14
STR R1, .Pixel15
STR R1, .Pixel16
STR R1, .Pixel17
STR R1, .Pixel18
STR R1, .Pixel19
HALT
(a) Write a simple ARMlite assembly program that draws a single line of the same length
across the second row (starting from the left-most column) in Low-res display mode.
(b) Add to your assembly program code that draws a single line of the same length
vertically, down the middle of the display in Low-res display mode
Once complete, show your lab demonstrator, and take a snap shot of your screen and include
in your lab submission document
Exercise 9.1.2
Consider the following code in Medium-res display mode, which like the code above, draws a
straight red line of length 20 pixels.
MOV R1, #.PixelScreen // Base address of the medium and high res pixel display memory
MOV R2, #.red // The color value for red
MOV R3, #0 // Offset, initially set to 0
loop:
ADD R4, R1, R3 // Calculate the byte offset (R1 + R3) for the next pixel and store new
address in R4
STR R2, [R4] // Store the red color at the calculated pixel address
ADD R3,R3,#4 // Increment the offset by 4 to move to the next pixel
CMP R3, #80 // Compare the offset with 80
BLT loop // If R3 is less than 80, branch back to loop
HALT
This is an example of using indirect addresssing. Step through the code yourself and make sure
you understand how its working. You may want to verify your understanding with your lab
demonstrator before you move on.
Exercise 9.1.3
(a) Explain what specifically makes this code an example of indirect addressing ? How is it
using indrect addressing to draw each pixel ?
- It calculates the pixel's address dynamically by combining a base address (#.PixelScreen, stored
in R1) with an offset (stored in R3) to form the target address in each iteration. This offset is
adjusted incrementally in a loop to move from one pixel to the next along the desired line. By
calculating addresses this way, the program efficiently updates multiple pixels in memory
without needing to hard-code each pixel’s address individually, which makes it adaptable for
different display modes or positions.
(b) Once you're confident yo understand the code, modify the program so that it draws a
line of the same length along the second row of the Mid-res display.
Hint - think about how many bytes the start and end of this line must be from the #.PixelScreen
(the top-left corner pixel of the display)
(c) Further modify your program so that it also draws a line of the same length vertically
down the middle of the display.
Hint - in this case the pixels to draw are not adjacenet to each other in memory, but they are a
constant number of bytes apart from each other. Think about how many bytes you need to jump
to get to the same position in the next row.)
Once complete, show your lab demonstrator, and take a snap shot of your screen and include
in your lab submission document
Excercise 9.2.1
Consider again the code below which we looked at in the last part:
MOV R1, #.PixelScreen
MOV R2, #.red
MOV R3, #0
loop: ADD R4, R1, R3
STR R2, [R4]
ADD R3,R3,#4
CMP R3, #80
BLT loop
HALT
In the example above, the indirect address, held in R4, is made up of from a constant value held
in R1, (the starting address for the grid of pixels, #.PixelScreen) plus a variable number of bytes
(in R3). We could say that the value in R1 is the ‘base’ address and the value in R3 is a variable
‘index’, added to the base. This suggests the use of 'indexed addressing', which as discussed in
this week's lectures, is often used when accessing individual locations within a pre-defined
blocks of memory.
In ARMlite, rewrite the code above so that is uses indexed addressing to draw the line in
Medium-res display mode.
Copy and past a screenshot of your code and correct output into your submission document.
Excercise 9.2.2
Let's now extend your solution in 9.2.1 to produce 10 consecutive rows containing a line of
length 20 pixels (ie, an offset of #80). For this you must use indexed addressing
(using .PixelScreen as the base address, and should not duplicate any code to draw each line on
the display (ie., use loops).
When complete, copy and past a screenshot of your code and correct output into your
submission document.
Excercise 9.3.2
Now modify your code so that it adds up all the values in the array. Your program should use
indexed addressing to access each value and write the result to R0.
Take a screen shot showing the code and output, and include in your submission document.
Excercise 9.4.1
Using the original array defintiion give in Part 9.3, write an ARMlite program copies all the
values from this array into another array of equal size (in reverse order).
Once complete, show your tutor the executing program, and take a screen shot showing the
code and output, and include in your submission document.
Excercise 9.4.2
Using the original array definition, write an ARMlite program that reverses the order of the
values in the array (without using another array)
Once complete, show your tutor the executing program, and take a screen shot showing the
code and output, and include in your submission document.