Write MIPS code that emulates a simple calculator. The
calculator initially has the
value 0. Prompt the user to enter a command. A command is a number,
where 0 is add,
1 is subtract, 2 is multiply, 3 is divide, 4 is clear, and 5 is
exit. When the user enters 0,
1, 2, or 3, prompt the user for a number to add, subtract, multiply
or divide from the
current value. If the user enters 4, then clear the current value
(set it to 0). If the user
enters 5, exit the program. Give useful prompts.
(MARS)
calculator.asm:
.data
string1: .asciiz "\nEnter command 0 - add 1- subtract 2 - multiply
3 - Divide 4 - clear 5 - exit: "
string2: .asciiz "Enter number: "
string3: .asciiz "\n result = "
string4: .asciiz "\n******* result cleared *******"
string5: .asciiz "\n******* Terminating Program *******"
.text
li $t0,0 #result variable initially result = 0
loop:
li $v0,4
la $a0,string3 #print string 3
syscall
li $v0,1
move $a0,$t0 #print result
syscall
li $v0,4
la $a0,string1 #print string 1
syscall
li $v0, 5
syscall
move $s0,$v0 #store user choice
beq $s0,4,clear #check user choice if 4 clear
beq $s0,5,exit #check user choice if 5
exit
li $v0,4
la $a0,string2 #print string 2
syscall
li $v0, 5
syscall
move $t1,$v0 #store user numberand perform valid
operation
beqz $s0,addition #check user choice
if 0 add
beq $s0,1,subtraction #check user choice
if 1 subtract
beq $s0,2,multiplication#check user choice if 2
multiply
beq $s0,3,division #check user choice if 3
divide
addition: add $t0,$t0,$t1 # add number to result
j loop
subtraction: sub $t0,$t0,$t1 # subtract number to
result
j loop
multiplication: mul $t0,$t0,$t1 # multiply result with
number
j loop
division: div $t0,$t0,$t1 # divide result with
number
j loop
clear: li $t0,0
li $v0,4
la $a0,string4 #print string
4
syscall
j loop
exit: li $v0,4
la $a0,string5 #print string
5
syscall
li $v0, 10#stop the program and
exit
syscall
Output:
Write MIPS code that emulates a simple calculator. The calculator initially has the value 0. Prom...
Write a calculator that will give the user this menu options: 1)Add 2)Subtract 3)Multiply 4)Divide 5)Exit . Your program should continue asking until the user chooses 5. If user chooses to exit give a goodbye message. After the user selections options 1 - 4, prompt the user for two numbers. Perform the requested mathematical operation on those two numbers. Round the result to 1 decimal place. Please answer in python and make it simple. Please implement proper indentation, not just...
Please make a JAVA program for the following using switch structures Write a program that simulates a simple Calculator program. The program will display menu choices to the user to Add, Subtract, Multiply and Divide. The program will prompt the user to make a selection from the choices and get their choice into the program. The program will use a nested if….else (selection control structure) to determine the user’s menu choice. Prompt the user to enter two numbers, perform the...
Design a calculator program that will add, subtract, multiply, or divide two numbers input by a user.Your program should contain the following:-The main menu of your program is to continue to prompt the user for an arithmetic choice until the user enters a sentinel value to quit the calculatorprogram.-When the user chooses an arithmetic operation (i.e. addition) the operation is to continue to be performed (i.e. prompting the user for each number, displayingthe result, prompting the user to add two...
In this assignment, you will write a subclass of the MemoryCalc class from Sixth Assignment – Memory Calculator. This new calculator, called ScientificMemCalc, should be able to do everything that the MemoryCalc could do, plus raise the current value to a power and compute the natural logarithm of the current value. This is a fairly realistic assignment – often when you are working for a company, you will be asked to make minor extensions to existing code. You will need...
JAVA QUESTIONDesign a simple calculator for two numbers.Important note. Avoid using IDE's facilities for automatically GUI code generation.Simple Calculator Second Number Multiply 」L Divide First Number Result Add Subtract Power Remainder -
The main method of your calculator program has started to get a little messy. In this assignment, you will clean it up some by moving some of your code into new methods. Methods allow you to organize your code, avoid repetition, and make aspects of your code easier to modify. While the calculator program is very simple, this assignment attempts to show you how larger, real world programs are structured. As a new programmer in a job, you will likely...
Question 20: Write a python program that will perform the operations of simple calculator. The operations are : Addition, subtraction, Multiplication and division. Sample output : Select operation. 1.Add 2.Subtract 3.Multiply 4.Divide Enter choice(1/2/3/4): 3 Enter first number: 15 Enter second number: 14 15 * 14 = 210
7- (50 points) Write a simple calculator in Python which supports four basic mathematical operators (1.e. + - / *). You need to define a module which supports addition, deletion, multiplication and subtraction. Then import your module to your calculator file and use it in your code. The following example shows how your basic calculator needs to work. Select operation: 1.Add 2.Subtract 3.Multiply 4.Divide Enter your choice(1/2/3/4): 3 Enter first number: 12 Enter second number: 14 12 * 14 =...
Introduction: In this lab, you will write a MIPS program to read in (up to) 50 integer values from the user, store them in an array, print out the amay, one number per line, reverse the elements in the array and finally print out the elements in the just-reversed) array. Feel free to do this lab and all assembly programming labs) in Windows. You must use MARS Getting started: l. In MARS, create a new assembly file with the name...
I'm working in assembly using nasm, and need to create a program that performs simple calculations. The prompt is below: Write a program that contains 4 procedures: ADD SUBTRACT MULTIPLY DIVIDE Read expressions from the user, such as: 1 + 2 4 - 3 2 * 3 4 / 2 . Execute every expression by calling the proper procedure. The end of user input is a period: . The output for the above code should be: 1 + 2 =...