0% found this document useful (0 votes)
6 views57 pages

II-i It MPMC Unit-1

The document provides an overview of the 8086 microprocessor, including its internal architecture, assembly language programming, and types of computers. It details the components of the microprocessor, such as the Execution Unit and Bus Interface Unit, as well as addressing modes and the evolution of the Intel 80x86 family. Additionally, it includes problems related to number systems and logic circuits.

Uploaded by

venkysmiley341
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views57 pages

II-i It MPMC Unit-1

The document provides an overview of the 8086 microprocessor, including its internal architecture, assembly language programming, and types of computers. It details the components of the microprocessor, such as the Execution Unit and Bus Interface Unit, as well as addressing modes and the evolution of the Intel 80x86 family. Additionally, it includes problems related to number systems and logic circuits.

Uploaded by

venkysmiley341
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 57

10/16/2024

Unit--1
Unit
MPMC

SYLLABUS
UNIT - I
Introduction to 8086: The 8086 Microprocessor family-overview; 8086
internal architecture: the execution unit, the BIU;
8086 Family Assembly Language Programming: Program development
steps, constructing the machine codes for 8086 instructions, writing
program for use with an assembler, assembly language program
development tools.

1
10/16/2024

Microprocessor and Microcontroller


Microprocessor:
• A microprocessor is a multipurpose, programmable, clock-driven, register-
based electronic device that reads binary instructions from a storage device
called memory accepts binary data as input and processes data according to
instructions, and provides result as output.
Microcontroller:
• A microcontroller (sometimes abbreviated μC, uC or MCU) is a small
computer on a single integrated circuit containing a processor core, memory,
and programmable input/output peripherals.
or
• CPUs with integrated memory or peripheral interfaces

Number System
Problems
• 22710 = Binary Value?
• (10110.11) = Decimal Value?
• 22710 = Hexa Decimal Value?
• Decimal Value for BCD Code 010100101001 ?

2
10/16/2024

Number System
Problems
• 22710 = (11100011)2
• (10110.11) = (22.75)10
• 22710 = (E3)16
• Decimal Value for BCD Code 0101 0010 1001 = 529

Logic Circuits

3
10/16/2024

Logic Circuits

Logic Circuits

4
10/16/2024

Logic Circuits

Logic Circuits

5
10/16/2024

Logic Circuits

Types of Computers
• Main Frame Computers
• Mini Computers
• Micro Computers

6
10/16/2024

Types of Computers-
Computers- Main Frame Computers
• Mainframe computers may fill an entire room.
• They are designed to work at very high
speeds with large data words, typically 64
bits or greater, and they have massive
amounts of memory.
• Computers of this type are used for military
defense control, for business data processing
(in an insurance company, for example), and
for creating computer graphics displays for
science fiction movies.
• Examples of this type of computer are the
IBM 4381, the Honeywell DPS8, and the Cray
Y-MP1832. The fastest and most powerful
mainframes are called supercomputers

Types of Computers-
Computers- Mini Computers
• Scaled-down versions of mainframe
computers are often called minicomputers.
• The main unit of a minicomputer usually fits in
a single rack or box.
• A minicomputer runs more slowly, works
directly with smaller data words often 32-bit
words), and does not have as much memory as
a mainframe.
• Computers of this type are used for business
data processing, industrial control (for an oil
refinery, for example), and scientific research.
• Examples of this type of computer are the
Digital Equipment Corporation VAX 6360 and
the Data General MV/8000l1.

7
10/16/2024

Types of Computers-
Computers- Micro Computers
• As the name implies, microcomputers are
small computers.
• They range from small controllers that
work directly with 4-bit words and can
address a few thousand bytes of memory
to larger units that work directly with 32-
bit words and can address billions of bytes
of memory.
• One distinguishing feature of a
microcomputer is that the CPU is usually a
single integrated circuit called a
microprocessor.
• Examples of micro computers are the Intel
8o51 single-chip controller: the SDK-86, a
single-board computer design kit, the IBM
Personal Computer (PC) and the Apple
Macintosh computer.

Block Diagram of Microcomputer

8
10/16/2024

Block Diagram of Microcomputer


• Memory
• Input / Output
• CPU
• Address Bus
• Data Bus
• Control Bus

Evolution of Microprocessor Family

9
10/16/2024

Evolution of Intel 80x 86 Microprocessor Family

Specifications of Intel 8086 Microprocessor


1. It is 16-bit microprocessor
2. It has a 16-bit data bus, so it can read data from or write data to memory and
ports either 16-bit or 8-bit at a time.
3. It has 20 bit address bus and can access up to 220 memory locations (1 MB).
4. It can support up to 64K I/O ports
5. It provides 14, 16-bit registers
6. It has multiplexed address and data bus AD0-AD15 & A16-A19
7. It requires single phase clock with 33% duty cycle to provide internal timing.
8.Pre-fetches up to 6 instruction bytes from memory and queues them in order
to speed up the processing.
9. 8086 supports 2 modes of operation
a. Minimum mode
b. Maximum mode

10
10/16/2024

8086 Internal Architecture


• As shown by the block diagram in Figure 2-7. the 8086 CPU Is
divided into two independent functional parts,
1.Bus Interface Unit (BIU) and
2.Execution unit (EU)

8086
Internal
Architecture

11
10/16/2024

8086 Internal Architecture


