1. (a) Convert the following C function to the corresponding MIPS assembly procedure:
int count(int a[], int n, int x){
int res = 0; int i = 0; for(i = 0; i != n; i++)
if(a[i] == x) res = res + 1;
return res;
}
Cannot use converter need hard copy!!!
Program:
.data
.data
n: .word 10 #n
a: .word 21, 20, 30, 4, 20, 10, 10, 21 , 15, 10 #array
a[]
x: .word 10 #search key 10
.text
.globl main
main:
la $t0, a # $t0 = &a
lw $t1, n #s2 = n
lw $t2,x #s4 = x
li $s0,0 #res=0
li $s1,0 #i=0
loop: beq $s1,$t1,end #check i<=n if i==n exit
loop
lw $s3,0($t0) #get $s3 = a[i]
bne $s3,$t2,increment #check for a[i]==x if not skip
element else continue
addi $s0,$s0,1 #increment res value
j increment
increment: addi $s1,$s1,1 #increment
i
addi $t0,$t0,4 #increment array address value of
a[]
j loop
end: li $v0,1 #Print
res value
move $a0,$s0 #for the given
inputs it sould be 3
syscall
li $v0,10
syscall
Output:
1. (a) Convert the following C function to the corresponding MIPS assembly procedure: int count(int a[],...
Convert the following to mips assembly: int recursion (int N) { int i, j, k; if (N greater than 9) { print "End recursion\n"; return N; } print "Recursion in "; print N; print ":"; for (k=0; k less than N; k=k+1) print "x"; print "\n"; i = N + 7; j = N + 1; k = 13 - i; j = recursion (j); j = j - k; j = j + i; print "Recursion...
Convert the following function to MIPS assembly code /* function to multiply two positive integers x and y*/ int multiply(int x, int y) { /* 0 multiplied with anything gives 0 */ if(y == 0) return 0; /* Add x one by one */ if(y > 0 ) return (x + multiply(x, y-1)); } Carefully assess what to place in the stack.
MIPS assembly language Covert this code to MIPS: #include <stdio.h> int function (int a) int main)i int x=5 ; int y: y function(x); printf "yd",y); return 0; int function (int a) return 3*a+5; Assumptions: . Place arguments in $a0-$a3 . Place return values in $vO-$v1 Return address saved automatically in $ra . lgnore the stack for this example. (Thus, the function will destroy registers used by calling function
How can I convert the following C code to MIPS Assembly? +++++++++++++++++++++++++++++++++ MIPS main program ++++++++++++++++++++++++++++++++ .data # Defines variable section of an assembly routine. array: .word x, x, x, x, x, x, x, x, x, x # Define a variable named array as a word (integer) array # with 10 unsorted integer numbers of your own. # After your program has run, the integers in this array # should be sorted. .text # Defines the start of the code...
19. (4 points) Convert the following C function (a leaf procedure) to an LEGv8 assembly subroutine. Make sure that you follow the LEGv8 calling conventions. long long int func (long long int a, long long int b) long long int 0: long long int s 0: while (s < b) return k;
B2. Convert the C code to MIPS assembly with only 2 efficient instructions: Register assignment: timer-v0 int timer = 0x0AC8 0001; B3. Write MIPS assembly code segment for the following C code snippet for (i - 0, i < 100; i++) -array Register assignment: i-) $ao Base of array -> $s0 array [ i+1] [i] / 2; B2. Convert the C code to MIPS assembly with only 2 efficient instructions: Register assignment: timer-v0 int timer = 0x0AC8 0001; B3. Write...
CONVERT THE FOLLOWING FUNCTION IN MARS SIMULATOR (MIPS) This FUNCTION should be Runnable on MARS (MIPS Assembler and Runtime Simulator) IDE C FUNCTION WHICH NEEDS TO BE CONVERTED (ONLY USE MARS) void decrypt(int numberOfChar, int key, char * cipherText, char * plainText) { int j = 0; int i =0; int k = 0; int reverseOrderedKey[4]; int n =4; int c =0; int d =0; int orderedKey[4] = {0,0,0,0}; while(key) { reverseOrderedKey[k] = key %10; key /= 10; k++; }...
Implement the functionality of "main" function for the following C code in MIPS assembly. Comment your code including which registers represent the variables in the main function. Include the .data and the .text sections. Do not write the bit_count function. int main() { int count = 149; int num = 432; if (count + num > 534){ count = bit_count(num); printf("%d bits to store the number", count); }else{ printf("cannot count bit in %d",) } }
How do i convert the following C program into MIPS assembly? int main(void) { short var1[4] ={5, 8, 13, 6}; short var2[4]= {16, 4, 7, 15}; short result[4]={0}; for (int i=0 ; i< 4; i++) result[i] = var1[i] - var2[i]; }
Problem #2 (20pts) Please write the MIPS assembly code corresponding to the following C code segment. Assume that f is assigned to register $s2 int Example int i, int j, int k) int f; f i+j-k-1: return fi