Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
5 views

Lecture #02, Microprocessor Lab 2

Uploaded by

Shuvro Saha
Copyright
© © All Rights Reserved
Available Formats
Download as KEY, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Lecture #02, Microprocessor Lab 2

Uploaded by

Shuvro Saha
Copyright
© © All Rights Reserved
Available Formats
Download as KEY, PDF, TXT or read online on Scribd
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
Set of program statements that s 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
Call to procedure: IFACT ENDP
CALL HEX2ASC MYCODE ENDS
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
Macros
MACRO 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 tools include-
1) Text Editor  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 
functions
Tools
combines relocatable object program modules and library

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
Process
1) Text editors  Source file (e.g.,
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 mov si, offset result
msg1 db 'Enter a single digit: ', '$' mov [si], al
msg2 db cr, lf, 'You have entered: $' inc si
result db 3 dup(0) mov al, ‘$’
_DATA ends mov [si], al
mov ah, 09h
_CODE segment mov dx, offset msg2
assume cs: _CODE, ds: _DATA int 21h
start: mov ax, _DATA
mov ds, ax mov ah, 09h
mov ah, 4ch
mov ah, 09h mov dx, offset result
mov al, 00h
mov dx, offset msg1 int 21h
int 21h
int 21h
_CODE ends
end start
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
msg2 db cr, lf, 'You have entered: $'int 21h
result db 3 dup(‘$’) mov si, offset result
_DATA ends mov [si], al

_CODE segment mov ah, 09h


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

You might also like