Coal 9

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 9

H. M.

Faisal (03455275108) Computer Organization and Assembly Language (CS-530)

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.

Assignment: Give them a home assignment on programming practices.


Time Lecture
Plan Contents of Lecture Strategy
(min) (Remarks)
 Introduction of stack:
15
mins 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. The
most recent addition to the stack is called the top of the stack. A familiar example
is a stack of dishes; the last dish to go on the stack is the top one, and it's the only
one that can be removed easily.

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

Lesson 8 -2- Computer Organization and Assembly Language (CS-530)


Time Lecture
Plan Contents of Lecture Strategy
(min) (Remarks)

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

Lesson 8 -3- Computer Organization and Assembly Language (CS-530)


Time Lecture
Plan Contents of Lecture Strategy
(min) (Remarks)

10
mins

After POP DX

Lesson 8 -4- Computer Organization and Assembly Language (CS-530)


Time Lecture
Plan Contents of Lecture Strategy
(min) (Remarks)
Stack (A String Reversal Application)
10
mins .MODEL SMALL
.STACK 100H
.DATA
MSG1 DB "ENTER A STRING: $"
MSG2 DB 10,13,"REVERSE STRING: $"
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX

MOV AH, 9
LEA DX, MSG1
INT 21H

MOV CX, 0 ;TO COUNT THE CHARACTER


MOV AH, 1
INPUT:
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

MOV AH, 4CH


INT 21H
MAIN ENDP
END MAIN

Lesson 8 -5- Computer Organization and Assembly Language (CS-530)


Time Lecture
Plan Contents of Lecture Strategy
(min) (Remarks)
 Procedures:
15
mins
One of the procedures is the main procedure, and it contains the entry point to the
program. To carry out a task, the main procedure calls one of the other procedures. It
is also possible for these procedures to call each other, or for a procedure to call itself.
When one procedure calls another, control transfers to the called procedure and its
instructions are executed; the called procedure usually returns control to the caller at
the next instruction after the call statement.

Procedure Declaration:
The syntax of procedure declaration is the following:
Name PROC type
; Body of the procedure
RET
Name ENDP

Procedure Call and Return:

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.

Lesson 8 -6- Computer Organization and Assembly Language (CS-530)


Time Lecture
Plan Contents of Lecture Strategy
(min) (Remarks)
Exercise:
10 Procedures
mins
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
CALL PRINTSTAR

MOV AH, 4CH


INT 21H

MAIN ENDP
PRINTSTAR PROC
MOV CX, 10
MOV AH, 2
MOV DL, '*'

PRINT:
INT 21H
LOOP PRINT
RET

PRINTSTAR ENDP
END MAIN

Lesson 8 -7- Computer Organization and Assembly Language (CS-530)


Time Lecture
Plan Contents of Lecture Strategy
(min) (Remarks)
Procedures (RETURN + ARGUMENT)
10
mins .MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
MOV CX, 10;FEEL LIKE ARGUMENT PASS
CALL PRINTSTAR

PRINT: ;FEEL LIKE RETURN VALUE


INT 21H
LOOP PRINT

MOV AH, 4CH


INT 21H

MAIN ENDP
PRINTSTAR PROC
MOV AH, 2
MOV DL, '*'
RET

PRINTSTAR ENDP
END MAIN

Lesson 8 -8- Computer Organization and Assembly Language (CS-530)


Time Lecture
Plan Contents of Lecture Strategy
(min) (Remarks)
Procedures (Get From File)
10
mins .MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
CALL PRINTSTAR

MOV AH, 4CH


INT 21H

MAIN ENDP
INCLUDE D:\ PRINTSTAR.ASM
END MAIN

Lesson 8 -9- Computer Organization and Assembly Language (CS-530)

You might also like