The BIU functions in such a way that it:
• The BIU sends out addresses, fetches instructions from memory,
• reads data from ports and memory, and
• writes data to ports and memory.
• In other words, the BIU handles all transfers of data and addresses
on the buses for the execution unit.

8086 Internal Architecture


The Execution Unit (EU): The execution unit of the 8086 tells the BIU where to fetch
instructions or data from, decodes instructions, and executes instructions.
The main functions of EU are:
o Decoding of Instructions
o Execution of instructions
• Steps
EU extracts instructions from top of queue in BIU
Decode the instructions
Generates operands if necessary
Passes operands to BIU & requests it to perform read or write bus cycles to
memory or I/O
Perform the operation specified by the instruction on operands

12
10/16/2024

8086 Internal Architecture


Execution Unit consists
• CONTROL CIRCUITRY, INSTRUCTION DECODER, AND ALU
• FLAG REGISTER
• GENERAL-PURPOSE REGISTERS
BIU consists
• THE QUEUE
• SEGMENT REGISTERS
• INSTRUCTION POINTER
• POINTERS AND INDEX REGISTERS

8086 Internal Architecture-


Architecture- Execution Unit
CONTROL CIRCUITRY, INSTRUCTION DECODER, AND ALU

• Control Circuitry which directs internal operations.


• A decoder in the EU translates instructions fetched from memory into
a series of actions which the EU carries out.
• The EU has a 16-bit arithmetic logic unit which can add, subtract,
AND, OR, XOR, increment, decrement, complement, or shift binary
numbers.

13
10/16/2024

8086 Internal Architecture-


Architecture- Execution Unit
FLAG REGISTER
• A flag is a flip-flop which indicates some condition produced by the
execution of an instruction or controls certain operations of the EU.
• A 16-bit flag register in the EU contains nine active flags.
• Figure 2-8 shows the location of the nine flags in the flag register.
• Six of the nine flags are used to indicate some condition produced
by an Instruction. For example, a flip-flop called the carry flag will be
set to a I if the addition of two 16- bit binary numbers produces a
carry out of the most significant bit position. If no carry out of the
MSB is produced by the addition, then the carry flag will be a 0.
• The EU thus effectively-runs up a "flag" to tell you that a carry was
produced.

8086 Internal Architecture-


Architecture- Execution Unit
FLAG REGISTER

14
10/16/2024

8086 Internal Architecture-


Architecture- Execution Unit
FLAG REGISTER
Control Flags
• Direction Flag (DF): decides on the direction of string operations , it can vary from forwards to
backwards.
• Trap Flag (TF): may help in debugging one instruction at a time by turning on single step mode.
• Interrupt Flag (IF): that can turn ON or OFF maskable interrupts.
Condition Flags
• Carry Flag(CF): shows whether there was a carry on the most important bit (MSB) during
mathematics operations.
• Parity Flag (PF): shows the parity (even/odd) of the least significant byte of the result,
• Auxiliary carry flag (AF): Auxiliary carry flag indicates a carry between bits 3 and 4 during
mathematics operations.
• Zeroflag (ZF): tells us whether or not our answer has been zeroed.
• Sign Flag (SF): Shows the outcome’s polarity. In this case, 1 means a negative return and 0 points to
a positive return.
• Overflow Flag (OF): This bit is raised when the result of a signed operation goes beyond limits of
the data type.

8086 Internal Architecture-


Architecture- Execution Unit
GENERAL PURPOSE REGISTERS
• EU has eight general purpose registers, labeled AH, AL, BH, BL, CH ,
CL, DH and DL. These registers can be used individually for temporary
storage of 8-bit data. The AL register is also called the accumulator. It
has some features that the other general-purpose registers do not
have.
• Certain pairs of these general purpose registers can be used together
to store 16-bit data words. The acceptable register pairs are AH and
AL. BH and BL. CH and CL, and DH and DL. The AH—AL pair is referred
to as the AX register, the BH—BL pair is referred to as the BX register,
the CH—CL pairs referred to as the CX register, and the DH—DL pair is
referred to as the DX register.

15
10/16/2024

8086 Internal Architecture-


Architecture- Execution Unit
GENERAL PURPOSE REGISTERS

• The four general purpose registers are the AX, BX, CX, and DX
registers.
• AX - accumulator, and preferred for most operations.
• BX - base register, typically used to hold the address of a procedure or
variable.
• CX - count register, typically used for looping.
• DX - data register, typically used for multiplication and division.

8086 Internal Architecture-


Architecture- BIU
THE QUEUE
• The BIU stores the prefetched bytes in a first-In—first-out register set called a
queue.
• When the EU is ready for its next Instruction, it simply reads the instruction byte(s)
for the instruction from the queue in the BIU.
• This is much faster than sending out an address to the system memory and waiting
for memory to send back the next instruction byte or bytes.
• Except in the cases of JMP and CALL instructions, where the queue must be
dumped and then reloaded starting from a new address, this prefetch-and-queue
scheme greatly speeds up processing.
• Fetching the next instruction while the current instruction executes is called
pipelining.

16
10/16/2024

8086 Internal Architecture-


