Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

TASK #1: Write a program for a simple calculator that meets the following requir

ID: 1846189 • Letter: T

Question

TASK #1: Write a program for a simple calculator that meets the following requirements : 1. Since we have not taught you how to input data from the keyboard or output data to the terminal, the input and output for the calculator will be in memory locations. The calculator operations(and operands) will be stored starting at memory location $1000. The results of the operations will be stored starting at memory location $1050. Labels shall be used in the program to refer to $1000 and $1050. 2. The input operands and the output results w ill all be positive integers between 0 and 255 (i.e., unsigned byte). If a result exceeds 255, it must be set to the maximum value of 255. If a result is less than 0, it must be set to the minimum value of zero. 3. Your program will read the first operand from memory location $1000.The program will then read the first operation from memory location $1001 and the second operand from memory location $1002. The program will execute the requested operation and the result will be stored in memory location $1050. This result will then be the first operand for the next operation. The program will then read the second operation from memory location $1003 and its second operand from memory location $1004, executing and storing the result in memory location $1051. This process will continue until the END_OP instruction is reached, and the program will terminate. 4. The list of required operations and their unique codes are shown below. Labels shall be used for the operations. ADD_OP EQU $11 SUB_OP EQU $22 MUL_OP EQU $33 CLR_OP EQU $44 END_OP EQU $55 5. ADD_OP adds the two numbers. SUB_OP subtracts the two numbers. MUL_OP multiplies the two numbers. CLR_OP clears the result to be stored in the next memory location in the result table, then u ses the second operand as the initial value in the accumulator for the next operation. Requirements: 1. Complete a flowchart. 2. Demonstrate your working program

Explanation / Answer

Flow chart


Start

initialize pointer to p1=1000 and p2=1050


get operand from memory location p1
store operand in register A


LOOP

get operation from memory location p1+1

store it in register B

get operand from memory location p1+2

store it in register C


is register B ADD ?

Jump to addition

add Reg A and Reg C

if ovrflow flag is set

result =255

store result to p2

p1=p1+3

p2=p2+1


is register B SUB ?

Jump to subtraction

Jump to addition

sub Reg A and Reg C

if sign flag is set

result =0

store result to p2

p1=p1+3

p2=p2+1



is register B Mul ?

Jump to Multiplication

sub Reg A and Reg C

if ovrflow flag is set

result =255

if sign flag is set

result =0

store result to p2

p1=p1+3

p2=p2+1


is register B clear ?

Jump to clear

strore 0 in p2;

p2=p2+1;

get operand from memory location p1
store operand in register A

p1=p1+1;


is register B end ?

Jump to end


jump to LOOP


END

stop the program