Coal 9
Coal 9
Coal 9
Lesson Plan 8
Objectives: The main objectives are: (a) The Stack; (b) A Stack Application; (c) Procedures.
Content: In this lecture detailed explanation and implementation of Stack and Procedures with different
programming practices will be covered. A stack is one-dimensional data structure. Items are
added and removed from one end of the structure; that is, it is processed in a "last-in, first-out"
manner.
Procedures or subroutines are very important in assembly language, as the assembly language
programs tend to be large in size. Procedures are identified by a name. Following this name,
the body of the procedure is described which performs a well-defined job. End of the
procedure is indicated by a return statement.
Methods: For every new topic, I will first provide the definition and the basic working, then I will
request some student to come to the board and with the help of class discussion repeat that
discussion. This process will not only give them confidence, but will also clear their idea and
encourage them to openly discuss any complications with this topic.
Resources: Besides the lecture handout, this lesson will draw from the following Text books: Assembly
Language Programming and Organization of the IBM-PC, Ytha Yu and Charles Marut.
Evaluation: In this lecture I will not be using any formal evaluation process. I will be using informal
techniques to monitor if the students have absorbed the material or not: (i) By making the
students step up to the board and solve some examples. (iii) By judging the class interaction,
which is a clear indicator of their interest.
A program must set aside a block of memory to hold the stack. we have been
doing this by declaring a stack segment:
For example:
.STACK 100H
When the program is assembled and loaded in memory, SS will contain the segment
number of the stack segment. For the preceding Stack Declaration, SP, the stack
pointer, is initialized to 100p. This represents the empty stack position: When the
stack is not empty, SP contains the offset address of the top of the stack.
PUSH:
To add a new word to the stack we PUSH it on,
The syntax is:
PUSH Source
Where source is a 16-bit register or memory word.
For example:
PUSH AX after PUSH AX
10
mins
POP:
To remove the top item from the stack, we POP It.
The syntax is:
POP destination
Where destination is a 16-bit register (except IP) or memory word.
For example:
POP BX
Before POP After POP CX
10
mins
After POP DX
MOV AH, 9
LEA DX, MSG1
INT 21H
CMP AL, 13
JE END_INPUT
PUSH AX
INC CX
JMP INPUT
END_INPUT:
MOV AH, 9
LEA DX, MSG2
INT 21H
MOV AH, 2
PRINT:
POP DX
INT 21H
LOOP PRINT
Procedure Declaration:
The syntax of procedure declaration is the following:
Name PROC type
; Body of the procedure
RET
Name ENDP
RET:
The RET (return) instruction causes control to transfer back to the calling procedure.
Every procedure (except the main procedure) should have a RET someplace; usually
it's the last statement in the procedure.
MAIN ENDP
PRINTSTAR PROC
MOV CX, 10
MOV AH, 2
MOV DL, '*'
PRINT:
INT 21H
LOOP PRINT
RET
PRINTSTAR ENDP
END MAIN
MAIN ENDP
PRINTSTAR PROC
MOV AH, 2
MOV DL, '*'
RET
PRINTSTAR ENDP
END MAIN
MAIN ENDP
INCLUDE D:\ PRINTSTAR.ASM
END MAIN