Architecture- BIU
SEGMENT REGISTERS
• There are 4 segment registers. They are:
o Code Segment Register(CS)
o Data Segment Register(DS)
o Extra Segment Register(ES)
o Stack Segment Register(SS

8086 Internal Architecture-


Architecture- BIU
SEGMENT REGISTERS
• The 8086 architecture uses the concept of segmented memory. 8086 able to address a memory
capacity of 1 megabyte and it is byte organized. This 1 megabyte memory is divided into 16 logical
segments.
• Each segment contains 64 kbytes of memory.
• Code segment register (CS): is used for addressing memory location in the code segment of the
memory, where the executable program is stored.
• Data segment register (DS): points to the data segment of the memory where the data is stored.
• Extra Segment Register (ES) : also refers to a segment in the memory which is another data
segment in the memory.
• Stack Segment Register (SS): is used for addressing stack segment of the memory. The stack
segment is that segment of memory which is used to store stack data.
• While addressing any location in the memory bank, the physical address is calculated from two
parts:
Physical address= segment address + offset address
• The first is segment address, the segment registers contain 16-bit segment base addresses, related
to different segment.
• The second part is the offset value in that segment.

17
10/16/2024

18
10/16/2024

Physical Address Calculation

8086 Internal Architecture-


Architecture- BIU
Pointers and Index Registers:
• The index and pointer registers are given below:
o IP—Instruction pointer-store memory location of next instruction to be executed
o BP—Base pointer
o SP—Stack pointer
o SI—Source index
o DI—Destination index
• The pointers registers contain offset within the particular segments.
o The pointer register IP contains offset within the code segment.
o The pointer register BP contains offset within the data segment.
o Thee pointer register SP contains offset within the stack segment.
• The index registers are used as general purpose registers as well as for offset storage in case of
indexed, base indexed and relative base indexed addressing modes.
• The register SI is used to store the offset of source data in data segment.
• The register DI is used to store the offset of destination in data or extra segment.
• The index registers are particularly useful for string manipulation.

19
10/16/2024

Addressing Modes
• Addressing mode indicates a way of locating data or operands.
• The addressing modes describe the types of operands and the way they are
accessed for executing an instruction.
• According to the flow of instruction execution, the instructions may be
categorized as
i) Sequential control flow instructions and
ii) Control transfer instructions
• Sequential control flow instructions are the instructions, which after execution,
transfer control to the next instruction appearing immediately after it (in the
sequence) in the program. For example, the arithmetic, logic, data transfer and
processor control instructions are sequential control flow instructions.
• The control transfer instructions, on the other hand, transfer control to some
predefined address or the address somehow specified in the instruction, after
their execution. For example, INT, CALL, RET and JUMP instructions fall under this
category.

Addressing Modes
• The addressing modes for sequential control transfer instructions are:
1.Immediate
2. Direct
3. Register
4. Register Indirect
5. Indexed
6. Register Relative
7. Based Indexed
8. Relative Based Indexed

20
10/16/2024

Addressing Modes
1. Immediate: In this type of addressing, immediate data is a part of
instruction and appears in the form of successive byte or bytes.
Ex: MOV AX, 0005H
In the above example, 0005H is the immediate data. The immediate data
may be 8-bit or 16-bit in size.
2. Direct: In the direct addressing mode a 16-bit memory address (offset) is
directly specified in the instruction as a part of it.
Ex: MOV AX, [5000H]
Here, data resides in a memory location in the data segment, whose effective
address may be completed using 5000H as the offset address and content of
DS as segment address. The effective address here, is 10H * DS + 5000H.

Addressing Modes
3. Register: In register addressing mode, the data is stored in a register and is
referred using the particular register. All the registers, except IP, may be used
in this mode.
Ex: MOV BX, AX
4. Register Indirect: Sometimes, the address of the memory location, which
contains data or operand, is determined in an indirect way, using the offset
register. This mode of addressing is known as register indirect mode. In this
addressing mode, the offset address of data is in either BX or SI or DI register.
The default segment is either DS or ES.
Ex: MOV AX, [BX]
Here, data is present in a memory location in DS whose offset address is in BX.
The effective address of the data is given as 10H * DS+[BX].

21
10/16/2024

Addressing Modes
5. Indexed: In this addressing mode, offset of the operand is stored in one of
the index registers. DS and ES are the default segments for index registers, SI
and DI respectively. This is a special case of register indirect addressing mode.
Ex: MOV AX, [SI]
Here, data is available at an offset address stored in SI in DS. The effective
address, in this case, is computed as 10*DS+[SI].
6. Register Relative: In this addressing mode, the data is available at an
effective address formed by adding an 8-bit or 16-bit displacement with the
content of any one of the registers BX, BP, SI and DI in the default (either DS
or ES) segment.
Ex: MOV AX, 50H[BX]
Here, the effective address is given as 10H *DS+50H+[BX]

Addressing Modes
7. Based Indexed: The effective address of data is formed, in this addressing
mode, by adding content of a base register (any one of BX or BP) to the
content of an index register (any one of SI or DI). The default segment register
may be ES or DS.
Ex: MOV AX, [BX][SI]
Here, BX is the base register and SI is the index register the effective
address is computed as 10H * DS + [BX] + [SI].
8. Relative Based Indexed: The effective address is formed by adding an 8 or
16-bit displacement with the sum of the contents of any one of the base
register (BX or BP) and any one of the index register, in a default segment.
Ex: MOV AX, 50H [BX] [SI]
Here, 50H is an immediate displacement, BX is base register and SI is an index
register the effective address of data is computed as
10H * DS + [BX] + [SI] + 50H

22
10/16/2024

Addressing Modes
• For control transfer instructions, the addressing modes depend upon whether the
destination is within the same segment or different one. It also depends upon the
method of passing the destination address to the processor.
• Basically, there are two addressing modes for the control transfer instructions,
intersegment addressing and intrasegment addressing modes.
• If the location to which the control is to be transferred lies in a different segment
other than the current one, the mode is called intersegment mode.
• If the destination location lies in the same segment, the mode is called
intrasegment mode.

