In: Computer Science
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.
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.