Question 1: Answer:
addi $s0, $0, 5
addi $s0, $s0, 1
Explanation:
addi $s0, $0, 5 ;; $s0 = 5
addi $s0, $s0, 1 ;; $s0 = $s0 + 1; which is technically x++
Question 2: Answer: $8 = 10
Explanation:
addi $8, $0, 5 ;;; $8 = 5
add $8, $8, $8 ;; $8 = 5+5 = 10
1. Consider the following java code snippet. x = 5; X++; Give equivalent MIPS Assembly. Assume...
1. Consider the following java code. int x 5 X++ Give equivalent MIPS ISA. Assume compiler will keep x in $s0 ($16) 2. What will be in $8 after executing the following statements? addi $8, $0, 5 add $8, $8, $8 What will be in $8 after execution? 2. addi $8, $0, 5 sll $8, $8, 2 shifting $8 left twice (logical shift- assume no sign) 4. What will be in $8 after execution? Assume $9 contains a valid RAM...
1. (15 pts) For the following C statement, what is the corresponding MIPS assembly code? Assume f, g, h correspond to $80, $s1, and $s2, respectively. f=g+(h-5) 2. (15 pts) For the following pseudo-MIPS assembly instructions, what is the corresponding C code? add f, g, h add f,i, f 3. (30 pts) Provide the instruction type, assembly language instruction, and binary representation of the instruction described by the following MIPS fields: a. op = 0, rs = 18, rt=9, rd...
Question 3 (10 points) Convert the following MIPS assembly code into machine language. Write the instruction in hexadecimal. The opcode for sw 43 (101011). sw St1, -4(St3) Question 4 (10 points) Consider the following MIPS assembly code: addi $s3, $0, 5 addi $s1, S0, 3 addi Ss1, $s1, 2 beq Ss3, Ssl, target addi Ss1, Ss1, 1 target: add Ss3, Ss1, Ssl a. After running the code, what is the value of Ss3? b. If the memory address of the...
Convert from Java code to MIPS Assembly code C statements MIPS Assembly code f = (g + h) + (j + 13) A[12] = h + A[8] if (f != 0) { f = f + j; j = j - 1; } if (j==h) f = g+h; else f = g-h; f = f + A[2]; if (j !=h ) f = f + 1; f = g + h;
The following MIPS assembly code contains a mistake that violates the MIPS convention in terms of using stack for storing/protecting registers. What is the mistake and how should it be fixed? Correct the corresponding lines in the code. For the corrected code, sketch the stack frame contents at the time when the instruction ‘move $s1, $a1’ is being executed. f: addi $sp, $sp, 12 sw $ra, 8($sp) sw $s1, 4($sp) sw $s0, 0($sp) move $s0, $a0 move $s1, $a1 #...
Convert the following instructions from MIPS assembly language to
machine language
add $50, $t0, $s3 (op code: 0, function code: 32) sub $t9, $50, $zero (op code: 0, function code: 34) addi $s2, $t0, 16 (op code: 8, function code: Does not exist for I-type instructions)
(Computer
structure)For the MIPS
datapath shown below, several lines are marked with "X".
(a)
If the line
is cut at
place 1. Which of the following two
instructions will
not work?
Briefly explain why.
Add $1, $2,$3
SW $1,100($2)
(b)If the line is cut at place 2,
which code snippet will not work? Briefly explain. Code snippet
1:
Add $1, $2, $3
Add $4, $1, $1
Code snippet 2:
Add $1, $2,$3
Add $4, $5,$6
(C) If the line is...
its
brr[8]
(40%) Convert the following C-pseudo code into MIPS assembly code as a standalone program (including main and all the required directives). You can use any register. You must comply, however, with the convention of register usage. Before writing your code perform an explicit register allocation phase. Note that the C snippet is int arr[8]; int brr[4]-{1, 2, 3, 4, 5, 6, 7, 8) int i-8; while (i>-0) arrli]-brr[i-); (40%) Convert the following C-pseudo code into MIPS assembly code...
For the following C statement, what is the corresponding MIPS assembly code? Assume that the variables f, g, h, and i are given and could be considered 32-bit integers as declared in a C program. Use a minimal number of MIPS assembly instructions: f g(h 5);
For the following C statement, what is the corresponding MIPS assembly code? Assume that the variables f, g, h, and i are given and could be considered 32-bit integers as declared in a C...
2. The table below holds MIPS assembly code fragments with different branch instructions LOOP addi $s2. $s2. 2 subi $t1. st1. 1 bne t1. 0. LOOP DONE: LOOP: it st2. $0. stl beq t2. 0. DONE addi $s2. Ss2. 2 LOOP DONE: For the loops written in MIPS assembly in the above table, assume that the register Şt1 is initialized to the value of 10. What is the value in register $s2 assuming that $s2 initially has a value of...