8086 Family Assembly Language Programming - Introduction


• Program Development Steps
 Defining the Problem
 Representing program operations
 Finding the right instructions
 Writing a program
• Constructing the machine codes for 8086 instructions
 Instruction templates
 MOV instruction coding format
 Tips for hand coding
• Writing programs for the use with assemblers
 Program format
 Assembler Directives
 Types of numbers used in data statements
• Assembly Language Program development Tools
 Assembler, Linker, Locator, Debugger, Emulator

23
10/16/2024

8086 Family Assembly Language Programming - Introduction


• To run a program, a microcomputer must have the program stored in binary form
in successive memory locations, as shown in Figure 2-12.
• There are three language levels that can be used to write a program for a
microcomputer.
Machine Language
Assembly Language
High-level Languages
• This binary form of the program is referred to as machine language because it is
the form required by the machine.

8086 Family Assembly Language Programming - Introduction


• Assembly language uses two-, three-, or four-letter mnemonics to
represent each instruction type.
• A mnemonic is just a device to help you remember something.
• The letters in an assembly language mnemonic are usually initials or a
shortened form of the English word(s) for the operation performed by the
instruction.
• For example, the mnemonic for subtract is SUB, the mnemonic for Exclusive
OR is XOR. and the mnemonic for the instruction to copy data from one
location to another is MOV.
• Assembly language statements are usually written in a standard form that
has four fields.

24
10/16/2024

8086 Family Assembly Language Programming - Introduction


• The first field in an assembly language statement is the label field.
• A label is a symbol or group of symbols used to represent an address which
is not specifically known at the time the statement is written.
• Labels are usually followed by a colon.
• Labels are not required in a statement. They are just inserted where they are
needed.
• The opcode field of the instruction contains the mnemonic for the
Instruction to be performed. Instruction mnemonics are sometimes called
operation codes, or opcodes.

8086 Family Assembly Language Programming - Introduction


• The operand field of the statement contains the data, the memory address,
the port address, or the name of the register on which the instruction is to
be performed.
• Operand is just another name for the data item(s) acted on by an
instruction. In the example instruction in Figure 2-12, there are two
operands. AL and 07H, specified in the operand field.
• The final field In an assembly language statement such as that in Figure 2-12
is the comment field, which starts with a semicolon.
• Comments do not become part of the machine language program; but they
are very important.
• You write comments in a program to remind you of the function that an
instruction or group of instructions performs in the program.

25
10/16/2024

PROGRAM DEVELOPMENT STEPS


• Defining the Problem: As you think about the problem, it is a good Idea to
write down exactly what you want the program to do and the order in
which you want the program to do it.
• Representing Program Operations- FLOWCHARTS, STRUCTURED
PROGRAMMING AND PSEUDO CODE, STANDARD PROGRAMMING
STRUCTURES
• Finding the Right Instruction- DATA TRANSFER INSTRUCTIONS,
ARITHMETIC INSTRUCTIONS, BIT MANIPULATION INSTRUCTIONS, STRING
INSTRUCTIONS, PROGRAM EXECUTION TRANSFER INSTRUCTIONS,
PROCESSOR CONTROL INSTRUCTIONS
• Writing a Program- INITIALIZATION INSTRUCTIONS, INITIALIZATION LIST, A
STANDARD PROGRAM FORMAT, DOCUMENTATION

8086 Family Assembly Language Programming - Introduction


• When you write a computer program, It is a good idea to start by
developing a detailed plan or outline for the entire program.
• A good outline helps you to break down a large and seemingly
overwhelming programming job Into small modules which can easily be
written, tested, and debugged.
• The more time you spend organizing your programs, the less time it will
take you to write and debug them.

26
10/16/2024

PROGRAM DEVELOPMENT STEPS


• Representing Program Operations:
• The formula or sequence of operations used to solve a programming
problem is often called the algorithm of the program.
• There are two ways of representing algorithms:-
Flowchart
Structured programming and pseudo code

PROGRAM DEVELOPMENT STEPS


Representing Program Operations: Flow Chart
• Flowchart : It uses graphical shapes to represent different types of
programming operations.

• Flow chart symbols

A racetrack- or circular shaped symbol labeled START Is used to indicate the beginning of
the program.

27
10/16/2024

PROGRAM DEVELOPMENT STEPS


Representing Program Operations: Flow Chart
• A parallelogram is used to represent an input or an output operation.
• A rectangular box symbol is used to represent simple operations other than input
and output operations.
• A rectangular box with double lines at each end is often used to represent a
subroutine, Subprogram or procedure that will be written separately from the
main program. When a Set of operations must be done several times during a
program, it is usually more efficient to write the series of operations once as a
separate subprogram, then just call this subprogram each time it is needed.
• A diamond-shaped box is used In flowcharts to represent a decision point or
crossroad. Usually it indicates that some condition is to be checked at this point in
the program. lithe condition is found to be true, one set of actions is to be done: if
the Condition is found to be false, another set of actions is to be done.

PROGRAM DEVELOPMENT STEPS


Representing Program Operations: Flow Chart

• If a flowchart column gets to the bottom of the paper, but not all the
program has been represented, you can put a small circle with a letter in
it at the bottom of the column, You then start the next Column at the
top of the same paper with a small circle containing the same letter.
• If you need to continue a flowchart to another page. you can end the
flowchart on the first page with the five-sided off page connector
symbol containing a letter or number. You then start the flowchart on
the next page with an off-page connector symbol containing the same
letter or number.

28
10/16/2024

PROGRAM DEVELOPMENT STEPS


Representing Program Operations: Flow Chart

FIGURE 3-2 Flowchart for program to read in 24 data


samples from a port, Correct each value, and store
each in a memory location.

PROGRAM DEVELOPMENT STEPS


Representing Program Operations: Structured programming and pseudo code
• As the number of computers increased and the complexity of the programs
being written increased. In this case the compatibility of parts written by
different programmers became an important concern.
• Programs should be understandable to other programmers
• Two approaches top-down and bottom up approach
 Top-down: divide the program in to major modules and divide theses major modules
in to sub modules and so on.
 Bottom-up: each programmer writes the low level module code and hopes that all
pieces will eventually fit together.

29
10/16/2024

PROGRAM DEVELOPMENT STEPS


Representing Program Operations: Structured programming and pseudo code
• The development of standard programming methods for any desired program
operation could be represented by three basic types of operation.
• The first type of operation is sequence, which means simply doing a series of
actions.
• The second basic type of operation is decision or selection, which means choosing
between two alternative actions.
• The third basic type of operation is repetition or iteration, which means repeating
a series of actions until some condition is or is not present.
• On the basis of this observation, the suggestion was made that programmers use a
set of three to seven standard structures to represent all the operations in their
programs.
• Main structures are only three viz. IF-THEN-ELSE, SEQUENCE & WHILE-DO. The
others are IF-THEN, CASE & REPEAT-UNTIL.

PROGRAM DEVELOPMENT STEPS


Representing Program Operations: Structured programming and pseudo code
• Flowchart symbols to represent the commonly used structures so that you can
more easily visualize their operation.
• In actual program documentation, however, English-like statements called
pseudocode are used rather than the space-consuming flowchart symbols.
• Each structure has Only one entry point and one exit point.
• The output of one Structure is connected to the input of the next structure.
• Program execution then proceeds through a series of these structures.
• Any structure can be used within another.
• Any place that the term statement(s) appears in Figure 3-3, one of the other
structures could be substituted for it.
• The term statement(s) can also represent a subprogram or procedure that is
called to do a series of actions

30
10/16/2024

Standard Program Structures. (a) Sequence. (b) IF-THEN-ELSE.

Standard Program Structures. (c) IF-THEN. (d) CASE expressed as nested IF-THEN-ELSE

31
10/16/2024

Standard Program Structures. (e) case (f) WHILE-DO LOOP

Standard Program Structures. (g) REPEATE-UNTIL

32
10/16/2024

PROGRAM DEVELOPMENT STEPS


• Finding the Right Instruction- After you get the structure of a program
worked out and written down, the next step Is to determine the Instruction
statements required to do each part of the program.
• We list the 8086 instructions in functional groups with single-sentence
descriptions so that you can see the types of instructions
DATA TRANSFER INSTRUCTIONS,
ARITHMETIC INSTRUCTIONS,
BIT MANIPULATION INSTRUCTIONS,
STRING INSTRUCTIONS,
PROGRAM EXECUTION TRANSFER INSTRUCTIONS,
PROCESSOR CONTROL INSTRUCTIONS

PROGRAM DEVELOPMENT STEPS


• Finding the Right Instruction- DATA TRANSFER INSTRUCTIONS
General purpose byte or word transfer instructions:

33
10/16/2024

PROGRAM DEVELOPMENT STEPS


• Finding the Right Instruction- DATA TRANSFER INSTRUCTIONS
Simple input and output port transfer instructions:

Special address transfer instructions:

Flag transfer Instructions:

PROGRAM DEVELOPMENT STEPS


• Finding the Right Instruction- ARITHMETIC INSTRUCTIONS
ADDITION INSTRUCTIONS:

SUBTRACTION INSTRUCTIONS:

34
10/16/2024

PROGRAM DEVELOPMENT STEPS


• Finding the Right Instruction- ARITHMETIC INSTRUCTIONS

PROGRAM DEVELOPMENT STEPS


• Finding the Right Instruction- LOGICAL INSTRUCTIONS

35
10/16/2024

PROGRAM DEVELOPMENT STEPS


• Finding the Right Instruction- LOGICAL INSTRUCTIONS

PROGRAM DEVELOPMENT STEPS


• Finding the Right Instruction- STRING INSTRUCTIONS
• String is a group of bytes/words and their memory is always allocated in a
sequential order.

36
10/16/2024

PROGRAM DEVELOPMENT STEPS


• Finding the Right Instruction- PROGRAM EXECUTION TRANSFER INSTRUCTIONS (BRANCH AND
LOOP INSTRUCTIONS) These instructions are used to transfer/branch the instructions during an
execution.

PROGRAM DEVELOPMENT STEPS


• Finding the Right Instruction- PROGRAM EXECUTION TRANSFER
INSTRUCTIONS (BRANCH AND LOOP INSTRUCTIONS)

37
10/16/2024

PROGRAM DEVELOPMENT STEPS


• Finding the Right Instruction- PROCESSOR CONTROL INSTRUCTIONS:
• These instructions are used to control the processor action by setting/resetting the flag values.

PROGRAM DEVELOPMENT STEPS


