Question

In: Computer Science

Hello I am needing an example of how to write an assembly (MIPS) code that with...

Hello I am needing an example of how to write an assembly (MIPS) code that with will ask the user for two numbers then for addition or multiplication by typing in + or * into the command prompt. For example if I type in the number 2 and 5 then + The code should add the sum between the two numbers like 2 + 3 + 4 + 5 = 14. If multiplication is implemented then it will do the same but 2 * 3 * 4 * 5 = 120.

Thank you.

Solutions

Expert Solution

program to compute the sum of Number.

# ---------------------------------------------------------------------------------------------------------------

# Data Declarations

.data

n:              .word 5

  sumOfNumbers:   .word      0

# ------------------------------------------------------------------------------------------------------------------

# text/code section

.text

.globl main .ent main main:

# ----# Compute sum of Numbers from 1 to n.

lw   $t0, n
li   $t1, 1
li   $t2, 0
sumLoop:

$t1 add $t2,
$t2, $t3


add $t1, $t1, 1
ble $t1, $t0,
sumLoop
sw   $t2, sumOfNumbers
# ----# Done,
terminate program.

program to compute the Multification of Number.

# ---------------------------------------------------------------------------------------------------------------

# Data Declarations

.data

n: .word 5

MultificationOfNumbers:   .word 0

# ------------------------------------------------------------------------------------------------------------------

# text/code section

.text

.globl main .ent main main:

# ----# Compute multification of Numbers from 1 to n.

lw   $t0, n
li   $t1, 1
li   $t2, 0
mulLoop:

$t1 mul $t2,
$t2, $t3


mul $t1, $t1, 1
ble $t1, $t0,
mulLoop
sw   $t2, multificationOfNumbers
# ----# Done,
terminate program.


Related Solutions

I am needing assistance figuring out how to write the code for this project in C#...
I am needing assistance figuring out how to write the code for this project in C# (C sharp)... Create a new Project and name it - InClassParticipation3 Get up to 5 inputs from the user. The user must enter at least 1 number. After the first input, ask them if they would like to input another number if they say 'yes' get the provided input and multiply it to the other inputs provided by the user. If the user says...
Write MIPS assembly code for the following C code. for (i = 10; i < 30;...
Write MIPS assembly code for the following C code. for (i = 10; i < 30; i ++) { if ((ar[i] > b) || (ar[i] <= c)) ar[i] = 0; else ar[i] = a; }
This is to be done with MIPS assembly language. Write MIPS code which is equivalent to...
This is to be done with MIPS assembly language. Write MIPS code which is equivalent to the follow java program: int day = (int)(Math.random() * 7); switch (day) { case 1: System.out.println(“Monday”); break case 2: System.out.println(“Tuesday”); break case 3: System.out.println(“Wednesday”); break case 4: System.out.println(“Thursday”); break case 5: System.out.println(“Friday”); break case 6: System.out.println(“Saturday”); break case 0: System.out.println(“Sunday”); break }
Hello, I am very new to 64-bit ARM assembly and would like the code to this...
Hello, I am very new to 64-bit ARM assembly and would like the code to this following question: The Fibonacci Sequence is a series of integers. The first two numbers in the sequence are both 1; after that, each number is the sum of the preceding two numbers. 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ... For example, 1+1=2, 1+2=3, 2+3=5, 3+5=8, etc. The nth Fibonacci number is the nth number in this sequence, so...
4.Translate the following C code to MIPS assembly code. Assume that the value of i is...
4.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]; 6.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 in registers $s0, $s1, $t0, and $t1, respectively. Also, assume that register $s2 holds...
Write a MIPS assembly language to transpose a square integer matrix in code
Write a MIPS assembly language to transpose a square integer matrix in code
Compile the following C code to MIPS assembly. a. Assume that i and j are stored...
Compile the following C code to MIPS assembly. a. Assume that i and j are stored in register $s1 and $s2, respectively. i = i – 2 + j; b. Assume base address of Array B and the variable i are stored in registers $s3 and $s1, respectively. B[1] = (B[0] x 4) - I; Explain each step in detail! my professor has the following answer: 1) addi $t0, $s1, -2 add $s1, $$t0, $s2 2) lw $t0, 0 ($s3)...
Write a mips assembly code program that ask the user to enter an integer value, and...
Write a mips assembly code program that ask the user to enter an integer value, and then print the result of doubling that number.
Hello, I am working on an assignment but I am unsure of how to solve it....
Hello, I am working on an assignment but I am unsure of how to solve it. Please help me. The assignment details are below. Consider this scenario: Your friend starts a website, nothingbutflags.com, which is not making money. Your friend asks you to help generate more traffic. You ask your friend how much traffic the website had last month? And your friend replies and says only 500 visits. You also ask how many flags did you sell? Your friend replies...
Hello, I am working on an assignment but I am unsure of how to solve it....
Hello, I am working on an assignment but I am unsure of how to solve it. Please help me. The assignment details are below. Consider this scenario: Your friend starts a website, nothingbutflags.com, which is not making money. Your friend asks you to help generate more traffic. You ask your friend how much traffic the website had last month? And your friend replies and says only 500 visits. You also ask how many flags did you sell? Your friend replies...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT