Lecture #02, Microprocessor Lab 2
Lecture #02, Microprocessor Lab 2
General Form:
ProcedureName PROC [NEAR/FAR]
; save all registers that get modified using PUSH
…
; procedure codes
…
; Restore all registers that were saved in stack
; Return to calling program using RET instruction
ProcedureName ENDP
General Form:
CALL ProcedureName
Procedure
Procedure Return: s
RET transfer control from procedure back to calling procedure.
returns to main program instruction following CALL.
two types
1) Near RET:
Transfer of control is within segment.
RET replaces IP with a word from top of stack.
IP = offset address of instruction following CALL.
SP = SP+2
2) Far RET:
RET instruction pops 2 words from stack
IP = offset address of instruction following CALL
CS = segment address of calling program.
Procedure
Procedure Examples:
a) HEX2ASC PROC NEAR
s
b) MYCODE SEGMENT
… IFACT PROC FAR
; procedure code …
… ; procedure code
RET …
HEX2ASC ENDP RET
IFACT ENDP
Call to procedure: MYCODE ENDS
CALL HEX2ASC
Call to procedure:
CALL FAR PTR IFACT
Programming with
General Form:
Macros
MacroName MACRO [Argument1, …, ArgumentN]
…
; Body of macro: Program text to be declared as
macro
…
ENDM
Invoking Macro:
MacroName Arguments
Programming with
MACRO Example:
PrintString MACRO Macros
msg
mov ah, 09H ; AH=display string
function
mov dx, offset msg ; DX=offset of a data item msg
int 21H ; call DOS service
ENDM
Invoking Macro:
msg1 db ‘Hello everyone!$’
PrintString msg1
After assembling
mov ah, 09H
mov dx, offset msg1
int 21H
Program Development
Tools
Program development
1) Text Editor
tools include-
program created
source program with filename extension ASM.
DOS editor (EDIT), Visual editor (VI) etc.