• Finding the Right Instruction- ITERATION CONTROL INSTRUCTIONS:
• These instructions are used to execute the given instructions for number of times.

• INTERRUPT INSTRUCTIONS:
• These instructions are used to call the interrupt during program execution.

38
10/16/2024

PROGRAM DEVELOPMENT STEPS


Writing a Program-
INITIALIZATION INSTRUCTIONS: After finding the instructions, there are few instructions
that you need to determine before you actually write your program. The purpose of these
additional instructions is to initialize various parts of the system, such as segment
registers, flags, and programmable port devices. Segment registers, for example, must be
loaded with the upper 16 bits of the address in memory where you want the segment to
begin
INITIALIZATION LIST:

PROGRAM DEVELOPMENT STEPS


Writing a Program- A STANDARD PROGRAM FORMAT
• To help you write your programs In the correct format, assembly language coding
sheets such as that shown in Figure 3-4 are available.
• The ADDRESS column is used for the address or the offset of a code byte or data byte.
• The actual code bytes or data bytes are put in the DATA/CODE column.
• A label is a name which represents an address referred to in a Jump or call instruction:
labels are put in the LABELS column. A label is followed by a colon (:) if it is used by a
Jump or call Instruction in the same code segment.
• The MNEM column contains the opcode mnemonics for the instructions.
• The OPERAND(S) column contains the registers. memory locations, or data acted upon
by the instructions.
• A COMMENTS column gives you space to describe the function of the instruction for
future reference

39
10/16/2024

PROGRAM DEVELOPMENT STEPS


Writing a Program-
3.4 A STANDARD
PROGRAM FORMAT

PROGRAM DEVELOPMENT STEPS


Writing a Program- DOCUMENTATION
• In a previous section of this chapter. we stressed the point that you should do a lot of
thinking and carefully write down the algorithm for a program before you start writing
instruction statements.
• You should also document the program Itself so that its operation is clear to you and to
anyone else who needs to understand it.
• Each page of the program should contain the name of the program. the page number,
the name of the programmer, and perhaps a version number.
• Each program or procedure should have a heading block containing an abstract
describing what the program is supposed to do. which procedures it calls, which
registers it uses, which ports it uses, which flags it affects, the memory used, and any
other information which will make It easier for another programmer to Interface with
the program.
• Comments should be used generously to describe the specific Junction of an
instruction or group of instructions in this particular program. Comments should not be
just an expansion of the instruction mnemonic.

40
10/16/2024

CONSTRUCTING THE MACHINE CODES FOR 8086 INSTRUCTIONS


• It is useful to understand how the codes are constructed.
• If you have an 8086-based prototyping board such as the Intel SDK-86 available,
knowing how to hand code instructions will enable you to code, enter, and run simple
programs.
Instruction Templates
• There are 32 ways to specify the source of the operand in an instruction such as MOV
CX, source. The source of the operand can be any one of eight 16-bit registers.
• If CX is made the source rather than the destination, then there are 32 ways of
specifying the destination. Each of these 32 possible instructions requires a different
binary code.
• There are thus 64 different codes for MOV instructions using CX as a source or as a
destination.
• Large number of possible codes for the 8086 instructions which is impractical to list
them all In a simple table. Instead, we use a template for each basic instruction type
and fill in bits within this template to indicate the desired addressing mode, data type,
etc. in other words, we build up the instruction codes on a bit- by-bit basis.

CONSTRUCTING THE MACHINE CODES FOR 8086 INSTRUCTIONS


code for the IN AL, 05H instruction

41
10/16/2024

CONSTRUCTING THE MACHINE CODES FOR 8086 INSTRUCTIONS


• Note that two bytes are required for the instruction.
• The upper 7 bits of the first byte tell the 8086 that this is an input from a fixed port
instruction.
• The bit labeled W in the template is used to tell the 8086 whether it should input a
byte to AL or a word to AX.
• If you want the 8086 to input a byte from an 8-bit port to AL, then make the W bit a 0.
• If you want the 8086 to input a word from a 16-bit port to the AX register, then make
the W bit a 1.
• The 8-bit port address, 05H or 00000101 binary, is put in the second byte of the
instruction.
• When the program is loaded into memory to be run, the first instruction byte will be
put in one memory location, and the second instruction byte will be put in the next.
Figure 3-5 c shows this in hexadecimal form as E4H, 05H.

CONSTRUCTING THE MACHINE CODES FOR 8086 INSTRUCTIONS


Coding template for 8086 instructions which MOV data between registers or between a
register and a memory location.

The MOD bits are


used to indicate
whether the address
specification in the
instruction contains
a displacement.
The R/M code
indicates which
register(s)
Contain part(s) 01
the effective
address.

42
10/16/2024

CONSTRUCTING THE MACHINE CODES FOR 8086 INSTRUCTIONS


Figure 3-8 shows the MOD and R/M bit patterns for each of the 32 possible
addressing modes in two ways.
1. if the other operand in the Instruction is also one of the eight registers,
then put in 11 for the MOD bits in the instruction code, in the R/M bit
positions in the instruction code, put the 3-bit code for the other register.
2. If the other operand is a memory location, there are 24 ways of specifying
how the execution unit should compute the effective address of the
operand in memory.
The MOD bits are used to indicate whether the address specification .in the
instruction contains a displacement. The R/M code indicates which register(s)
contain part(s) of the effective address.

CONSTRUCTING THE MACHINE CODES FOR 8086 INSTRUCTIONS


