Translate the following C code to MIPS assembly code.
Question 1)
int counter = 0;
void change_global(int value)
{
counter = counter + value;
}
void main()
{
change_global(5);
change_global(10);
}
The MIPS assembly code will be: .file 1 "" .section .mdebug.abi32 .previous .nan legacy .module fp=32 .module nooddspreg .abicalls .globl counter .section .bss,"aw",@nobits .align 2 .type counter, @object .size counter, 4 counter: .space 4 .text .align 2 .globl change_global .set nomips16 .set nomicromips .ent change_global .type change_global, @function change_global: .frame $fp,8,$31 # vars= 0, regs= 1/0, args= 0, gp= 0 .mask 0x40000000,-4 .fmask 0x00000000,0 .set noreorder .cpload $25 .set nomacro addiu $sp,$sp,-8 sw $fp,4($sp) move $fp,$sp sw $4,8($fp) lw $2,%got(counter)($28) movz $31,$31,$0 nop lw $3,0($2) lw $2,8($fp) nop addu $3,$3,$2 lw $2,%got(counter)($28) nop sw $3,0($2) nop move $sp,$fp lw $fp,4($sp) addiu $sp,$sp,8 j $31 nop .set macro .set reorder .end change_global .size change_global, .-change_global .align 2 .globl main .set nomips16 .set nomicromips .ent main .type main, @function main: .frame $fp,32,$31 # vars= 0, regs= 2/0, args= 16, gp= 8 .mask 0xc0000000,-4 .fmask 0x00000000,0 .set noreorder .cpload $25 .set nomacro addiu $sp,$sp,-32 sw $31,28($sp) sw $fp,24($sp) move $fp,$sp .cprestore 16 movz $31,$31,$0 li $4,5 # 0x5 lw $2,%got(change_global)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,change_global 1: jalr $25 nop lw $28,16($fp) li $4,10 # 0xa lw $2,%got(change_global)($28) nop move $25,$2 .reloc 1f,R_MIPS_JALR,change_global 1: jalr $25 nop lw $28,16($fp) nop move $sp,$fp lw $31,28($sp) lw $fp,24($sp) addiu $sp,$sp,32 j $31 nop .set macro .set reorder .end main .size main, .-main .ident "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609"
Translate the following C code to MIPS assembly code. Question 1) int counter = 0; void...
Convert the following code to assembly MIPS void checki() { int i = 0; while(i < 10) { switch(i) { case 1: i += 5; break; case 2: i --; break; case 3: i += 2; break; default: i++; } } } void main() { checki(); }
Translate the following piece of code into MIPS assembly. int x, y; int A=100, B=15, C=19, D=21; main(){ x = A + B; y = C + D; if (x > y) swap(&x,&y); } int swap (int *arg1,int *arg2) { int temp; temp = *arg1; *arg1 = *arg2; *arg2 = temp; }
Translate the following C code to MIPS assembly code. Assume that the value of i is in register $t0, and $s0 holds the base address of the integer MemArray if (i > 10) MemArray[i] = 0; else MemArray[i] = -MemArray[i];
Can anyone help to solve this MIPS assembly language problem? Please help. Translate the fowlowwing C code to MIPS assembly language. void main() { int i, sum, begin, end; for(i=0; i < 5; i++){ scanf(“%d, %d”, &begin, &end); sum = accum_range(begin, end); printf(“sum[%d: %d] = %d\n”, begin, end, sum); } int accum_range(int a, int b){ return accum (b) - accum(a); } int accum(int final) { int sum = 0; for (int I = 1; I <= final; I = I...
IN MIPS AND MUST RUN IN QTSPIM
Translate the following C code to MIPS assembly code. Use a minimum number of instructions. Assume that the values of a, b, i and j are stored in registers Ss0, Ss1, St0 and Stl, respectively. Also assume that register Ss2 holds the base address of the array D. for (i=0; i<a; itt) for (i-0j<b:jt+)
C code to MIPS Translate the following C command into MIPS assembly. Assume that the base address of arrays A is stored in register $s1. 시 I-A[2] + 7;
Translate function f into MIPS assembly language. The code for function f is as follows: int func(int a, int b){ return a + b; } int f(int a, int b, int c, int d){ return func(func(a, b), c - d);
How do i convert the following C program into MIPS assembly? int main(void) { int var1[4] ={4, 7, 12, 5}; int var2[4]= {15, 3, 6, 14}; int result[4]={0}; for (int i=0 ; i< 4; i++) result[i] = var1[i] - var2[i]; }
6. [5 points] Translate the following c code to MIPS assembly code. f = g - A(B[h]] The value of A, B, g, and h are in registers $a0, $al, $a2, and Sa3, respectively. The value of f should be stored in the register $v0.
4. (a) Translate the following pseudo-code into MIPS assembly code. Assume that A, B, C are arrays of size N elements, indexed 0..N-1 I=I; WHILE(I<N AND A[I]<B[I]) C[I] = A[I] + B[I-1]