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...
C PROGRAM HELP create a new file calc.c which implements a simple calculator. The calculator will perform the four basic arithmetic operations +, -, * and /. The program should prompt the user for the operation to perform in an endless loop. For example: calc > 3 + 6 9 calc > You must implement the calculator such that there is one calc function which takes as arguments the numerical values of the two operands and a pointer to the...
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...
Write a simple command-line calculator with an exception handler that deals with nonnumeric operands. Your program should display a message that informs the user of the wrong operand type before exiting. It should also ask the user to re-input the number to finish the calculation. PLEASE WRITE IN JAVA.
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)
Write a C program that prompts the user to enter a binary value, multiplies it by ten, then displays the result in binary. (“Binary” here means that the user communicates with the program in ones and zeros.) Your main function should a) declare a char array, b) call the readLn function to read from the keyboard c) call a function to convert the input text string to an int d) multiply the int by ten e) call a function to...