CS代考 Instruction Set Architecture – II

Instruction Set Architecture – II
*Note: For the MIPS code sequences, the $ symbol is used to represent a register location. Also, note that $zero is used to represent MIPS register location 0.
1. Assume that the variables g, h, i, and j are given and could be considered 32-bit integers as declared in a C program:
f = g + (h – 5)

Copyright By PowCoder代写 加微信 powcoder

For the statements above, what is the corresponding MIPS instructions?
2. Write the MIPS instructions for the following C program.
3. In the snippet of MIPS assembler code below, how many times is instruction memory accessed? How many times is data memory accessed? (Count only accesses to memory for each individual instruction, not registers).
lw $t0, 0($t1) addi $t0, $t0, 1 sw $t1, 0($t1) addi $t0, $t0, 1

4. Use the register and memory values in the table below for the next questions. Assume a 32-bit machine with addressing modes as discussed in H&P. Assume each of the following questions starts from the table values; that is, DO NOT use value changes from one question as propagating into future parts of the question.
i. Give the values of R1, R2, and R3 after this instruction: add R3, R2, R1
ii. What values will be in R1 and R3 after this instruction is executed:
load R3, 12(R1)
iii. What values will be in the registers after this instruction is executed:
addi R2, R3, 16
5. Decode the following MIPS instructions (explain in English what are the effects of these instructions to the least significant 16 bits of $t2).
i. ori $t0, $zero, 0xFF2B and $t2, $t2, $t0
ii. ori $t2, $t2, 0x00E9
iii. xori $t2, $t2, 0x85
6. What’s wrong with the following picture? Correct the corresponding MIPS code.

7. Write the MIPS code segment for the following snippet of C program.
8. Write the MIPS code segment for the following snippet of C program.
9. Write the MIPS code segment for the following snippet of C program.
You can use the following branch instruction to translate the code: bge $t0,$t1,target # branch to target if $t0 >= $t1.
For your reference, a list of additional branch instructions and their description is included in the following table:
Branch Instruction
blt $t0,$t1,target ble $t0,$t1,target bgt $t0,$t1,target bge $t0,$t1,target
# branch to target if $t0 < $t1 # branch to target if $t0 <= $t1 # branch to target if $t0 > $t1 # branch to target if $t0 >= $t1

10. Look at registers $12 and $13 and memory (given below). Write the instruction that puts the value 0x00000004 into register $12.
 Register $12 contains 0xFFFFFFFF
 Register $13 contains 0x00040000
Complete the instruction below to put the value 0x00000004 into register $12.: lw$ , ($ )
11. Considering the contents of the memory location as described in the previous question, and the specified register location with the following contents:
 Register $12 contains 0xFFFFFFFF
 Register $13 contains 0x00040014
Complete the instruction below to put the word 0xFFFFFFFF into memory location 0x0004000C. It is OK to specify the 16-bit offset as a signed decimal integer.
sw$ , ($ )
Hint: You can specify the 16-bit offset as a signed decimal integer.

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com