Question

In: Computer Science

Write a MIPS assembly language program to find the addition of two arrays

Write a MIPS assembly language program to find the addition of two arrays

Solutions

Expert Solution

1
#data segment
02
 
03
.data     
04
 
05
      numbers:.word 2,1,5,3,10
06
 
07
      count: .word 5  
08
 
09
      
10
 
11
      ans1: .asciiz "sum = "
12
 
13
      endl: .asciiz "\n"
14
 
15
      
16
 
17
#text segment
18
 
19
.text
20
 
21
  
22
 
23
main:
24
 
25
      la $a0, numbers         # load array address
26
 
27
      lw $a1, count           # load number of elements   
28
 
29
      jal sum                 # call sum function
30
 
31
  
32
 
33
      move $a0, $v0           # call print
34
 
35
      jal print
36
 
37
  
38
 
39
      j finish                # finish
40
 
41
  
42
 
43
sum:
44
 
45
      bge $t2, $a1, done      #if t2>=$a1, goto done
46
 
47
      lw  $t0, 0($a0)         #load value at addr a0 to t0
48
 
49
      add $t1, $t1, $t0       # sum = sum + array[i]
50
 
51
      addi $a0, $a0, 4        # add addr by 4 to get the address of   next value in the array
52
 
53
      addi $t2, $t2, 1        # i = i + 1
54
 
55
     j sum
56
 
57
  
58
 
59
done:
60
 
61
      move $v0, $t1           # move result to v0
62
 
63
      jr   $ra                #go to return addr
64
 
65
  
66
 
67
print:
68
 
69
      # code to print ansl, sum and end
70
 
71
      # deleted for brevity
72
 
73
      jr $ra                  # return
74
 
75
  
76
 
77
finish:
78
 
79
      li $v0, 10    # exit
80
 
81
        syscall

Related Solutions

Write a mips assembly language program to ask the user to enter two integers A and...
Write a mips assembly language program to ask the user to enter two integers A and B and then display the result of computing the expression: A + 2B - 5.
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user toinput an...
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user to input an integer and then prints out a string that shows how that integer should be encoded using 16 bits. Your program should handle both positive and negative valued inputs. Your program should also print out an error message if the given input cannot be expressed as a 16 bit signed integer.As an example, if the input is 12, your program should output “0000000000001100”. If the input...
Write a program in MIPS assembly language to perform the calculation of the following equation and...
Write a program in MIPS assembly language to perform the calculation of the following equation and save the result accordingly:    f = 5x + 3y + z Assumptions: - Registers can be used to represent variables x, y, z, and f - Initialize x, y, and z to values of your choice. f can be initialized to zero. - Use comments to specify your register usage and explain your logic
Assignment Description: Write a MIPS assembly language program that adds the following two integers and displays...
Assignment Description: Write a MIPS assembly language program that adds the following two integers and displays the sum and the difference. In the .data section, define two variables num1 and num2 both words. Initialize num1 to 92413 10 and num2 to D4B 16 (use 0xD4B to initialize, Note that D4B is a hexadecimal number). Your main procedure/function should load the values of num1 and num2 into two temporary registers, and display them on the console window. Then add the values...
Write a MIPS Assembly Language program to perform the following operations: Request and read two integers...
Write a MIPS Assembly Language program to perform the following operations: Request and read two integers from the console (Dn and Up), Call a recursive function to compute the result int RecurseFunc( int Dn, int Up ) { if( Dn < 1 ) return 0; return Dn * Up + RecurseFunc( Dn - 1, Up + 1 ); } Print out the results
Write a MIPS Assembly Language program to perform the following operations: Request and read two integers...
Write a MIPS Assembly Language program to perform the following operations: Request and read two integers from the console (Dn and Up), Call a recursive function to compute the result int RecurseFunc( int Dn, int Up ) { if( Dn < 1 ) return 0; else return Dn * Up + RecurseFunc( Dn - 1, Up + 1 ); } Print out the results Submit your code and report here.
Write a MIPS Assembly Language program to perform the following operations: Request and read two integers...
Write a MIPS Assembly Language program to perform the following operations: Request and read two integers from the console (Dn and Up), Call a recursive function to compute the result int RecurseFunc( int Dn, int Up ) { if( Dn < 1 ) return 0; return Dn * Up + RecurseFunc( Dn - 1, Up + 1 ); } Print out the results
Write a mips assembly language program that asks the user to enter an unsigned number and...
Write a mips assembly language program that asks the user to enter an unsigned number and read it. Then swap the bits at odd positions with those at even positions and display the resulting number. For example, if the user enters the number 9, which has binary representation of 1001, then bit 0 is swapped with bit 1, and bit 2 is swapped with bit 3, resulting in the binary number 0110. Thus, the program should display 6.
Write a MIPS assembly language program to solve the following problem: For a set of integers...
Write a MIPS assembly language program to solve the following problem: For a set of integers stored in an array, calculate the sum of the even numbers and the sum of the odd numbers. The program should store these numbers in memory variables: evenSum and oddSum. Numbers should be read from the array one at a time with a zero value (0) being used to signal the end of data in the array.
Using MARS write a MIPS assembly language program to prompt the user to input two 32-bit...
Using MARS write a MIPS assembly language program to prompt the user to input two 32-bit integers X and Y (X and Y can be prompted separately or at the same time), get them from the user then store them in memory locations labeled X and Y respectively. The program then loads X and Y from the main memory to registers, calculates the sum of them (i.e. X + Y) and store the sum into a memory location labeled S....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT