Question

Question 1. Answer the following questions on MIPS Instruction Set. a) Show the minimal sequence of...

Question 1. Answer the following questions on MIPS Instruction Set.
a) Show the minimal sequence of MIPS instruction for the following pseudocode segment:

A[3] = A[10] + B;

Assume that B corresponds to register $t3 and the array A has a base address of 1000C41016 which is required to be loaded to register $t0 in your code. Provide comments for each line of your MIPS instruction.

b) Assume that Loop starts at memory location 0xC010. Provide a) instruction format of each MIPS instruction, b) encode each MIPS instruction into hexadecimal format and c) show each instruction field. Use the reference shown in Page 7 and 8, or MIPS Reference Data Green Card.

Loop :

sub $t3, $t1, $t2

lw $s2, 4($t3)

bne $s0, $s2, Exit

j Loop

Exit: …

Homework Answers

Answer #1

(a)
A[3] = A[10] + B;

lw $t1, 40($t0)       //$t1 = A[10]
add $t1, $t1, $t3   //$t1 = A[10] + B
sw $t1, 12($t0)       // A[3] = A[10] + B

(b)
sub $t3, $t1, $t2
R-format

opcode       rd           rs   rt   shamt      funct
000000   01001   01010   01011   00000   100010

Hexadecimal = 0x012A5822
-------------------------------------------------------------------------------
lw $s2, 4($t3)
I-format

opcode        rs           rt               offset
100011   01011   10010   0000000000000100

Hexadecimal = 0x8D720004
-------------------------------------------------------------------------------
bne $s0, $s2, Exit
I-format
offset = 1

opcode      rs            rt              offset
000101   10000   10010   0000000000000001

Hexadecimal = 0x16120001
-------------------------------------------------------------------------------
j Loop
J-type
Address of Loop = 0xC010 (1100 0000 0001 0000)
right shift (1100 0000 0001 0000) by 2 bit
Target = 0011 0000 0000 0100

opcode            target
000010   00000000000011000000000100

Hexadecimal = 0x08003004

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
This is a homework assignment for Computer Architecture and some question use MIPS Assembly language. 1.    ...
This is a homework assignment for Computer Architecture and some question use MIPS Assembly language. 1.     In the following MIPS assembly code, translate all the instructions to their corresponding machine code in hexadecimal format. This code is stored in the memory from address 0x1fff0000. Loop: sw $t1, 4($s0)        addi $t1, $t1, -1    sll $t1, $t1, 2        bne $t1, $s5, Exit    addi $s0, $s0, 4          j Loop Exit: … 2.     Find the MIPS...
1a. Using the MIPS program below (with bugs intact), determine the instruction format for each instruction...
1a. Using the MIPS program below (with bugs intact), determine the instruction format for each instruction and write the decimal values of each instruction field. addi $v0, $zero, 0 loop: lw $v1, 0($a0) sw $v1, 0($a1) sll $a0, $a0, 2 add $a1, $a1, $a0 beq $v1, $zero, loop 1b. Translate the following C/Java code to MIPS assembly code. Assume that the values of a, i, and j are in registers $s0, $t0, and $t1, respectively. Assume that register $s2 holds...
For the MIPS assembly instructions below, what is the corresponding C statement? Assume that the variables...
For the MIPS assembly instructions below, what is the corresponding C statement? Assume that the variables f, g, h, and I are assigned to registers $s0 - $s3, respectively. Assume that the base address of arrays X, Y, and Z are in registers $s4 - $s6, respectively. Be conservative and use a single temp register as possible. It is a C arithmetic command with two source operands and a destination. Each part is 3 points. Add $t0, $s0, $s1 addi...
Encode the following instruction (1) identify the instruction format that will be used, (2) indicate the...
Encode the following instruction (1) identify the instruction format that will be used, (2) indicate the values of each of the fields for that format in decimal, (3) convert each of these decimal val- ues to binary 4) represent the entire instruction as one hexadecimal value. subu $t3,$v1,$s2
Write the corresponding MIPS I instruction to the C++ code segment below. for (; i <...
Write the corresponding MIPS I instruction to the C++ code segment below. for (; i < 100; i ++) s = s + (2*i + 1); Use the table below for variable-register association Variable i s Register $t0 $t1 Variables s has been initialized with 0; i has been initialized with 1. No need to write instruction for their initializations. The instructions corresponding to the for-loop is labeled as "LOOP". The instructions following the for-loop is labeled by "DONE" (no...
Show the single RISC-V instruction or minimal sequence of instructions for this C statement: b =...
Show the single RISC-V instruction or minimal sequence of instructions for this C statement: b = 25 | a. Assume that a corresponds to register x0 and b corresponds to register x1. Write each instruction in a separate box.
1. Assume there are three memory locations named h hand area, translate the following expression into...
1. Assume there are three memory locations named h hand area, translate the following expression into MIPS assembly language. No Floating point. Area= 1/2 b. h 2. Show the assembly statement that allocates a word in the data segment named area with an initial value of 10. 3. What are the contents of register $t0, $t1, and $t2? .data str:    .asciiz   "ab" .text main:   la $t0, str li    $t1, 0 loop: lb $t2, ($t0) beqz   $t2, eloop addi $t1,...
(MIPS Assembly Language): Assume the following piece of MIPS code: label1: .text 0x4000fc lui $t0, 1022...
(MIPS Assembly Language): Assume the following piece of MIPS code: label1: .text 0x4000fc lui $t0, 1022 ori $t0, $t0, 2048 srl $t1, $t0, 18 sw $t0, 101($t1) slti $t2, $t1, 5 beq $t2, $0, label3 label2:... ... label3:... a) The code modifies a word in memory at the following address (circle one): (i) 1022 (ii) 101 (iii) 5 (iv) 10220000 (v) Other (provide your own answer): _________________ b) The following value is stored in memory (circle one): (i) 0x17 (ii)...
Design an expanding opcode instruction set for a computer having 18-bit instructions and the following types...
Design an expanding opcode instruction set for a computer having 18-bit instructions and the following types of instructions. There are 16 CPU registers and 16 bit addresses a. T1: 63 instructions with three registers referenced b. T2: 15 instructions with an 8 bit constant value c. T3: 16 instructions with one register reference
Answer the following questions in question/answer format. Questions 1-3, you should show calculations on how you...
Answer the following questions in question/answer format. Questions 1-3, you should show calculations on how you calculated your final answer. Each question is worth 2 points. 1. An infectious disease broke out in a village where men and women were given different medications. All infected persons had to go to the clinic to get injections once a day. Men were prescribed medication “A” which costs $400. Women were prescribed medication “B” which costs $150. The cost to administer the medication...