3.If the effective address specified in the instruction contains a displacement
less than 256 along with a reference to the contents of a register, as in the
instruction MOV CX, 43H[BX], then code in MOD as 01 and choose the R/M
bits which correspond to the register(s) which contain the part(s) for the
effective address. For the instruction MOV CX, 43H[BX], MOD will be 01 and
R/M will be 111. Put the 8-bit value of the displacement in as the third byte
of the instruction.
4. If the expression for the effective address contains a displacement which is
too large to fit in 8 bits, as in the instruction MOV DX, 4527H[BX], then put in
10 for MOD and choose the R/M bits which correspond to the register(s)
which contain the part(s) for the effective address. For the instruction MOV
DX, 4527H[BX], the R/M bits are 111. The low byte of the displacement is put
in as a third byte of the instruction. The high byte of the displacement is put
in as a fourth byte of the instruction.

43
10/16/2024

CONSTRUCTING THE MACHINE CODES FOR 8086 INSTRUCTIONS

44
10/16/2024

CONSTRUCTING THE MACHINE CODES FOR 8086 INSTRUCTIONS

FIGURE 3-8 MOD and R/M bit patterns for 8086 instructions. The effective address (EA) produced by these addressing modes
will be added to the data segment base to form the physical address, except for those eases where BP is used as part of the
EA. In that case the EA will be added to the slack segment base to form the physical address. You can use a segment-override
prefix to indicate that you want the EA to be added to some other segment base.

45
10/16/2024

CONSTRUCTING THE MACHINE CODES FOR 8086 INSTRUCTIONS


EXAMPLES

MOV SP,BX

CONSTRUCTING THE MACHINE CODES FOR 8086 INSTRUCTIONS


EXAMPLES

MOV SP,BX Alternate form

46
10/16/2024

CONSTRUCTING THE MACHINE CODES FOR 8086 INSTRUCTIONS


EXAMPLES

MOV CL,[BX]

CONSTRUCTING THE MACHINE CODES FOR 8086 INSTRUCTIONS


EXAMPLES
MOV 43H[SI], DH.
DH.

47
10/16/2024

CONSTRUCTING THE MACHINE CODES FOR 8086 INSTRUCTIONS


EXAMPLES
MOV CX, [437AH]
[437AH]-- Direct Addressing

CONSTRUCTING THE MACHINE CODES FOR 8086 INSTRUCTIONS


EXAMPLES
• This instruction copies a byte from the DL register to a memory location.
• The effective address for the memory location is contained in the BX register.
• Normally an effective address in BX will be added to the data segment base in
DS to produce the physical memory address.
• In this instruction, the CS: in front of [BX] indicates that we want the BIU to add
the effective address to the code segment base in CS to produce the physical
address. The CS: is called a segment override prefix.
• When an instruction containing a segment override prefix is coded, an 8-bit
code for the segment override prefix is put in memory before the code for the
rest of the instruction.
• The code byte for the segment override prefix has the format 001xx110. You
insert a 2-bit code in place of the X's to indicate which segment base you want
the effective address to be added to.
• ES=00,CS=01, SS=10, DS=11

48
10/16/2024

CONSTRUCTING THE MACHINE CODES FOR 8086 INSTRUCTIONS


EXAMPLES
MOV CS:[BX], DL

CONSTRUCTING THE MACHINE CODES FOR 8086 INSTRUCTIONS


EXAMPLES

ALP Code Equivalent Machine Code


MOV AX, OO1OH 10111000 0001 0000 or B8H, 10H
MOV DS, AX 0001110 11011000 or 8EH D8H
IN AL, 05H 1100100 00000101 or E4H 05H
ADD AL, 07H 00000100 00000111 or 04H 07H
MOV [0000], AL 10100010 00000000 00000000 or A2H 00H
INT 3 11001100 or CCH

49
10/16/2024

WRITING PROGRAMS FOR USE WITH AN ASSEMBLER


• An assembler also allows us to refer to data items by name rather than
by their numerical offsets.
• This greatly reduces the work you have to do and makes your programs
much more readable.
• The assembly language programs were assembled with TASM 1.0 from
Borland International or MASM 5.1 from Microsoft Corp.
• TASM is faster, but the program format for these two assemblers is
essentially the same.

WRITING PROGRAMS FOR USE WITH AN ASSEMBLER


• Program Format: The example program in Figure 3-14 contains direction
to the assembler. These directions to the assembler are commonly called
assembler directives or pseudo operations.
SEGMENT and ENDS Directives
• The SEGMENT and ENDS directives are used to Identify a group of data
items or a group of instructions that you want to be put together In a
particular segment.
• These directives are used in the same way that parentheses are used to
group like terms in algebra.

50
10/16/2024

FIGURE 3-14 Assembly


language source program
to multiply two 16-bit
binary numbers to give a
32-bit result.

WRITING PROGRAMS FOR USE WITH AN ASSEMBLER


SEGMENT and ENDS Directives
• A group of data statements or a group of instruction statements
contained between SEGMENT and ENDS directives is called a Logical
Segment.
• When you Set up a logical segment, you give it a name of your choosing. In
the example program, the statements DATA_HERE SEGMENT and
DATA_HERE ENDS set up a logical segment named DATA_HERE.
• The statements CODE_HERE SEGMENT and CODE_HERE ENDS in the
example program set up a logical segment named CODE_HERE which
contains instruction statements.
• Most 8086 assemblers allow you to use names and labels of up to 31
characters.
• You can’t use spaces or mnemonics in a name, but you can use an
underscore as shown to separate words in a name.

