Convert the following high-level language into MIPS instructions. Please write comments for each instructions. Assume a, b, c, d are associated with registers $s0, $s1, $s2, $s3, respectively.
void main ()
{
int a = 10, b = 20;
int c = add(a, b);
int d = sub(a, b);
swap (a, b);
}
int add( int var1, int var2)
{ return (var1 + var2); }
int sub(int var1, int var2)
{ return (var1 - var2); }
void swap(int var1, int var2)
{
int tmp = var1;
var1 = var2;
var2 = tmp;
}
MIPS Instruction Set- Machine Language
.file 1 "" .section .mdebug.abi32 .previous .nan legacy .module fp=32 .module nooddspreg .abicalls .text .align 2 .globl main .set nomips16 .set nomicromips .ent main .type main, @function main: .frame $fp,48,$31 # vars= 16, regs= 2/0, args= 16, gp= 8 .mask 0xc0000000,-4 .fmask 0x00000000,0 .set noreorder .cpload $25 .set nomacro addiu $sp,$sp,-48 sw $31,44($sp) sw $fp,40($sp) move $fp,$sp .cprestore 16 movz $31,$31,$0 li $2,10 # 0xa sw $2,24($fp) li $2,20 # 0x14 sw $2,28($fp) lw $5,28($fp) lw $4,24($fp) lw $2,%got(add)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,add 1: jalr $25 nop lw $28,16($fp) sw $2,32($fp) lw $5,28($fp) lw $4,24($fp) lw $2,%got(sub)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,sub 1: jalr $25 nop lw $28,16($fp) sw $2,36($fp) lw $5,28($fp) lw $4,24($fp) lw $2,%got(swap)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,swap 1: jalr $25 nop lw $28,16($fp) nop move $sp,$fp lw $31,44($sp) lw $fp,40($sp) addiu $sp,$sp,48 j $31 nop .set macro .set reorder .end main .size main, .-main .align 2 .globl add .set nomips16 .set nomicromips .ent add .type add, @function add: .frame $fp,8,$31 # vars= 0, regs= 1/0, args= 0, gp= 0 .mask 0x40000000,-4 .fmask 0x00000000,0 .set noreorder .set nomacro addiu $sp,$sp,-8 sw $fp,4($sp) move $fp,$sp sw $4,8($fp) sw $5,12($fp) movz $31,$31,$0 lw $3,8($fp) lw $2,12($fp) nop addu $2,$3,$2 move $sp,$fp lw $fp,4($sp) addiu $sp,$sp,8 j $31 nop .set macro .set reorder .end add .size add, .-add .align 2 .globl sub .set nomips16 .set nomicromips .ent sub .type sub, @function sub: .frame $fp,8,$31 # vars= 0, regs= 1/0, args= 0, gp= 0 .mask 0x40000000,-4 .fmask 0x00000000,0 .set noreorder .set nomacro addiu $sp,$sp,-8 sw $fp,4($sp) move $fp,$sp sw $4,8($fp) sw $5,12($fp) movz $31,$31,$0 lw $3,8($fp) lw $2,12($fp) nop subu $2,$3,$2 move $sp,$fp lw $fp,4($sp) addiu $sp,$sp,8 j $31 nop .set macro .set reorder .end sub .size sub, .-sub .align 2 .globl swap .set nomips16 .set nomicromips .ent swap .type swap, @function swap: .frame $fp,24,$31 # vars= 8, regs= 1/0, args= 0, gp= 8 .mask 0x40000000,-4 .fmask 0x00000000,0 .set noreorder .set nomacro addiu $sp,$sp,-24 sw $fp,20($sp) move $fp,$sp sw $4,24($fp) sw $5,28($fp) movz $31,$31,$0 lw $2,24($fp) nop sw $2,8($fp) lw $2,28($fp) nop sw $2,24($fp) lw $2,8($fp) nop sw $2,28($fp) nop move $sp,$fp lw $fp,20($sp) addiu $sp,$sp,24 j $31 nop .set macro .set reorder .end swap .size swap, .-swap .ident "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609"
Convert the following high-level language into MIPS instructions. Please write comments for each instructions. Assume a, b, c, d are associated with registers $s0, $s1, $s2, $s3, respectively. void ma...
Convert the following c code into instructions MIPS Assembly language. Assume a associated with $s0, i with $s1, and j with $s2. if( i < 10) { if( j < 10) { a = 0; } else { a = 1;} } else { a = 2; }
Given the following sequence of instructions: lw $s2, 0($s1) //1 lw $s1, 40($s3) //2 sub $s3, $s1, $s2 //3 add $s3, $s2, $s2 //4 or $s4, $s3, $zero //5 sw $s3, 50($s1) //6 a. List the read after write (current instruction is reading certain registers which haven’t been written back yet) data dependencies. As an example , 3 on 1 ($s2) shows instruction 3 has data dependency on instruction 1 since it is reading register $s2. b. Assume the 5...
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)
Convert the following C/C++ fragment into equivalent MIPS assembly language. Assume that the variables a, b, c, d, i and x are assigned to registers $t1, $t2, $t3, $t4, $s0 and $s1 respectively. if ((a<b && (c == 0) d = 1;
Convert the following C fragment to equivalent MIPS assembly language. Assume that the variables a, b, c, d, i and x are assigened to registers $t1, $t2, $t3, $t4, $s0 and $s1 respectively. Assume that the base address of the array A and B is in register $a0 and $a1 respectively. if (a > 0) b = a + 10; else b = a - 10;
Translate each of the following pseudo-instructions into MIPS instructions. You should Produce a minimal sequence of MIPS instructions to accomplish the required computation. (8 Points) 1) bgt $t1, 100, Label # bgt means branch if greater than 2) ble $s2, 10, Next # ble means branch if less than or equal 3) ror $s0, $s4, 7 # ror means rotate right $s4 by 7 bits and store the result in $s0 4) neg $s5, $s4 # $s5 will have the...
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 the below C code to basic MIPS. Please leave comments for explanation #include <stdio.h> int main(void) { printf("Insert two numbers\n"); int a,b; scanf("%d",&a); scanf("%d",&b); a=a<<2; b=b<<2; printf("%d&%d\n",a,b); return 0; }
Convert the below C code to basic MIPS. Leave comments for explanation please #include <stdio.h> int main(void) { printf("Insert two numbers\n"); int a,b,c; scanf("%d",&a); scanf("%d",&b); c=a|b; printf("%d|%d=%d\n",a,b,c); return 0; }
3. Assume that the variables £, g, i are assigned to registers $so, $s1, 5s2 respectively. Assume that the base address of arrays A, B, C are in registers Ss6, Ss7, Ss8 Write down MIPS instructions that implement the following C statement: (a) f = g- A(B [C[B+1]]]; 3. Assume that the variables £, g, i are assigned to registers $so, $s1, 5s2 respectively. Assume that the base address of arrays A, B, C are in registers Ss6, Ss7, Ss8...