Topic: ARMv7 Assembly and Debugging with gdb
Related Reading: rpi-asm 9.2, Chap 11, Chap 12
and class lecture notes
Practice assembly programs:
Note: Downloading the zip file given in the tutorial will provide you with all the files for the following three examples, but you can also download the three independently from the following links, and can then use this Makefile to compile/assemble these practice problems. Just make a directory (we suggest ex_asmprogs), download the Makefile and the three example assembly programs into that directory, then type make on the Linux command line to compile/assemble all three practice problems. (Don't forget that if you make any changes to the assembly program (such as using trying different intial values) you need to re-make the programs before using them again.)
Practice program #1: This program compares two 32-bit numbers (in r1 and r4) and sets r0 to 0 if they're equal, otherwise sets r0 to 1 if they're not equal.
Try different initial values for the two numbers.
Practice program #2: This program takes an ASCII character (in variable num) and determines whether it corresponds with a number. If does, it computes the corresponding number (between 0 and 9) and stores it in r0. Otherwise it sets r0 to -1.
Try different initial values for the ASCII character in variable num.
Practice program #3: This program takes two 16-bit numbers (in variables a and b) and computes their product (in r0) through iterative addition, adding b to the sum a times.
Try different initial values for the two numbers.
Question: What will happen if the number in a is negative? How about if b is negative?
You are allowed to submit your assignment via email, but if you choose to do so, you must bring a hardcopy of your assignment along with a completed cover sheet to the instructor at the next class. (Note: Do not email the instructor any .zip file attachments, as SLU's email may not accept these emails; i.e. the instructor may not receive your email.)
Complete the Assembler and Debugger Tutorial, and answer questions #1 through #8 at the end of the tutorial (you don't need to answer question #9).
Note: Questions #4 and #8 are worth 2 points each. The rest are 1 point each.
For this problem, the initial memory values for addresses 0x8000 to 0x800f (in left-to-right order) are:
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 120, -3, 0xa7, 33, 1, 0xff, -36, 17, 0, 0x7f
Assuming that the first 10 bytes in this address range correspond to:
in left to right order, respectively, what are the initial decimal values for each of these five variables:
Give the equivalent assembly code for the following three cases:
Assume that variables b, x, and z reside in registers r4, r7, and r10, respectively.
if (3 * b < z)
x = z / 8;
else
b = x & 21;
if ((3 * b < z) || (x - b > 15))
x = z / 8;
else
b = x & 21;
if ((3 * b < z) && ((x + b > 35) || (z - 14 > x)))
x = z / 8;
else
b = x & 21;
Create an assembly program (in a .s file) that computes the dot product of two vectors. In other words, given two vectors of the same size, it multiplies each pair of values with the same index in the vector (array), and sums all those products into one sum. Here's a pseudocode implementation:
i = 0;
sum = 0;
while (i < len(vecA))
{
sum = sum + vecA[i] * vecB[i];
i += 1;
}
For this problem, assume that variables sum, vecA, and vecB all use word-sized (4-byte) elements in memory, and that sum is a scalar (single element), while vecA and vecB are arrays with the same number of elements. To accomplish this, the .data section in your assembly file (.s file) should contain a .data section declaration like the following:
.section .data
sum:
.word 0
vecA:
.word 10, -6, 14, 8, 27, -5
vecB:
.word 19, -4, 21, 3, -2, 6
You can change these values as desired.
Your program should store the final sum back into memory (into sum) and print out the result.
Verify that your program works with different initial values and different lengths of arrays for vecA and vecB. Hint: You may want to add a length variable...
You should turn in a .s file that can be compiled and run on a Pi.
Answer the Challenge Question (question #9) in the Assembler and Debugger Tutorial. Clearly explain all modifications that need to be made, especially in the assembly code.
Also turn in a .s file that can be compiled and run on a Pi.