.data element_prompt: .asciiz "Enter an element: " msg_space: .asciiz " " .text .globl main main: stack: beq $t0,$s0,sumlist # prompt user for input element la $a0,element_prompt li $v0,4 syscall # read every input li $v0,5 syscall # push element to stack addi $sp,$sp,-4 sw $v0,0($sp) addi $t0,$t0,1 j stack # get sum of array elements # t6 -- sum value sumlist: li $t6,0 # sum = 0 move $t4,$s0 # get the count sumlist_loop: beqz $t4,average # at end? if yes, fly # pop element off stack lw $t7,0($sp) # get next array element value addi $sp,$sp,4 # advance array pointer add $t6,$t6,$t7 # sum += array[i] addi $t4,$t4,-1 # bump down the count j sumlist_loop # get average # t6 -- sum value # t5 -- average value average: # print the sum li $v0,1 move $a0,$t6 # get the sum syscall div $t6,$s0 # compute sum / count mflo $t5 # retrieve it # output a space li $v0,4 la $a0,msg_space syscall # print average move $a0,$t5 li $v0,1 syscall exit: li $v0,10 # exit program syscall
In mips code please Implement the following C code in MAL and develop a small main...
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...
Write a MIPS assembly code that corresponds to the following C code. Note: use the stack to store all register values that you use in the procedures. int aver(int * array, int N){ int i, sum = 0; for ( i=0;i i<N; i++) sum += array[i]; return sum/N;} int Max( int * array, int N){ int i, Maximum = array[i]; for ( i = 1; i< N; i++) if ( array[i] > Maximum) Maximum = array[i]; return Maximum; } int...
MIPS assembly language Implement the following code in MIPS int array [ ] {2, 3, 4, 5, 6); int main) int num, position; scanf("%d",&num) ; position search(array, printf("The position is: num, 5); %d\n",positio int search(int array, int num, int size int position =-1; for(int i-0;i<size; i++) if(array [i]=num) { position-i; break; return position; Register map $s1: position $a0: array address $a1: num . $a2: size . $VO: return value
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...
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",) } }
The following code is a Java code for insertion sort. I would like this code to be modified by not allowing more than 10 numbers of integer elements (if the user enters 11 or a higher number, an error should appear) and also finding the range of the elements after sorting. /* * Java Program to Implement Insertion Sort */ import java.util.Scanner; /* Class InsertionSort */ public class InsertionSortTwo { /* Insertion Sort function */ public static void sort( int...
the code needs to be modifed. require a output for the code Java Program to Implement Insertion Sort import java.util.Scanner; /Class InsertionSort * public class Insertion Sort { /Insertion Sort function */ public static void sort( int arr) int N- arr.length; int i, j, temp; for (i-1; i< N; i++) j-i temp arrli; while (j> 0 && temp < arrli-1) arrli]-arrli-1]; j-j-1; } arrlj] temp; /Main method * public static void main(String [] args) { Scanner scan new Scanner( System.in...
2. Write a MIPS program that translates the following C code int a 1234; b 5678 int sum void main () atb sum = cout <<sum; } 2. Write a MIPS program that translates the following C code int a 1234; b 5678 int sum void main () atb sum = cout
5. Consider the following C code: int main() int x = 1; switch (x) case 1: i=1; case 2: i=5; return 0; Based on this code, answer the following: (a) Convert the above C code to MIPS assembly. (b) The condition you are testing is met at Case 1. You do not want the Case 2 to be tested. Add appropriate instructions in MIPS for this implementation. (c) If int x is any integer other than 1 or 2, you...
Step 4: Write a Sum Function Since we can write, compile and run simple c files, lets add a bit to make a program that will sum an entire array of integers. To do this we are going to simply overwrite the main.c file to include the new function. The sum function below is not complete and must be finished before the program will execute properly. %%file main.c #include <stdio.h> int sum(int array[], int arrayLength) { int i =...