0% found this document useful (0 votes)
11 views14 pages

Lecture #02, Microprocessor Lab 2

Uploaded by

Shuvro Saha
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
0% found this document useful (0 votes)
11 views14 pages

Lecture #02, Microprocessor Lab 2

Uploaded by

Shuvro Saha
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 14

EEE-3104: Microprocessor and Interfacing Lab

Dept. of Electrical and Electronic Engineering


University of Dhaka

Prof. Sazzad M.S. Imran, PhD


sazzadmsi.webnode.com
&
Dr. Sakhawat Hussain
Procedure
s
Set of program statements that can be processed independently.
Variable and labels defined in procedure are local.

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

PROC  directive that indicates beginning of procedure.


ENDP  directive that indicates end of procedure.
Procedures must be defined within code segment only.
Procedure
Procedure Call:
CALL 
s
transfer control to subprogram or procedure.
saves return address on stack.
two types  Intra-Segment or near call.
Inter-Segment or far call.

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

MACRO = beginning of macro.


ENDM = end of macro.
Body = definitions, declarations, or small part of codes.
Codes are substituted while translating them to machine code.

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.

2) Pre-Processor  translates source program to source file


macros resolved and header files included.
TASM, MASM, Borland C, Microsoft C.

3) Assembler  translates assembly language program to machine


language program.
source_file.ASM  object code with filename extension OBJ.
Borland’s TASM, Microsoft’s MASM etc.

4) Compiler  translates high level language program to equivalent object


code.
Borland or Microsoft compiler for C, Turbo Pascal etc.
Program Development
5) Linker  Tools
combines relocatable object program modules and library functions
produce single executable file.
TLINK, LINK etc.

6) Loader  loads executable file into main memory for execution.


MS-DOS shell COMMAND.COM.

7) Debugger  allows execution of program in single step mode.


process of locating and correcting error.
Borland’s TD, Microsoft’s CV etc.

8) EXE to COM Converter  converts executable file (EXE) to command file


(COM).
Microsoft’s EXE2BIN, Borland’s Turbo linker
(TLINK/T) etc.

9) Library Builder  combines all program modules into single file.


Microsoft’s LIB, Borland’s TLIB etc.
Program
Development
1) Text editors  Source file (e.g.,
Process
HELLOA.ASM)
2) Assembler/compiler  Relocatable object file.
TASM HELLOA.ASM  HELLOA.OBJ.
3) Linker  Executable files.
TLINK HELLOA.OBJ  HELLOA.EXE
TLINK HELLOA  HELLOA.EXE
4) Program running  C> HELLOA
5) Program testing:
Errors in result  Program is debugged.
6) Program debugging:
Assembling: TASM /ZI HELLOA.ASM
Linking: TLINK /V HELLOA.OBJ
Output: HELLOA.EXE
Debugging: TD HELLOA
Microprocessor Lab Execution
Procedure
How to run MASM programming through DOSBox in Windows 10?
STEP-1: Download and install DOSBox on your PC.
STEP-2: Download and copy MASM folder on your PC.
STEP-3: Now open DOSBox and type-
mount d d:\MASM and press enter.
d: and press enter.
STEP-4: Type edit filename.asm and press enter.
Write your program and save the file.
[Alternately, use Notepad to edit program]
STEP-5: Now on DOSBox window type-
masm filename.asm; and press enter.
link filename.obj; and press enter.
filename.exe and press enter.

Emu8086  emulator to edit, assemble, debug and execute ALP.


Problem: Read a single digit number from keyboard and display the number on
the screen.
(without macro,
Programming result initialized with 0)
Code:
_DATA segment mov ah, 01h
cr equ 0dh int 21h
lf equ 0ah
msg1 db 'Enter a single digit: ', mov si, offset result
'$' mov [si], al
msg2 db cr, lf, 'You have entered: inc si
$' mov al, ‘$’
result db 3 dup(0) mov [si], al
_DATA ends
mov ah, 09h
_CODE segment mov dx, offset msg2
assume cs: _CODE, ds: _DATA int 21h mov ah, 4ch
start: mov ax, _DATA mov al, 00h
mov ds, ax mov ah, 09h int 21h
mov dx, offset result _CODE ends
mov ah, 09h int 21h end start
mov dx, offset msg1
int 21h
Problem: Read a single digit number from keyboard and display the number on
the screen.
(without macro,
Programming result initialized with ‘$’)
Code:
_DATA segment
cr equ 0dh
lf equ 0ah
msg1 db 'Enter a single digit: ', mov ah, 01h
'$' int 21h
msg2 db cr, lf, 'You have entered:
$' mov si, offset result
result db 3 dup(‘$’) mov [si], al
_DATA ends
mov ah, 09h
_CODE segment mov dx, offset msg2
assume cs: _CODE, ds: _DATA int 21h mov ah, 4ch
start: mov ax, _DATA mov al, 00h
mov ds, ax mov ah, 09h int 21h
mov dx, offset result _CODE ends
mov ah, 09h int 21h end start
mov dx, offset msg1
int 21h
Problem: Read a single digit number from keyboard and display the number on
the screen.
(with macro, result
Programming Code: initialized with ‘$’)
printstring macro msg
mov ah, 09h
mov dx, offset msg
int 21h start: mov ax, _DATA
endm mov ds, ax

_DATA segment printstring msg1


cr equ 0dh
lf equ 0ah mov ah, 01h
msg1 db 'Enter a single digit: ', int 21h
'$'
msg2 db cr, lf, 'You have entered: mov si, offset result mov ah, 4ch
$' mov [si], al mov al, 00h
result db 3 dup(‘$’) int 21h
_DATA ends printstring msg2 _CODE ends
printstring result end start
_CODE segment
assume cs: _CODE, ds: _DATA

You might also like