Microprocessors Lab Manual 408331: Hashemite University
Microprocessors Lab Manual 408331: Hashemite University
408331
Lab Rules 2
Programming Techniques 28
Microprocessor Lab
Prepared by: Eng. Ezya Khader 2
Lab Rules
General Rules:
o Be PUNCTUAL for your laboratory session.
o Foods, drinks and smoking are NOT allowed.
o The lab timetable must be strictly followed. Prior permission from the
Lab Supervisor must be obtained if any change is to be made.
o Experiment must be completed within the given time.
Instruments:
o Be careful in dealing with the lab apparatus.
o Don't change the place of any instrument or any of its cables.
o The main equipment that you will use in the lab experiments is the
MTS-8088 trainer kit; check your program carefully before
implementing it in order to avoid harming or damaging the kit ICs.
o Don't touch or remove the kit ICs.
o When you connect interfaces cards to the kit, make sure that you use
the right connector in its right location.
o If you face any problem or you have any question about the
instruments operations please refer to the laboratory supervisor.
o At the end of the lab turn-off all the instruments.
Lab Reports:
o Lab work is very important to you as an engineer, it gives you some
practical experience that you will need in your future work. Also it
increases your understanding of the theoretical material that you have
taken at class.
o Writing lab reports with high quality is also important to you, it
develops your ability to express your ideas, work, and your
observations to other people in the field.
o You must follow the following sequence in organizing your lab report .
Microprocessor Lab
Prepared by: Eng. Ezya Khader 3
Guidelines for Writing Lab Report
The most effective way to acquire the practical skills in engineering studies is
usually by experimenting in a laboratory. The process of experimentation involves
organization, observation, familiarization with various pieces of equipment, working
with others, writing, and communicating ideas and information. These are the skills
required of an engineer.
In a practical situation, such as that in the industry or university research,
experiments are designed for the purpose of clarifying research questions or
conflicting theories by means of collecting a series of data. The conclusions drawn
from that data can be used to validate a theory or sometimes to develop a theory that
explains the behavior of an engineering object. The report for this kind of experiments
must includes an introduction to the topic and purpose of the experiment, the theory,
method, procedure, equipment used in the experiment, the data presented in an
organized manner, and the conclusions based on the data gathered.
In engineering education, lab experiments are usually designed to enhance the
understanding in engineering topics. Students are supposed to "dirty their hand" in
preparing the experiment setup, organize the experiment flow, and learn to observe
the salient features as well as to spot any unexpected occurrence as part of the training
to acquire the practical skill to become an engineer. Although the introduction and the
procedure are usually given in the lab handouts, students should practice writing a
proper lab report which includes all the necessary sections, targeting at a reader who
does not have any prior knowledge about the experiment. This is to develop the skill
in documenting the laboratory work and communicating that experience to others.
This write-up gives some guidelines on what to write in each section in preparing
laboratory reports for engineering curricula.
Title Page
The title page should contain the title of the experiment, the code and title of
the course, the name of the writer, the date when the experimental work was
performed, submission date of the lab report, and the name of lecturer for whom the
report is prepared for.
Introduction or Objectives
An introduction is necessary to give an overview of the overall topic and the
purpose of the report. The motivation to the initialization of the experimental work
can be included. Its content should be general enough to orientate the reader
gracefully into the subject materials.
Theoretical Background
This section is to discuss the theoretical aspects leading to the experiment.
Typically, this involves the historical background of the theories published in the
research literature and the questions or ambiguities arose in these theoretical work.
Citations for the sources of information should be given in one of the standard
bibliographic formats (for example, using square brackets with the corresponding
number [2] that points to the List of References). Explore this background to prepare
the readers to read the main body of the report. It should contain sufficient materials
to enable the readers to understand why the set of data are collected, and what are the
salient features to observe in the graph, charts and tables presented in the later
sections.
Microprocessor Lab
Prepared by: Eng. Ezya Khader 4
Depending on the length and complexity of the report, the introduction and the
theoretical background may be combined into one introductory section.
Conclusions
The conclusions section closes the report by providing a summary to the
content in the report. It indicates what is shown by the experimental work, what is its
significance, and what are the advantages and limitations of the information
presented. The potential applications of the results and recommendations for future
work may be included.
Appendices
The appendices are used to present derivations of formulae, computer program
source codes, raw data, and other related information that supports the topic of the
report.
List of References
The sources of information are usually arranged and numbered according to
the order they are cited in the report. The reference materials may be entered in the
following formats:
[1] Author, "Title of the book", 2nd edition, New York: Publisher, 1989.
[2] Author, "Title of the paper", Journal name, Vol. 2, No. 3, Jan 1990, pg. 456-458.
[3] Author, "Title of the paper", Proceedings of Conference 1991, pg. 5-6.
[4] Author, "Title of the thesis", Ph.D. thesis, RiceUniversity, Houston, May 1973.
Microprocessor Lab
Prepared by: Eng. Ezya Khader 5
Hashemite University
Faculty of Engineering and Technology
Computer Engineering Department
Experiment 1
Exploring Software Architecture of the 8088 Microprocessor
1.1 Objectives:
1. Be familiar with the software structure of MTS-8088 kit.
2. To utilize and apply the system commands of MTS-8088 system.
3. Calculate the physical address of storage locations in the memory
address space.
4. Assemble instructions into the memory and Disassemble machine code
stored in memory.
1.3 Equipments:
Personal computer.
MTS-8088 kit.
Command Description
Memory Management Commands
D Display the contents of Memory
C Compare the contents of Memory
E Edit/Modify the memory contents
F Fill memory
M Move the contents of memory
Assembler Commands
A Command A is used to write an assembly language program.
I Insert instruction in the program
U Disassemble the assembly language instructions into machine code
Program Control Commands
G Executing Programs
R Display / modify the contents of registers.
T Trace the program execution
Numerical Operation/Conversion
B Convert a decimal number into binary
Microprocessor Lab
Prepared by: Eng. Ezya Khader 6
H Sum or difference of two hexadecimal numbers
J Convert a decimal number in Hexadecimal
S Convert a hexadecimal number into decimal
V Convert a binary number into decimal
Table 1: System commands.
You can examine this command not only on the MTS-8088 kit but also using the
DEBUG program, the programmer can issue commands to the microcomputer in the PC.
To load DEBUG program from DOS:
Start programs Run write cmdthen depress Enter () key.
Write DEBUG and depress Enter () key:
Microprocessor Lab
Prepared by: Eng. Ezya Khader 7
Hashemite University
Faculty of Engineering and Technology
Computer Engineering Department
Experiment 2
Addressing modes, Arithmetic and Data Transfer instructions
1.1 Objectives:
Practice different addressing modes.
Examine some arithmetic instructions.
Practice different data transfer instructions.
1.3 Equipments:
Personal computer.
MTS-8088 kit.
Microprocessor Lab
Prepared by: Eng. Ezya Khader 8
In this mode of addressing, Data is transferred between a memory location
located within the data segment, and the microprocessors registers. The general form
of this instruction is:
MOV REG, [Address]
Where the byte of data stored at the memory location Address (written in
HEX code) is transferred to the register REG .
Microprocessor Lab
Prepared by: Eng. Ezya Khader 9
Addition
The add instructions can be performed on 8-bit or 16-bit registers, The
allowable addressing modes include any register except segment registers, or the
memory-memory operation.
a- Addition (ADD).
Format: ADD Destination, Source
Operation: Destination = (Source) + (Destination)
(CF) = Carry
Flags affected: A, C, O, P, S, and Z.
(CF) = Carry
Flags affected: A, C, O, P, S, and Z.
Subtraction
The subtraction instructions can be either 8 or 16 bit. The allowable addressing
modes include any register except segment registers, or the memory-memory
operation.
a- Subtract (SUB)
Format: SUB Destination, Source
Operation: Destination = (Source) - (Destination)
(CF) = Borrow
Flags affected: A, C, O, P, S, and Z.
Multiplication
The addressing modes allowed for multiplication are the same for addition and
subtraction except the immediate addressing. There is no immediate multiplication
instruction in 8088. The instructions MUL & IMUL are designed in the
microprocessor 8088 to by one-operand instructions. The destination operand is AL or
AX register. This is determined by the size of the instruction operand.
a- Multiply (MUL)
Performs unsigned multiplication with 8 bit source:
Format: MUL source8Bit
Operation: AX = (AL)*( Source8Bit)
Microprocessor Lab
Prepared by: Eng. Ezya Khader 10
Performs unsigned multiplication with 16it source:
Format: MUL source16bit
Operation: DX,AX = (AX)*(Source16Bit)
Flags affected C, O (the flags are reset if the upper half of the result is
zero)
Flags affected: C, O
IMUL instruction has the same operation as MUL instruction but the flags CF and OF
are set if the upper half of the product is not the sign extension of the lower half.
Division
Microprocessor Lab
Prepared by: Eng. Ezya Khader 11
Operation: AX = Quotient ((DX, AX) / (Source16Bit))
DX = Reminder ((DX, AX) / (Source16Bit))
None of the flag bits change predictability for a division. A division can result
in two different types of errors; one is an attempt to divide by zero and the other is
a divide overflow. A divide overflow occurs when large number is divided by a
small number. For example, suppose that AX = 3000 and that it is divided by 2.
Because the quotient for an 8-bit division appears in AL, the result of 1500 a
divide overflow because the 1500 does not fit into AL. In either case, the
microprocessor generates an interrupt if a divide error occurs. In most systems, a
divide error interrupt displays an error message on the video screen.
The 8088 microprocessor has a group of data transfer instructions that are
provided to move data either between its internal registers or between an internal
register and a storage location in a memory.
MOV: Copy Data from source to destination. Source contents are not affected.
Format: MOV Destination, Source
Operation: (S) (D)
Example:
MOV Ax, 00FE
Microprocessor Lab
Prepared by: Eng. Ezya Khader 12
64Kbyte stack segment, the stack pointer (SP) is loaded with a 0000H. There are two
typical instructions that are used with stack. They are:
Examples:
By String we mean a series of data words (or bytes) that reside in consecutive
memory locations. The string instructions of the 8088 permit a programmer to
implement operations such as moving data from one block of memory to another
block elsewhere in memory. Associated with string operation, the direction flag that is
explained below.
Microprocessor Lab
Prepared by: Eng. Ezya Khader 13
The Direction Flag
The Direction flag (D) (located in the flag register) selects the auto-increment
(D = 0) or the auto decrement (D = 1) operation for the DI and SI registers during
string operations. The Direction flag is used only with the String operations. The CLD
instruction clears the D flag (D = 0), The STD instruction sets the D flag (D = 1)
A- LODS
The LODS instruction loads AL or AX with data stored at the data segment
offset address indexed by the SI register. After loading AL with a byte or AX with a
word, the contents of SI increment, if D = 0 or the contents of SI decrement, if D = 1.
B- STOS
C- MOVS
The instruction MOVS transfers data from one memory location to another.
This is the only memory-to-memory transfer allowed in the 8088.
The MOVS instruction transfers a byte or word from the data segment location
addressed by SI to the extra segment location addressed by DI.
The pointers (SI & DI) then increment or decrement the value as dictated by
the direction flag.
Microprocessor Lab
Prepared by: Eng. Ezya Khader 14
Before Execution Instructions After Execution
ES:[DI] = DS:[SI]
Df = 0 MOVSB DI = DI + 1
SI = SI + 1
ES:[DI] = DS:[SI]
Df = 1 MOVSB DI = DI - 1
SI = SI 1
ES:[DI] = DS:[SI]
ES:[DI+1] = DS:[SI+1]
Df = 0 MOVSW
DI = DI + 2
SI = SI + 2
ES:[DI] = DS:[SI]
ES:[DI+1] = DS:[SI+1]
Df = 1 MOVSW
DI = DI 2
SI = SI - 2
REPEAT
Examples
LODS
Before Execution Instructions After Execution
CLD Df = 0
MOV SI,80 SI = 81
LODSB AL = 30
CLD
MOV SI,84 Df = 0
LODSB SI = 86
MOV BH,AL BX = FC90
DS:7F = C2 LODSB AL = 90
DS:80 = 30 MOV BL,AL
DS:81 = 24 CLD Df = 0
DS:82 = 8B MOV SI,83 SI = 85
DS:83 = 71 LODSW AX = FC71
DS:84 = FC STD
DS:85 = 90 MOV SI,85 Df = 1
DS:86 = A0 LODSB SI = 83
DS:87 = F9 MOV CL,AL CX = FC90
LODSB AL = FC
MOV CH,AL
STD
Df = 1
MOV SI,83
SI = 7F
LODSW
DX = FC71
MOV DX,AX
AX = 8B24
LODSW
Microprocessor Lab
Prepared by: Eng. Ezya Khader 15
STOS
MOVS
Microprocessor Lab
Prepared by: Eng. Ezya Khader 16
Df = 0
SI = 87
DI = 77
CLD ES:6F = C2
MOV SI,7F ES:70 = 30
MOV DI,6F ES:71 = 24
MOV CX,4 ES:72 = 8B
REP MOVSW ES:73 = 71
ES:74 = FC
ES:75 = 90
ES:76 = A0
Df = 1
SI = 81
STD DI = 95
MOV SI,87 ES:97 = 71
MOV DI,9B ES:98 = FC
MOV CX,3 ES:99 = 90
REP MOVSW ES:9A = A0
ES:9B = F9
ES:9C = 8C
Microprocessor Lab
Prepared by: Eng. Ezya Khader 17
Hashemite University
Faculty of Engineering and Technology
Computer Engineering Department
Experiment 3
Assembling, Editing, Linking and Executing assembly
programs using Emu8086 and MASM
1.1 Objectives:
1. Assemble and execute instructions into the memory using Emu8086
2. Use MASM to identify then correct syntax errors and assemble a source
program into object code.
3. Edit an existing source program.
4. Explore the listing file and identify its different parts.
5. Make a run module with the LINK program then load and execute it with the
DEBUG program.
1.2 Pre-lab Preparation:
Read the experiment thoroughly and make a real effort to answer the
questions.
Read Appendix A: MASM 6.11 installation Notes.
The Pre-lab questions must be answered and submitted by each student on a
separate piece of paper to the lab supervisor BEFORE the lab starts.
1.3 Equipments:
Personal computer with MASM 6.11 software installed on it.
MTS-8088 kit.
Microprocessor Lab
Prepared by: Eng. Ezya Khader 18
3) Use MASM/L instruction to assemble the source file exp3.ASM into a
machine language object file exp3.OBJ.
Note: MASM checks the source file for syntax errors. If it finds any, a short
description of the errors will be displayed with the line number of each.
Now the files exp3.OBJ and exp3.LST will be created.
Before feeding the ".OBJ" file into LINK, all syntax errors produced by the
assembler must be corrected.
The ".lst" file which is optional is very useful to the programmer because it
lists all the opcodes and offset addresses as well as errors that MASM
detected.
4) LINK program with MASM version 6.11 take one or more object files and
combine them into a single executable file (.EXE file).
Microprocessor Lab
Prepared by: Eng. Ezya Khader 19
Now the files exp3.EXE and exp3.MAP will be created.
The ".MAP" file which is optional gives the name of each segment, where it
starts, where it stops, and its size in bytes.
So when there are many segments for code or data there is a need to see where
each is located and how many bytes are used by each.
5) Now you can load the program in the DEBUG. See the following figure.
Microprocessor Lab
Prepared by: Eng. Ezya Khader 20
Second: Emu8086
1. Open emu8086 (Figure 1)
Figure 1
Figure 2
Figure 3
Figure 4
Microprocessor Lab
Prepared by: Eng. Ezya Khader 21
Figure 5
Figure 6
Figure7
Microprocessor Lab
Prepared by: Eng. Ezya Khader 22
5. Example: Create COM file and write these tow instructions as shown in
(Figure 8)
Figure 8
6. Compile, correct errors if any, and then run (Emulate) (Figure 9)
Figure 9
7. When you press Emulate, this window (Figure 10) will appear, it displays the
value of all Registers, flags, block of memory (1K) at a time as Hex value,
Decimal value, and ASCII char, and disassembled machine code.
You can watch and change them during the executing of your code.
Figure 10
8. This window (Figure 11) views the source code; the highlighted instruction is
the next one to be executed
Microprocessor Lab
Prepared by: Eng. Ezya Khader 23
Figure 11
9. To change any register or any memory location, double click on the register
(Figure 10), this window (Figure 12) will appear, from Watch select the
register then change it as HEX, BIN, or OCT.
Figure 12
Figure 13
Close the window in Figure 13; the value of AX is changed (blue color)
(Figure 14)
Microprocessor Lab
Prepared by: Eng. Ezya Khader 24
Figure 14
Figure 15
Figure 16
Microprocessor Lab
Prepared by: Eng. Ezya Khader 25
Figure 17
4) Close the window in Figure 17; the value at offset 0106 and 0107 is
changed (Figure 18)
Figure 18
Figure 19
12. Figure 20 & 21 show the changes after executing MOV AX, 2
Figure 20
Microprocessor Lab
Prepared by: Eng. Ezya Khader 26
Figure 21
13. Then press again on Single Step for the next instruction until you finish your
code.
14. NOTE: Emulator has a complete 8086 instruction set, press on HELP
Microprocessor Lab
Prepared by: Eng. Ezya Khader 27
Hashemite University
Faculty of Engineering and Technology
Computer Engineering Department
Experiment 4
Programming Techniques
1.1 Objectives:
1. Learn how to write assembly programs using simplified and full segment
definitions
2. Define subroutines.
3. Explain the use of EXTRN and PUBLIC as they apply to modular
programming.
4. Set up a library file that contains commonly used subroutines.
5. Define macros by coding its definition directives, write assembly language
instructions to invoke macros.
1.3 Equipments:
Personal computer with MASM software installed on it.
MTS-8088 kit.
Data Definition
Using assembly language the user can define different types of data with different
sizes. Data allocation directives (DB, DW, DD.) are used to declare variables as
in the following examples:
An error occurs if the value assigned is greater than memory size allocated to
it
Microprocessor Lab
Prepared by: Eng. Ezya Khader 28
STR2 DB 8 ; STR2='8', the ASCII code of '8'
Illegal instructions
In assembly language there are some illegal operations that the user should avoid to
make sure that the assembler will not generate errors:
VAR DB 5
MOV AX, VAR ; error
Directives:
1. Use Directives to tell assembler what to do
2. Commands that are recognized and acted upon by the assembler
Not part of the Intel instruction set
Used to declare code, data areas, select memory model, declare
procedures, etc.
3. Different assemblers have different directives
NASM != MASM, for example.
Instructions:
1. Use Instructions to tell CPU what to do.
2. Assembled into machine code by assembler
3. Executed at runtime by the CPU
4. Member of the Intel IA-32,IA-16 instruction set
Segment Definition
There are two ways to define segments in assembly
Microprocessor Lab
Prepared by: Eng. Ezya Khader 29
Simplified segment Definition
The following example shows the structure of a main module using simplified segment
directives:
.MODEL memorymodel ; It is required before you can use other simplified segment
directives
.STACK ; Use default 1-kilobyte stack
.MODEL Directive
The .MODEL directive defines the attributes that affect the entire module: memory
model, default calling and naming conventions, operating system, and stack type.
You must place .MODEL in your source file before any other simplified segment
directive. The syntax is: .MODEL memorymodel
The memorymodelfield is required and must appear immediately after the .MODEL
directive
The following list summarizes the memorymodelfield
Memory model No. of code No. of data Data and code Segment size
segments segments combined
Tiny 1 Yes 64k
Compact 1 Many No 64k
Small 1 1 No 64k
Medium Many 1 No 64k
Large Many Many No 64k
Flat 1 Yes 32 bit OS
4G
Microprocessor Lab
Prepared by: Eng. Ezya Khader 30
Full Segment Definitions
If you need complete control over segments, you can fully define the segments in your
program.
A defined segment begins with the SEGMENT directive and ends with the ENDS
directive:
nameSEGMENT
nameENDS
Everything between the two directives SEGMENT and ENDS is the program's data
segment. There is nothing in this segment definition to tell the assembler that it is a
data segment. You can define variables in the code segment or in the stack segment if
you want, even though it's customary and more correct programming practice to keep
variables in the data segment.
Segment MyData could be just as easily considered a code segment, though not a
stack segment. We have the problem of indicating to the assembler which segment is
the data segment. This might seem like an easy one, but rather than a single problem it
is actually two problems: one is that the assembler needs to know which segment
address to put into the Data Segment (DS) register; and the other problem is which
form of memory-addressing machine instructions to use.
The first problem is easily addressed:
Microprocessor Lab
Prepared by: Eng. Ezya Khader 31
That, however, doesn't solve the second problem. Although we wrote two instructions
that moved the address of our data segment into DS, the assembler doesn't "know" that
this move took place. Never forget that the assembler follows its orders without
understanding them. It doesn't make inferences based on what you do to addresses or the
segment registers. It must be told which segment is to be used as the data segment, the
code segment, and the stack segment. Somewhere inside the assembler program is a little
table where the assembler "remembers" that segment MyData is to be considered the data
segment, and that segment MyCode is to be considered the code segment, and that
segment MyStack is to be considered the stack segment. It can't remember these
relationships, however, unless you first tell the assembler what they are somehow. This
somehow (for the data, code, and extra segments, at least) is the ASSUME directive.
Why is this important? It has to do with the way the assembler creates the binary opcodes
for a given instruction. When you write an instruction that addresses memory data like
this:
MOV AX,Eat1
The assembler must put together the series of binary values that will direct the CPU to
perform this action. What that series of binary values turns out to be depends on what
segment the label Eat1 resides in. If Eat1 is in the data segment, the binary opcodes will
be one thing, but if Eat1 resides in the code segment, stack segment, or extra segment, the
binary opcodes will be something else again. The assembler must know whether any label
indicates an address within the data segment, code segment, stack segment, or extra
segment. The assembler knows that Eat1 indicates an address within the segment
MyData, but you must tell the assembler that MyData is in fact the data segment.
The Syntax of the ASSUME Directive is:
ASSUME CS:MyCode, DS:MyData, SS:MyStack
Example :
The following code shows how to define the same program using the simplified and full
segments definitions:
SIMPLIFIED SEGMENT FULL SEGMENT DEFINITION
DEFINITION
.MODEL SMALL
.STACK 64 MyStack SEGMENT
DB 64 DUP (?)
MyStack ENDS
Microprocessor Lab
Prepared by: Eng. Ezya Khader 32
Second: Subroutines
There are two basic instructions for subroutine handling: the call (CALL) and
ret (RET) instructions. Together they provide the mechanism for calling a subroutine
into operation and returning control back to the main program.
a- CALL
Format: CALL Operand
Operation: PUSH IP
IP = operand (16 bit)
Flags affected: None
b- RET
Format: RET or RET Operand
Operation: POP IP
SP = SP + Operand
Flags affected: None
EXAMPLE 1
.MODEL SMALL
.DATA
PUBLIC Table1
PUBLIC Table2
PUBLIC Table3
PUBLIC Datax
Table1 DW 01H,02H,3FH,42H,05H,16H
Table2 DW 10DUP(?)
Table3 DB 10DUP(?)
Datax DD 4DUP(?)
.CODE
.STARTUP
PUBLIC Main
Main PROC FAR
MOV SI, OFFSET Table1
Microprocessor Lab
Prepared by: Eng. Ezya Khader 33
MOV DI, OFFSET Table2
MOV CX, 6H
LO:
MOVSW
LOOP LO
Main ENDP
END
The EXTRN statement appears in both data and code segments to define labels as
external to the segment. If data are defined as external, their sizes must be defined as
BYTE, WORD, or DWORD. If a jump or call address is external, it must be defined as
NEAR or FAR. Example 2 shows how the external statement is used to indicate that
several labels are external to the program listed.
EXAMPLE 2
.MODEL SMALL
.DATA
EXTRN Table1:WORD
EXTRN Table2:WORD
EXTRN Table3:BYTE
EXTRN DATAx :DWORD
.CODE
EXTRN Main:FAR
.STARTUP
MOV DX, OFFSET Table3
MOV AX,05H
MOV [DX],AX
.EXIT
END
Fourth: Libraries
Library files are collections of procedures that are used by many different
programs. These procedures are assembled and compiled into a library file by the LIB
program that accompanies the MASM assembler program. Libraries allow common
procedures to be collected into one place so they can be used by many different
applications. The library file (FILENAME.LIB) is invoked when a program is linked
with the linker program.
When the library file is linked with a program, only the procedures required by
the program are removed from the library file and added to the program- If any
amount of assembly language programming is to be accomplished efficiently, a good
set of library files is essential and saves many hours in receding common functions.
A library file is created with the LIB command, typed at the DOS prompt. A
library file is a collection of assembled .OBJ files that each performs one procedure or
task. Example 3 shows two separate files (Main1 and Main2) that will be used to
structure a library file. The name of the procedure must be declared PUBLIC in a
library file and does not necessarily need to match the file name. Each procedure in
this example is defined as a FAR procedure, so that the linker can place the
procedures in a code segment separate from the main program.
EXAMPLE 3
; The first library module Main1
.MODEL TINY
.stack
.code
.startup
PUBLIC Main1
Main1 PROC FAR
Microprocessor Lab
Prepared by: Eng. Ezya Khader 34
PUSH DX
READKEY1: MOV BX,0AA55H
MOV CL, 5
SHR BX, CL
AND BX, 0F0FH
RET
Main1 ENDP
END
.MODEL TINY
.stack
.code
.startup
PUBLIC Main2
Main2 PROC FAR
MOV DX, AX
ADD DX, BX
ADD DX, CX
MOV SI, DX
POP DX
RET
Main2 ENDP
END
The LIB program is used to combine them into a single library file.
C:/masm614/bin> LIB
Microsoft (R) Library Manager Version 3.20-010
Copyright (C) Microsoft Corp. 1983-1992. All rights reserved.
Library name: name
Library file does not exist. Create? Y
Operations: Main1+Main2
List file: name
The LIB program begins with the copyright message from Microsoft, followed by the
prompt Library name. The library name chosen is name for the name.LIB file.
Because this is a new file, the library program asks if we wish to create the library
file. The Operations: prompt is where the library module names are typed. In this
case, we create a library by using two procedure files (Main1 and Main2). Note that
these files were created and assembled as Main1.ASM and Main2.ASM from
Example 3. The list file shows the contents of the library and is illustrated in Example
4. The list file shows the size and names of the files used to create the library, and the
public label (procedure name) that is used in the library file.
EXAMPLE 4
MAIN1.............main1 MAIN2.............main2
main1 Offset: 00000010H Code and data size: 50dH
MAIN1
main2 Offset: 000000b0H Code and data size: 50aH
MAIN2
Once the library file is linked to your program file, only the library procedures
actually used by your program are placed in the execution file. Don't forget to use the
label EXTRN when specifying library calls from your program module. For example,
to use the Main2 procedure in a program, type
EXTRN Main2:FAR
Microprocessor Lab
Prepared by: Eng. Ezya Khader 35
Fifth: Macros
A macro is a group of instructions that perform one task, just as a procedure
performs one task. The difference is that a procedure is accessed via a CALL
instruction, while a macro, and all the instructions defined in the macro, is inserted in
the program at the point of usage. Macro sequences execute faster than procedures
because there are no CALL and RET instructions to execute. The instructions of the
macro are placed in your program by the assembler at the point they are invoked.
The MACRO and ENDM directives delineate a macro sequence. The first
statement of a macro is the MACRO instruction, which contains the name of the
macro and any parameters associated with it.
Example 5
INCLUDE Irvine32.inc
Putchar MACRO char
pusheax
moval,char
popeax
ENDM
.code
main PROC
Putchar 'A'
moval,'A'
mov ecx,20
L1: Putchar al
inc al
Loop L1
quit: exit
main ENDP
END main
If a macro is expanded more than once in a program and there is a label in the label
field of the body of the macro, these labels must be declared as LOCAL. Otherwise,
an assembler error would be generated when the same label was encountered in two
or more places. The directive LOCAL is used to declare a local label. It must appear
right after the MACRO directive, before comments and the body of the macro. The
LOCAL directive can be used to declare all names and labels at once.
Microprocessor Lab
Prepared by: Eng. Ezya Khader 36
Hashemite University
Faculty of Engineering and Technology
Computer Engineering Department
Experiment 5
BIOS Interrupts Programming
1.1 Objectives:
1. To become familiar with the BIOS interrupts of the 8086/88 processor.
1.3 Equipments:
Personal computer with MASM software installed on it.
MTS-8088 kit.
Since interrupts are numbered 00 to FF, this gives a total of 256interrupts in 80x86
microprocessors. Of these 256 interrupts, two are the most widely used: INT10 and
INT 21. Each one can perform many functions. You can find a list of these interrupts
in textbooks or on the web. Before the service of INT 10H or INT 21H is requested,
certain registers must have specific values in them, depending on the function being
requested. Various functions of INT 21H and INT 10H are selected by the value put
in the AH register.
BIOS Interrupts
Interrupt types 0-1FH are known as BIOS interrupts. This is because most of these
service routines are BIOS routines residing in the ROM segment F000h.
Interrupt Types 0 7
Interrupt types 0 7 are reserved by Intel, with types 0 4 being predefined. IBM
uses type 5 for print screen. Types 6 and 7 are not used.
Interrupt Types 8h Fh
The 8086 has only one terminal for hardware interrupt signals. To allow more devices
to interrupt the 8086, IBM uses an interrupt controller, the Intel 8259 chip which can
interface up to eight devices. Interrupt types 8 Fh are generated by hardware devices
connected to 8259.
Microprocessor Lab
Prepared by: Eng. Ezya Khader 37
Interrupt Types 10h 1Fh
The interrupt routines 10h 1Fh can be called by application programs to perform
various I/O operations and status checking.
Mode Numbers
Depending on the type of adapter present, a program can select text or graphics
modes. Each mode is identified by a mode number; table 5.1 lists the text modes for
the different kinds of adapters.
Display Pages
For the DMA, the display memory can hold one screenful of data. The graphics
adapter, however, can store several screens of text data. This is because graphics
display requires more memory, so the memory unit in a graphics adapter is bigger. To
fully use the display memory, a graphics adapter divides its display memory into
display pages. One page can hold the data for one screen. The pages are numbered,
starting with 0; the number of pages available depends on the adapter and the mode
selected. If more than one page is available, the program can display one page while
Microprocessor Lab
Prepared by: Eng. Ezya Khader 38
updating another one. Table 5.2 shows the number of display pages for the MDA,
CGA, EGA, and VGA in text mode. In the 8025 text mode, each display page is
4KB. The MDA has only one page, page0; it starts at location B000:0000h. The CGA
has four pages, starting at address B800:0000h. In text mode, the EGA and VGA can
emulate either the MDA or CGA.
16 Color Display
The attribute byte for 16 color text display (modes 0 3) has the format shown
below. A 1 in a bit position selects an attribute characteristic. Bits 0 2 specify the
color of the character (foreground color) and bits 4 6 give the color background at
the character's position. Bit 3 specifies the intensity of the character and bit 7 specifies
whether the character is blinking or not.
Bit 7 6 5 4 3 2 1 0
Attribute Blinking Background color Intensity Foreground color
Red Green Blue Red Green Blue
Monochrome Display
For monochrome display, the possible colors are white and black. For white, the RGB
bits are all 1; for black, they are all 0. Normal video is a white character on a black
background; the attribute byte is 0000 0111 = 7h. Reverse video is a black character
on a white background, so the attribute is 0111 0000 = 70h.
INT 10h
Even though we can display data by moving them directly into the active display
page, this is a very tedious way to control the screen. Instead we use the BIOS video
screen routines which is invoked by the INT 10h instructions; a video functions is
selected by putting a function number in the AH register.
Function 0:
Select Display Mode
Input: AH = 0
AL = mode number ( see table 7.1)
Output: none
Function 1:
Change Cursor Size
Input: AH = 1
CH = Starting scan line
CL = ending scan line
Output: none
Microprocessor Lab
Prepared by: Eng. Ezya Khader 39
In text mode, the cursor is displayed as a small dot array at a screen position (in
graphics mode, there is no cursor). For the MDA and EGA, the dot array has 14 rows
(0 13) and for the CGA, there are 8 rows (0 7). Normally only rows 6 and 7 are lit
for the CGA cursor, and rows 11 and 12 for the MDA and EGA cursor. To change the
cursor size, put the starting and ending numbers of the rows to be lit in CH and CL,
respectively.
Function 2:
Move Cursor
Input: AH = 2
DH = new cursor row (0 24)
DL = new cursor column. 0 79 for 8025 display, 0 39 for 4025 display.
BH = Page number
Output: none
Function 3:
Get Cursor Position and Size
Input: AH = 3
BH = page number
Output: DH = cursor row
DL = cursor column
CH = cursor starting scan line
CL = cursor ending scan line
Function 5:
Select Active Display Page
Input: AH = 5
AL = active display page
0 7 for modes 0,1
0 3 for CGA modes 2,3
0 7 for EGA, MCGA, VGA modes 2,3
0 7 for EGA, VGA mode 7
Output: none
Function 6:
Scroll the Screen or a Window UP
Input: AH = 6
AL = number of lines to scroll (Al = 0 means scroll the whole screen or window)
BH = attribute for blank lines
CH,CL = row, column for upper left corner of window (see table 7.3)
DH,DL = row, column for lower right corner of window (see table 7.3)
Output: none
Function 7:
Scroll the screen or a Window Down
Input: AH = 7
AL = number of lines to scroll (Al = 0 means scroll the whole screen or window)
BH = attribute for blank lines
CH,CL = row, column for upper left corner of window (see table 5.3)
DH,DL = row, column for lower right corner of window (see table 5.3)
Output: none
Microprocessor Lab
Prepared by: Eng. Ezya Khader 40
Function 8:
Read Character at the Cursor
Input: AH= 8
BH = page number
Output: AH = attribute of character
AL = ASCII code of character
Function 9:
Display Character at the Cursor with Any Attribute
Input: AH = 9
BH = page number
AL = ASCII code of character
CX = number of times to write character
BL = attribute of character
output: none
Function Ah:
Display Character at the Cursor with Current Attribute
Input: AH = 0Ah
BH = page number
AL = ASCII code of character
CX = number of times to write character
Output: none
Function Eh:
Display Character and Advance Cursor
Input: AH = 0Eh
AL = ASCII code of character
BH = page number
BL = foreground color (graphics mode only)
Output: none
This is the BIOS function used by INT 21h, function 2, to display a character. The
control characters bell (07h), backspace (08h), line feed (0Ah), and carriage return
(0Dh) cause control functions to be performed.
Function Fh:
Get Video Mode
Input: AH = 0Fh
Output: AH = number of screen columns
AL = display mode (see table 5.1)
BH = active display page
This function can be used with function 5 to switch between pages being displayed.
Microprocessor Lab
Prepared by: Eng. Ezya Khader 41
Graphics Modes
In graphics mode operation, the screen display is divided into columns and rows; and
each screen position, given by a column number and row number, is called a pixel
(picture element), the number of columns and rows gives the resolution of the
graphics mode. The columns are numbered from left to right starting with 0, and rows
are numbered from top to bottom starting with 0, depending on mapping of rows and
columns into the scan lines and dot positions, a pixel may contain one or more dots.
For example, in the low-resolution mode of the CGA, there are 160 columns by 100
rows, but the CGA generates 320 dots and 200 scan lines; so a pixel is formed of 22
set of dots. A graphics mode is called APA (all points addressable) if it maps a pixel
into a single dot. Table 5.4 shows the APA graphics modes of the CGA, EGA, and
VGA. To maintain compatibility, the EGA is designed to display all CGA modes and
the VGA can display all the EGA modes.
CGA Graphics
The CGA has three graphics resolutions: a low resolution of 160100, a medium
resolution of 320200, and a high resolution of 640200. only the medium-resolution
and high-resolution modes are supported by the BIOS INT 10h routine.
Medium-Resolution Mode
The CGA can display 16 colors; Table 5.5 shows the 16 colors of the CGA. In
medium resolution, four colors can be displayed at one time. This is due to the limited
size of the display memory. To allow different four-color combinations, the CGA in
medium resolution mode uses two palettes; a palette is a set of colors that can be
displayed at the same time. Each palette contains three fixed colors plus a
background color that can be chosen from any of the standard 16 colors. The
background color is the default color of all pixels. Thus, a screen with the background
color would show up if no data have been written. Table 5.6 shows the two palettes.
Microprocessor Lab
Prepared by: Eng. Ezya Khader 42
Table 5.5: Sixteen standard CGA colors
IRGB Color
0000 Black
0001 Blue
0010 Green
0011 Cyan
0100 Red
0101 Magenta
0110 Brown
0111 White
1000 Gray
1001 Light Blue
1010 Light Green
1011 Light Cyan
1100 Light Red
1101 Light Magenta
1110 Yellow
1111 Intense White
The default palette is palette 0, but program can select either palette for display. A
pixel value (0 3) identifies the color in the current selected palette; if we change the
display palette, all the pixels change color. INT 10h, function 0Bh, can be used to
select a palette or a background color.
Function 0Bh:
Select Palette or Background Color
Microprocessor Lab
Prepared by: Eng. Ezya Khader 43
Function 0Ch:
Write Graphics Pixel
Input: AH = 0Ch
AL = pixel value
BH = page (for the CGA, this value is ignored)
CX = column number
DX = row number
Output: none
Function 0Dh:
Read Graphics Pixel
Input: AH = 0Dh
BH = page (for the CGA, this value is ignored)
CX = column number
DX = row number
Output: AL = pixel value
Examples:
Below are two examples that use BIOS interrupts:
a) Clearing the screen:
MOV AX, 0600H ; scroll entire screen
MOV BH, 07 ; normal attribute
MOV CX, 0000 ; start at 00,00
MOV DX, 184FH ; end at 18, 4F
INT 10H ; invoke the interrupt
Microprocessor Lab
Prepared by: Eng. Ezya Khader 44
Hashemite University
Faculty of Engineering and Technology
Computer Engineering Department
Experiment 6
DOS Interrupts Programming
1.1 Objectives:
2. To become familiar with the DOS interrupts of the 8086/88 processor.
1.3 Equipments:
Personal computer with MASM software installed on it.
MTS-8088 kit.
INT 21h
INT 21h may be used to invoke a large number of DOS functions, a particular
function is requested by placing a function number in the AH register and invoking
INT 21h. Here we are interested in the following functions.
Function 1:
Single Key Input
Input: AH = 1
Output: AL = ASCII code if character Key is pressed
= 0 if non character key is pressed
Microprocessor Lab
Prepared by: Eng. Ezya Khader 45
The processor will wait for the user to hit a key if necessary. If a character key is
pressed, AL gets its ASCII code; the character is also displayed on the screen.
Because INT 21h doesn't prompt the user for input, he might not know whether the
computer is waiting for input or is occupied by some computation. The next function
can be used to generate an input prompt.
Function 2:
Display a character or execute a control function
Input: AH = 2
DL = ASCII code of the display character or control character
Output: AL = ASCII code of the display character or control character
Table 5.7 shows some of the control characters and their corresponding control
functions.
In case the programmer wants to prompt user for input by a meaningful message
function 9 could be used.
Function 9:
Display a String
Input: AH = 9
DX = offset address of string.
The string must end with a '$' character.
Microprocessor Lab
Prepared by: Eng. Ezya Khader 46
To set the system time or date the following functions could be used.
Function 2Dh
Set System Time
Input: AH = 2Dh
CH = hours (0 23)
CL = minutes ( 0 59)
DH = seconds (0 59)
DL = hundredths (0 100)
Output: AL = 00 if the time is valid
FFh if the time is invalid
Function 2Bh
Set System Date
Input: AH = 2Bh
CX = year (1980 2099)
DH = month (1 12)
DL = day (1 31)
Output: AL = 00 if the date is valid
FFh if the date is invalid
File Handle
When a file is opened or created in a program, DOS assign it a unique number called
the file handle. This number is used to identify the file, so program must save it.
There are five predefined file handles. They are:
0 Keyboard
1 Screen
2 Error output screen
3 Auxiliary device
4 Printer
File Errors
There is many opportunities for errors in INT 21h file handling; DOS identifies each
error by a code number. In the functions described here, if an error occurred then CF
is set and the code number appears in AX. Table 5.8 shows the most common file
handling errors.
Microprocessor Lab
Prepared by: Eng. Ezya Khader 47
F Invalid drive specified
10 Attempt to remove current directory
11 Not the same device
12 No more files to be found
Microprocessor Lab
Prepared by: Eng. Ezya Khader 48
Reading a file
The following function reads a specified number of bytes from a file and stores them
in memory.
Function 3Fh
Read a File
Input: AH = 3Fh
BX = file handle
CX = number of bytes to read
DS:DX = memory buffer address
Output: AX = number of bytes actually read
If AX = 0 or AX < CX, end of file encountered
If CF = 1, error code in AX (5, 6)
Writing a file
Function 40h writes a specified number of bytes to a file or device.
Function 40h
Write File
Input: AH = 40h
BX = file handle
CX = number of bytes to write
DS:DX = data address
Output: AX = bytes written. If AX < CX, error (full disk)
If CF = 1, error code in AX (5, 6)
Examples:
Below are two examples that use DOS interrupts.
a) display the message defined with variable DATA_ASC DB the earth is but
one country,$
MOV AH, 09 ; option 9 to display string of data
MOV DX, OFFSET DATA_ASC ; DX= offset address of data
INT 21H ; invoke the interrupt
Microprocessor Lab
Prepared by: Eng. Ezya Khader 49
Hashemite University
Faculty of Engineering and Technology
Computer Engineering Department
Experiment 7
Parallel Data Input/Output
1.1 Objectives:
1) To understand the decoding circuit that is implemented for the 8088 input and
output subsystems.
2) To know how to download assembly program from PC to the MTS-8088 kit,
using serial communication port RS232.
3) Programming the 8255 Programmable Peripheral Interface.
4) Program simple traffic light on the kit.
1.3 Equipments:
Personal computer with MASM software installed on it.
MTS-8088 kit.
EDS-8809.
50 pins IDC flat cable
RS232 serial cable.
Microprocessor Lab
Prepared by: Eng. Ezya Khader 50
Figure 1 (8-port Output circuit for the 8088 microprocessor)
FF10 H Port A
FF11 H Port B
FF12 H Port C
FF13 H Control Register
Table 1
Figure2: shows the pin layout of the programmable 8255 interface.
Figure2
Microprocessor Lab
Prepared by: Eng. Ezya Khader 51
To Write a Program:
Example:
If we connect 7-segment display to Port A (Output), 8 Push buttons to Port B (Input),
and 8 LEDs to Port C (Output), the value of Control Register should be 10000010B=
82H.
MOV DX, .. ; put the address of Control Register
MOV AL, ; put the value of Control Byte. It is 82h in the example above.
OUT DX, AL ; after executing OUT instruction, the Control Register is initialized.
Microprocessor Lab
Prepared by: Eng. Ezya Khader 52
Hashemite University
Faculty of Engineering and Technology
Computer Engineering Department
Experiment 8
I/O Applications: Stop Watch & Dynamic Display
1.1 Objectives:
1. Implement wider applications on the I/O ports of the Microprocessor.
2. Understand how to deal with a 7-segment display using PPI 8255.
3. Understand the display principle of dot matrix LEDs module of EDS-8809.
4. Understand the principle of data's shift.
1.3 Equipments:
Personal computer with MASM software installed on it.
MTS-8088 kit.
EDS-8809.
50 pins IDC flat cable
RS232 serial cable.
Microprocessor Lab
Prepared by: Eng. Ezya Khader 53
Figure 1: "Connection of 7-segments display"
To avoid displaying the consecutive hexadecimal digits too quickly, an appropriate
delay period needs to be inserted before sending the subsequent digit to the 7-segment
display. This can be accomplished by writing a time delay loop as follows:
MOV CX, 0A000H
LOOP $
Microprocessor Lab
Prepared by: Eng. Ezya Khader 54
7.4 How to output the data?
First we have to change the dip switch to be enabled to output data to
the dot matrix display, as shown in Figure2.
Microprocessor Lab
Prepared by: Eng. Ezya Khader 55
Hashemite University
Faculty of Engineering and Technology
Computer Engineering Department
Experiment 9
LCD & Keypad Interrupts
1.1 Objectives:
To study and practice the use of various types of software interrupts.
To use interrupts to write a simple and real application.
1.3 Overview
MTS-8088 provides several I/O drivers to handle I/O devices; these programs can
be called by application programs to perform I/O. The I/O drivers provides by the
EGC-8088 are accessed through interrupt requests.
The functions provided by each I/O driver and their parameters are described in detail
in the following sections.
Microprocessor Lab
Prepared by: Eng. Ezya Khader 56
AH=0: Read a character from the key board.
The driver only returns the scan code of the keystroke and its ASCII code to the
calling program when a key is pressed.
Microprocessor Lab
Prepared by: Eng. Ezya Khader 57
Appendix A
MASM 6.11 Installation Notes
To install MASM611 on our machine you have to follow the following steps:
o Choose MASM 6.1 folder.
o Go to setup directory and then run Setup.exe. Now the MASM 6.11
installation begins. And a screen like the one in Figure A.1 will appears.
Microprocessor Lab
Prepared by: Eng. Ezya Khader 58
Figure A.2: MASM6.11 setup.exe screen.
c:\masm611\bin
c:\masm611\include
c:\masm611\init
c:\masm611\help
c:\masm611\samples
Microprocessor Lab
Prepared by: Eng. Ezya Khader 59
Appendix B
Communicating with MTS-8088 KIT
Objective
This Appendix will help you to know how to communicate with the 8088
MTS kit, how to download assembly programs from PC to KIT and how to upload it.
Introduction
Although the BGC-8088 MICROENGINEER is small and simple device, it
contains all the hardware elements of a computer. In particular, it provides RS-232
interface hardware circuit and software driver for communication with the outside
world. Here we present 2 built-in commands for communication with the BGC-8088.
Procedure
Step 1: Prepare the assembly code
a) Write the assembly code in a text document then save it as .ASM file.
b) Assemble the source code using MASM/L command as follow:
i) Suppose we have Try.asm file saved in the following directory:
(D:\interface lab).
ii) Open DOS from Run cmd, and then go to the path D:\interface lab.
(See figure 1).
iii) Use MASM/L instruction to assemble the source file Try.ASM into a
machine language object file Try.OBJ
Microprocessor Lab
Prepared by: Eng. Ezya Khader 60
c) LINK program with MASM version 6.11 take one or more object files and
combine them into a single executable file (.EXE file). (See figure 2)
d) Now convert the Execution file Try.EXE into binary file Try.BIN.
(See figure 3)
a) You need to connect a serial wire with COM1 or COM2 ports of the PC and
the other end with the MTS-8088 KIT.
b) Now power ON the KIT.
c) Now open the data transfer program. (See figure 4).
Figure 4
d) The welcome Screen will
appear for a small period.
Microprocessor Lab
Prepared by: Eng. Ezya Khader 61
e) Then the settings screen will appear, you have to choose the type of the kit and
the COM port you are connected with. (See figure 5)
Figure 5: Settings
f) Now the following screen will appear to choose the .BIN file which you want
to download it. (see figure 6)
Figure 6
DOWNLOAD....
h) Now press the Download button in the other side (PC), the transmition is
started, after completion the total number of bytes transferred is displayed on
the LCD of the KIT and on the PC. (see figure 7)
Microprocessor Lab
Prepared by: Eng. Ezya Khader 62
Figure 7
This interface allows the user to program in assembly on the PC, and to test
that program easily on the BGC-8088 MICROENGINEER, this is much easier
than using the A command to write programs for the BGC-8088 Kit.
Microprocessor Lab
Prepared by: Eng. Ezya Khader 63