Write an ARM program that implements a simple four-function calculator and prompts the user to enter a pair of decimal integers (A and B) followed by a character that specifies one of the operators:
‘+’ for addition to compute A+B
‘-‘ for subtraction to compute A-B
‘*’ for multiplication to produce the product A*B
‘/’ for division to produce the quotient A/B.
Input should be the pair of numbers followed by the operand followed by a return.
For example
5 5 + [enter]
Your program should display the result produced by performing the indicated operation on the two input operands A and B. Only the four operators listed above should be allowed and an attempt to divide by zero should be prohibited.
Define a separate function for each of the allowed operators and use the function names ADD, SUB, MUL, and DIV.
Upon return from the function, the main program should display the result on the console.
Please write the full code using scanf, switch statements, and subroutines to get the answer from the two inputs.
AREA DisplayResult, CODE, READONLY
IMPORT main
IMPORT getkey
IMPORT sendchar
EXPORT start
PRESERVE8
start
MOV R4, #0
; input1 =
0;
MOV R6, #10
; load value 10 into R6;
MOV R7, #0
; operator = 0;
MOV R8, #0
; input2 = 0;
while ; while (boolean finished == false)
; {
BL getkey ; read
key from console
BL sendchar ;
echo key back to console
CMP R0, #"+" ;
if (key=="+")
BNE elsif1 ;
{
MOV R7, #"+" ;
operator = "+";
B endwh ; finished = true;
; }
elsif1
CMP R0, #"-" ;
else if (key=="-")
BNE elsif2 ;
{
MOV R7, #"-" ;
operator = "-"
B endwh ;
finished = true;
; }
elsif2
CMP R0, #"*" ;
else if (key=="*")
BNE elsif3 ;
{
MOV R7, #"*" ;
operator = "*"
B endwh ;
finished = true;
; }
elsif3 ; else {
SUB R0, R0, #0x30 ;
convert ASCII to numeric
value
MUL R4, R6, R4 ;
input1 = input1 x 10;
ADD R4, R0, R4 ;
input1 = input1 +
value;
B while ;
}
endwh ; )
while2
BL getkey ; read key from
console
CMP R0, #0x0D
; while (key != CR)
BEQ endwh2 ; {
BL sendchar ;
echo key back to console
SUB R0, R0, #0x30 ;
convert ASCII to numeric value
MUL R8, R6, R8 ;
input2 = input2 x 10;
ADD R8, R0, R8 ;
input2 = input2 + value;
B while2 ; }
endwh2
CMP R7, #"+" ; if
(operator=="+")
BNE minus ; {
ADD R5, R4, R8
; answer = input1
+ input2;
B end ; }
minus
CMP R7, #"-" ; else if
(operator=="-")
BNE multiply ; {
SUB R5, R4, R8
; answer = input1
- input2;
B end ; }
multiply
CMP R7, #"*" ; else if
(operator=="*")
BNE end ; {
MUL R5, R4, R8
; answer = input1
* input2;
end ; }
MOV R0, #"=" ; move ASCII
value for "=" to R0
BL sendchar ; print "="
LDR R6, =0 ; load value 0 into
R6
LDR R7, =0 ; load value 0 into
R7
LDR R8, =10
; load constant value 10 into
R8
displaywh
CMP R5, #0 ;
while(answer>0)
BLS enddisplaywh ; {
MOV R10, R5
; copy value of
answer to 'number' to alter in calculations
LDR R7, =1 ;
R7 = 1;
whilea
CMP R10, #10
;
while(number>10)
BLS endwha
; {
LDR R9, =0
;
quotient = 0;
MOV R6, R10
;
remainder = number;
whileb
CMP R6, R8
;
while(remainder>10) // R6 divided
by 10
BLO endwhb
;
{
ADD R9, R9, #1
;
quotient = quotient +
1;
SUB R6, R6, R8
;
remainder = remainder - 10;
B whileb ;
}
endwhb
MOV R10, R9
; store quotient
value in 'number'
CMP R10, #0
; if
(number>0) // finding the
multiple of 10 that
BLS endifa
;
{
// we
should divide our answer by
MUL R7, R8, R7 ;
R7 =
10^x
endifa ; }
B whilea ;
}
endwha ;
LDR R6, =0
; load value 0
into R6 (R6 will store remainder)
whilec
CMP R5, R7
;
while(answer>=10^x) // dividing
our answer by 10^x
BLO endwhc
; {
ADD R6, R6, #1
;
remainder = remainder + 1;
SUB R5, R5, R7 ;
answer = answer -
10^x
B whilec ;
}
endwhc
ADD R0, R6, #0x30
; converting remaining number to
ASCII value
BL sendchar ;
print ASCII value to console
B displaywh ; }
enddisplaywh
stop B stop
END
Write an ARM program that implements a simple four-function calculator and prompts the user to enter...
Write an ARM program that implements a simple four-function calculator and prompts the user to enter a pair of decimal integers (A and B) followed by a character that specifies one of the operators: ‘+’ for addition to compute A+B ‘-‘ for subtraction to compute A-B ‘*’ for multiplication to produce the product A*B ‘/’ for division to produce the quotient A/B. Input should be the pair of numbers followed by the operand followed by a return. For example...
(50 pts) Write a program that asks user an arithmetic operator('+','−','∗' or '/') and two operands and perform the corresponding calculation on the operands. Specific requirements: (1) Your main function accepts inputs and display calculation result. (2) Write four functions to perform the four calculations. Call these functions in your main function. (3) Repeatedly asks for inputs, calculate and display result until user input nonnumeric value for operands. Hint: you can put getchar() right after scanf() to get rid of...
Write an assembler program that asks the user (as shown below) for two integers and a single character representing the arithmetic operations: addition, subtraction, multiplication and integer division (displays both quotient and remainder). Perform the requested operation on the operands and display the result as specified below. Assume SIGNED NUMBERS. The program should not divide by 0! If the user attempts to divide by 0, display the error message: "Cannot divide by zero." If this error occurs, the program should...
Implement a simple four function calculator in the LC3 assembly language that will run on the LC-3 simulator. The LC-3 computer only reads a character at a time but is capable of displaying a string of characters. This calculator program will use multiple subroutines that perform purposes such as reading multi-digit numbers, converting them to integers, performing addition, subtraction, multiplication, or division on these numbers, and displaying the result. The inputs to the calculator will not exceed 4 digits. The...
This is a quick little assignment I have to do, but I missed alot of class due to the Hurricane and no one here knows what theyre doing. please help! this is Java with intelli-J Overview In this project students will build a four-function one-run calculator on the command line. The program will first prompt the user for two numbers, then display a menu with five operations. It will allow the user to select an option by reading input using...
You are to write a program that implements a Reverse Polish Notation Calculator in C using BISON and FLEX, You only have to edit the BISON and FLEX files. Link to the files to start and have a general view of the program: https://www.dropbox.com/sh/83yzs66jhftqj5b/AABZcY9Qwl84JdUFnYpQaZk9a?dl=0 Reverse Polish Notation is a mathematical notation in which every operator follows all of its operands. It is sometimes called postfix notation, and does not require any parentheses as long as each operator has a fixed...
In C++, Write a program that it prompts to user for two integers, computes the quotient of two integers, and then displays the result. You need to do the following things in this assignment: + The main function prompts for user input and reads the two integers that the user entered. + Write a quotient function that computes the quotient of two integers and return the results. (hint: avoid integer division and divide by zero)
IN C language Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr andcreadLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate...
You are to write a program IN C++ that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: if the an item's wholesale cost is 5.00 and its markup percentage is 100%, then the item's retail price is 10.00 If an item's wholesale cost is 5.00 and its markup percentage is 50%, then the item's retail price is 7.50 Program design specs. You should have 5...
Develop a flowchart and then write a menu-driven C++ program that uses several FUNCTIONS to solve the following program. -Use Microsoft Visual C++ .NET 2010 Professional compiler using default compiler settings. -Use Microsoft Visio 2013 for developing your flowchart. -Adherence to the ANSI C++ required -Do not use <stdio.h> and <conio.h>. -Do not use any #define in your program. -No goto statements allowed. Upon execution of the program, the program displays a menu as shown below and the user is prompted to make a selection from the menu....