51
10/16/2024

WRITING PROGRAMS FOR USE WITH AN ASSEMBLER


• After the program is assembled and perhaps linked with other assembled
program modules, it is then assigned the physical address where it will be
loaded in memory to be run.
Naming Data and Addresses - EQU, DB, DW and DD Directives
• Programs work with three general categories of data: constants, variables,
and addresses.
• The value of a constant does not change during the execution of the
program. The number 7 Is an example of a constant you might use In a
program.
• A variable is the name given to a data item which can change during the
execution of a program. The Current temperature of an oven is an example
of a variable.
• Addresses are referred to in many instructions. You may for example, load
an address into a register or Jump to an address.

WRITING PROGRAMS FOR USE WITH AN ASSEMBLER


Naming Data and Addresses - EQU, DB, DW and DD Directives

• If you give names to constants, variables, and addresses, the assembler


can use these names to find a desired data item or address when you
refer to it in an instruction.
• Specific directives are used to give names to constants and variables in
your programs.
• Labels are used to give names to addresses in your programs.

52
10/16/2024

WRITING PROGRAMS FOR USE WITH AN ASSEMBLER


Naming Data and Addresses - EQU, DB, DW and DD Directives
EQU Directive
• The EQU or equate, directive is used to assign names to constants used In
your programs.
• The statement CORRECTION_FACTOR EQU 07H, in a program such as our
previous example, would tell the assembler to insert the value 07H every
time it finds the name CORRECTION_FACTOR in a program statement.
• When the assembler reads the statement ADD AL, CORRECTION_FACTOR it
will automatically Code the Instruction as if you had written it ADD AL, 07H.
• The assembler automatically inserts the new value of 09H in all 23
instructions.

WRITING PROGRAMS FOR USE WITH AN ASSEMBLER


Naming Data and Addresses - EQU, DB, DW and DD Directives
DB,DW and DD Directives
• The DB, DW and DD directives are used to assign names to variables in your
programs.
• The DB directive after a name specifies that the data is of type byte.
• The program statement OVEN_TEMPERATURE DB 27H, for example declares a
variable of type byte, gives It the name OVEN_TEMPERATURE, and gives it an
initial value of 27H.
• When the binary code for the program is loaded into memory to be run, the
value 27H will be loaded into the memory location identified by the name
OVEN_ TEMPERATURE DB 27H.
• DW is used to specify that the data is of type word 16 bits and DD is used to
specify that the data is of type doubleword (32 bits).

53
10/16/2024

WRITING PROGRAMS FOR USE WITH AN ASSEMBLER


Types of Numbers Used in Data Statements
BINARY Ex: TEMP_MAX 1DB 0111 1001 B
DECIMAL Ex: EMP._MAX DB 49
HEXADECIMAL Ex: MULTIPLIER DW 3B2AH
BCD
ASCII
• ASSUME Directive: The ASSUME directive tells the assembler which logical
segment to use for each of these physical. The statement ASSUME
CS:CODE_HERE tells the assembler that the logical segment named CODE_HERE
contains the instruction statements for the program and should be treated as a
code segment.
• END directive : The END directive, as the name implies. tells the assembler to
stop reading. Any Instructions or statements that you write after an END
directive will be Ignored.

ASSEMBLY LANGUAGE PROGRAM DEVELOPMENT TOOLS


•Editor
•Assembler
•Linker
•Locator
•Debugger
•Emulator

54
10/16/2024

ASSEMBLY LANGUAGE PROGRAM DEVELOPMENT TOOLS


• An Editor is a program which allows you to create a file containing the
assembly language statements for your program. Examples of suitable
editors are PC Write, Wordstar, and the editor that comes with some
assemblers.
• An Assembler program is used to translate the assembly language
mnemonics for instructions to the corresponding binary codes.
• A Linker is a program used to join several object flies into one large object
file. When writing large programs, it is usually much more efficient to
divide the large program into smaller modules.
• Each module can be Individually written, tested, and debugged. Then,
when all the modules work, their object modules can be linked together to
form a large functioning program.
• Also the object modules for useful programs - a square root program, for
example - can be kept in a libraryfile and linked into other programs as
needed.

ASSEMBLY LANGUAGE PROGRAM DEVELOPMENT TOOLS


• A locator program called A locator is a program used to assign the specific
addresses of where the segments of object code are to be loaded into
memory. EXE2BIN comes with the IBM PC Disk Operating system (DOS).
EXE2BIN converts a .EXE file to a BIN file which has physical addresses.
• A debugger is a program which allows you to load your object code
program into system memory, execute the program, and troubleshoot or
debug it. The debugger allows you to look at the contents of registers and
memory locations after your program runs, it allows you to change the
contents of registers and memory location.
• Another way to run your program is with an emulator. An emulator is a
mixture of hardware and software. It is usually used to test and debug
the hardware and software of an external system, such as the prototype
of a microprocessor-based instrument.

55
10/16/2024

UNIT - I REVIEW

Introduction to 8086: The 8086 Microprocessor family-overview; 8086 internal


architecture: the execution unit, the BIU;
8086 Family Assembly Language Programming: Program development steps,
constructing the machine codes for 8086 instructions, writing program for use
with an assembler, assembly language program development tools.

56
10/16/2024

UNIT-1 ENDS
UNIT-
THANK YOU

57

You might also like