Homework 3 (46 total points)
Show your work for full credit.
1. (5 points @ 1 point each) Write the hexadecimal values for variables a, bb, x, y and z after the following SAL program executes.
.data
a: .word
bb: .word
x: .word
y: .word
z: .word
.text
__start: move a, 25
add bb, a, 7
not x, bb
sll bb, a, 6
and y, x, 0x000000f4
sra z, 0x87654321, 3
move x, 'a'
done
2. (4 points) Show that the following two code segments give the same value for c, for any values of a
and b. Hint: consider truth tables (see page 116 of the text).
and c, a, b not c, a
not c not d, b
or c, c, d
3. (3 points) If a 4 by 5 integer array is stored in column major order, and the starting address of the array is contained in variable base, give an expression for the byte address of the 4th element in the 3rd row. Assume rows and columns are numbered starting with 1, as shown below.
col 1 | col 2 | col 3 | col 4 | col 5 | |
row 1 | |||||
row 2 | |||||
row 3 | addr? | ||||
row 4 |
4. (5 points total) Suppose that you wanted to write a SAL program that manipulated a collection of up to 100 student records where each record had room for a 25 character, null terminated string containing a name, a gpa stored as a floating point number and a year-to-graduate stored as an integer. For example, the first record might be: "Smith, Tom\0," 3.41, 1999. The character '\0' is used to "null terminate" each string. Assume the 25 character limit on the names would not include the '\0' termination character.
a. (2 points) How would you declare space, in a SAL program, for the 100 records?
b. (3 points) Write a SAL code segment that would print the gpa of the 15th
student in the list of students. Assume we are numbering students starting
with 1.
5. (4 points) Find the largest IEEE 32 bit floating point number that does not have an integer value. Express the answer in binary and in decimal.
6. (5 points, 1 point each) To specify an addressing mode, we might need a register and/or an immediate value within an instruction. If a register value is needed, assume the register contains the value 0x00000040. If an immediate value is needed, use the immediate value be 0x00000020. Assume that memory contains:
Address Value ------- ----- 0x00000020 0x00000040 0x00000040 0x00000060 0x00000060 0x00000020If an instruction uses the following addressing modes for an operand, what value of the operand is obtained?
- Immediate addressing mode
- Register addressing mode
- Register direct addressing mode
- Base displacement addressing mode
- Indirect addressing mode
7. (4 points total) a. (2 points)What addressing mode is used by the second operand in the MAL instruction
lw $8, int_variable
b. (2 points) Give a MAL code fragment that implements this instruction using a base displacement addressing mode for the second operand in the lw instruction.
8. (10 points total) Implement the following SAL code fragment in MAL. Make sure that the MAL code has exactly the same functionality of the SAL code.
a. (4 points)Assume that
variables X, Y, and Z have been declared as integers.
add X, Y, Z # SAL code fragment
b. (6 points)
Give a MAL code fragment that implements exactly the same thing as
the SAL instruction
sub M[addr1], M[addr2], int3
9. (6 points) The MIPS architecture provides the assembly language programmer with a stack of words. This stack grows from very large addresses towards smaller addresses, and the stack pointer is defined to point to the next available location at the top of the stack. MIPS further specifies that $29 (also called $sp) is the stack pointer. Our simulator initializes $29 before a program is simulated.
Write a MAL code fragment that pushes the value -26 onto the MIPS stack.
Write a MAL code fragment that pops the top value off the MIPS stack, and places the value into register $20.
Handing In Your Homework
Turn in your file containing your answers via the handin directory. You can ls
the directory where your files for this assignment will be stored:
~cs354-1/handin/username/HW3
where HW3
is the name of the directory where you will submit this assignment and username
is your cs login. The path information allows you to review your submissions.
Now copy your file to the handin directory:
cp hw3.txt ~cs354-1/handin/username/HW3
No printout will be turned in.