Question
Work Task Step 1 Allocate your stack such that the stack is located in what we defined as the data section of RAM. Remember, we
Work Task
Step 1
Allocate your stack such that the stack is located in what we defined as the data section of RAM. Remember, we defined our data section with the label PROG using the ORG assembler directive. Use the LDS instruction to initialize your stack. Now, load the stack using a loop with the values shown below. After the stack is loaded, use the TSX command to transfer the SP to index register X and then to load accumulator A with $44 and accumulator B with $77 (HINT: take a look at the lecture on stacks).
Memory | |
Stack Pointer | $11 |
$22 | |
$33 | |
$44 | |
$55 | |
$66 | |
$77 | |
$88 | |
Figure 3: Stack and its contents.
Step 2
Code the simple postfix notation calculator that performs the operation shown in Figure 4. This calculator will only perform one operation (512+4*+3-). The infix expression of the operation to be performed is 5 + ((1 + 2) x 4) 3. Dont worry about saving the operators on the stack. Always push values on the stack. However, when you reach an operator, pull the values off the stack into registers, perform the arithmetic operation, and push the result back on the stack according to Figure 4. Your final result should be 14 ($0E) and should be on the top of the stack.
NOTE: the multiply instruction (MUL) multiplies two 8-bit numbers and returns a 16-bit number. In this case, only return the lower 8-bit as the result.
Input | Operation | Stack | Comment |
5 | Push Value | 5 | |
1 | Push Value | 1 5 | |
2 | Push Value | 2 1 5 | |
+ | Add | 3 5 | Pull two value (1, 2) and push result (3) |
4 | Push Value | 4 3 5 | |
x | Multiply | 12 5 | Pull two value (3, 4) and push result (12) |
+ | Add | 17 | Pull two value (5, 12) and push result (17) |
3 | Push Value | 3 17 | |
- | Subtract | 14 | Pull two value (17, 3) and push result (14) |
Result | (14) |
Figure 4: Postfix notation operations.
Step 3
Now take the postfix notation calculator a step further. Using a loop, branches, and the stack, create a postfix notation calculator that performs the operations specified in RPN_IN. Add the variables below to the DATA section of your code. Use these variables to implement your calculator. The variable OPER contains the ASCII representation of the operators (addition, subtraction, multiplication, and division) in HEX. Use this variable in the loop to determine what operation to perform. RPN_IN contains the variable with the operation to perform. The values in RPN_IN below are initially 63/4*2+ and the result should be 10. Try another operation of your choosing by changing RPN_IN and discuss it in the methodology section of your report.
RPN_IN FCB $06,$03,$2F,$04,$2A,$02,$2B ; 63/4*2+=10
RPN_OUT RMB 1
RPN_START FDB RPN_IN ; Pointer to start of RPN array
RPN_END FDB RPN_OUT-1 ; Pointer to end of RPN array
OPER FCB $2A,$2B,$2D,$2F ;*,+,-,/
HINTS: You will traverse the RPN_IN array in a similar fashion to lab 3. You will jump out of the array when an operator is found, pull two values off the stack, perform that particular operation, push the result onto the stack, and then return to the loop. Otherwise, you will just push the value on the stack.
NOTE: the divide instruction (IDIV) requires two 16-bit registers and returns a 16-bit value. Only return the lower 8-bit as your result.
I'm trying to figure out how to use assembly language with this method
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started