Topic: Intro to Intel x86 Assembly, on the Linux OS
Related Reading: Sections 3.1 - 3.5 and class lecture notes
Practice problems from the textbook (answers are at the end of the chapter):
Solutions to the odd-numbered problems at the end of Chapter 6 are available on the textbook's companion website.
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 %ax is negative? How about if %bx 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 worth 1 point each.
Give the equivalent assembly code for the following three cases:
Assume that variables b, x, and z reside in registers r3, r5, and r8, respectively.
if (3 * x > b) x = b & 29; else b = x / 4;
if ((3 * x > b) || (z - b < 25)) x = b & 29; else b = x / 4;
if ((3 * x > b) && ((z - b < 25) || (z + 14 > x))) x = b & 29; else b = x / 4;
Create an assembly program that computes the "sum of absolute differences" operation. Have it compute the absolute difference between B and C and add that value to A, then take the absolute difference between B and D and again add that value to A. In other words, in a C or C++ program, the expression that accomplishes this is:
a = a + |b - c|;
a = a + |b - d|;
FYI, the "sum of absolute differences" computation is a crucial operation in MPEG video encoding. It is used to eliminate temporal redundancy, i.e. similarities between successive video images/frames in time. In fact, it is the reason that MPEG is able to achieve much higher compression rates on video than JPEG or JPEG-2000 are able to achieve on individual images.
Note: You should turn in a .s file that can be compiled and run on a Pi.
Given points A, B, and C, create a program that determines whether A is closer to point B or to point C. Compute the Euclidean distance between the points to determine whether A is closer to B, or to C. However, avoid computing the square root by using the fact that |X| < |Y| whenever X2 < Y2
Assume each point has an (x,y) coordinate, and that the coordinates are contained in the following registers:
Finally, print out which point is closer to A: point B or point C.
Again, 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.