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

CODE INASSEMBLY LANGUAGE!! This program is an exercise in using the stack and ca

ID: 3714903 • Letter: C

Question

CODE INASSEMBLY LANGUAGE!! This program is an exercise in using the stack and calling a procedure. You will populate a 5 element array nums with integers (possibly negative) and evaluate the expression: ((nums[0] - nums[1]) + (nums[2] - nums[3])) - nums[4] You will first input the contents of the nums array using a loop. Then you will evaluate the expression, utilizing the stack as much as possible. You will implement a procedure called PrintTop, that will output the top of the stack to the terminal by prefacing the value with "Top of the Stack is:". While evaluating the expession you will follow the following rules: 1. print the top of the stack whenever a) you push something onto the stack OR b) when the value at the top of the stack changes. 2. During expression evaluation, use ONLY the register eax. 3. add and subtract instructions can use ONLY the top of the stack as a destination. 4. minimize the use of constants in the .code section. For an input of 10, 20, 40, 30, 5 for nums[0] through nums[4], the output looks as follows: Please enter a number 50 or less: 10 Please enter a number 50 or less: 20 Please enter a number 50 or less: 40 Please enter a number 50 or less: 30 Please enter a number 50 or less: 5 Top of the Stack is: +10 Top of the Stack is: -10 Top of the Stack is: +40 Top of the Stack is: +10 Top of the Stack is: +0 Top of the Stack is: -5 The sum is -5 Examining this output and rule 1. above should suggest how to implement the expresson evaluation using the stack.

Explanation / Answer

Definition:

-----------------------------------------------------------------------------------------------------------------------

Assembly Language program for stack calling procedures for microprocessor 8086.

------------------------------------------------------------------------------------------------------------------------

Algorithm Execises:

Line 1: INPUT - Enter the value of the numbers using array loop A[100];

Line 2: Enter the value for expression for Stack.

Line 3: Formulate the Value X =  ((nums[0] - nums[1]) + (nums[2] - nums[3])) - nums[4] );

Line 4: Print the Expression value " Top of the stack is X = :";

Line 5: Enter the number to operate the stack operations:;

Line 6: Evaluvate the expression for given operand ADD, SUB, POP, PUSH, AND ;

Line 7: Enter number exchanges given expression by command options;

Line 8: Specifify the value for operation by using commond line arguments;

Line 9: Enter the value for the stack operaions that will be loaded;

Line 10: OUTPUT - Top of the stack value in the order.

---------------------------------------------------------------------------------------------------------------------------------------

Programming Lanaguage: Microprocessor 8086 for stack calling procedures filename callpro.asm

Call procedure using Stack Operations.

; Main Program

.model small

. stack 100

TITLE STACK_OPERATIONS

; THIS PROGRAM IS ABOUT STACK OPERATIONS BY USING CALLING PROCEDURES

; BY EXPRESSION EVALUATION IN THE PROGRAM

.data

DATA SEGMENT

BCD_INPUT DW 4209 ; Storage for BCD value

HEX_VALUE DW ? ; Storage for HEX value

BUF DB 80 ; MAX LENGTH OF ARRAY

DB 00 ; ACTUAL LENGTH OF ARRAY

DB 80 DUP (0) ; STARTING OF ARRAY

STRI DB 10,13, ' ENTER THE NUMBER:$'

SRT2 DB 10,13, ' EXPRESSION NUMBER:$'

SRT3 DB 10,13, ' ENTER VALUE NUMBER OF STACK IS:$'

SRT4 DB 10,13, ' TOP OF THE STACK IS:$'

NUM DB 0

SPC DB 0

ALPHA DB 0

DATA ENDS

CODE SEGMENT

.Code

START: MOV AX, @DATA

MOV DS, AX

MOV AH, 09H

LEA DX, M1

INT 21H

LEA DX, BUFFER

MOV CL, [BX]

MOV CH, 0

INC BX

ADD BX, CX

MOV BYTE PTR[BX], 0

MOV DS, AX

MOV AL,Y

SUB AL,Z ; Expressions Value = ((nums[0] - nums[1]) + (nums[2] - nums[3])) - nums[4]

ADD AL,X

MOV CL,X

SUB CL

MOV W, AX

SUB AX

MOV AX,BX   

MOV AH, 3DH

MOV AL, 0

LEA DX, FILE

INT 21H

JC ERROR2

MOV HANDLE, AX

MOV AH, 42H

MOV BX, HANDLE

MOV AL, 2

MOV CX, 0

MOV DX, 0

INT 21H

JC ERROR2

MOV SIZE1,DX

MOV SIZE2,AX

MOV AH, 9

LEA DX,M5

INT 21H

MOV DX, SIZE1

MOV AX, SIZE2

MOV BX,10

MOV CX,5

MOV AX, OFFSET BCD_INPUT

PUSH AX

CALL PRO1

.

.

.

; Procedure

PRO1 PROC NEAR

.

.

.

MOV AX, [BP+2] ; Base pointer is decremented by 2 when the procedure is called.

; So BCD_INPUT is available at location [BP+2].

.

.

.

MOV [BP+2] , AX ; Store the results on the stack

RET

PRO1 ENDP

CODE ENDS

----------------------------------------------------------------------------------------------------------------------

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote