Professional Documents
Culture Documents
Unit 1 Notes
Unit 1 Notes
Unit 1 Notes
Microprocessor:
A silicon chip that contains a CPU. In the world of personal Computers, the
terms microprocessor and CPU are used interchangeably. A microprocessor
(sometimes abbreviated μP) is a digital electronic component with miniaturized
transistors on a single semiconductor integrated circuit (IC).
Introduction:
• First Microprocessor – IN 4004 in1971
• First 8 – bit microprocessor – IN 8008 in1972
• IN 8085 – Functionally complete microprocessor.
Introduction to 8086:
8086 Overview:
• It is a 16 bit µp. Introduced in the year1978.
• 8086has 16-bit ALU; this means 16-bit numbers are directly processed by8086.
• It has 16-bit data bus, so it can read data or write data to memory or I/O ports
either 16 bits or 8 bits at a time.
• 8086 is first x86microprocessor.
The term x86 refers to a family of instruction set architectures based on the Intel 8086
CPU.
8086 Features:
• It is a 16-bitμp.
• 8086 has a 20 bit address bus can access up to 220 memory locations (1MB).
• It can support up to 64K I/O ports.
• It provides 14, 16 –bit registers.
• It has multiplexed address and data bus AD0- AD15 and A16 –A19.
• It requires single phase clock with 33% duty cycle to provide internal timing.
• 8086 is designed to operate in two modes, Minimum and Maximum.
• It can prefetches up to 6 instruction bytes from memory and queues
them in order to speed up instruction execution.
• It requires +5V power supply.
• A 40 pin dual in line package
Microprocessor Architecture:
8086 has two blocks BIU and EU.
• BIU(bus interface unit) 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.
• The instruction bytes are transferred to the instruction queue (6-byteslong).
• EU (execution unit) of the 8086 tells the BIU where to fetch instructions or data
from, decodes instructions, and executes instructions.
Memory segmentation:
• 16 – Logical segments.
• The 16-bit contents of the segment register actually point to the starting
location of the particular segment.
• To address a specific memory location within a segment, we need an offset
address.
• The offset address is also 16-bits long – Size of each segment: 64K.
Segment registers:
The advantage of using segmented memory scheme is that, instead of using a
20-bit register for a physical address, the processor just maintains two 16-bit registers
which are within the word length capacity of the machine.
Code segment Register (CS): It is a 16-bit register which stores the starting or base
of the code segment.
Stack segment (SS): It is a 16-bit register which stores the starting or base of the
stack segment.
Data segment (DS): It is a 16-bit register which stores the starting or base of the data
segment.
Extra segment (ES): It is a 16-bit register which stores the starting or base of the
extra data segment.
Flag Register or Program Status Word (PSW):
Flags are a 16-bit register containing 9 one bit flags.
Overflow Flag (OF) –it is set when arithmetic overflow has occurred.
Direction Flag (DF) - If set then string manipulation instructions will auto-decrement
index registers. If cleared then the index registers will be auto-incremented.
Interrupt-enable Flag (IF) - setting this bit enables maskable interrupts.
Trap Flag (TF) - if set, it executes one instruction at a time.
Sign Flag (SF) - set if the most significant bit of the result is set.
Zero Flag (ZF) - set if the result in accumulator is zero
Auxiliary carry Flag (AF) - set if there was a carry from D3 to D4 in the AL
register.
Parity Flag (PF) –when result in the accumulator has even number of 1PF is set 1.
Carry Flag (CF) - When carry come out of the last bit or MSB , CF is set to 1.
Addressing Modes:
Addressing mode is a method of locating data or operands. According to the
flow of instruction execution,
A] Sequential Control flow instructions
Ex, Arithmetic, Logical, data transfer, etc.
B] Control Transfer instructions
INT, Call, Ret and Jump.
A] Sequential Control flow instructions
1) Immediate Addressing
MOVAX, 0005H, MOV CL, 8FH
2) Direct Addressing ( Segment Override prefix)
MOV AX,[5000H]
Physical Address: (10H * DS) + 5000H
3) Register Addressing
MOVBX, AX MOV AL, CL
4) Register Indirect Addressing
MOV AX,[BX]
Effective / Physical Address: (10H * DS) + [BX]
5) Indexed Addressing
MOV AX,[SI]
Effective / Physical Address: (10H * DS) + [BX]
DS – default segment register for SI and DI except String manipulation instructions.
6) Register Relative addressing
MOV AX,50H[BX]
• Here 50H : 8 – bit Immediate Displacement
• Effective Address: (10H * DS) + 50H+[BX]
7) Based Indexed addressing
• MOV AX,[BX][SI]
• Effective Address: (10H * DS) +[BX] +[SI]
8) Relative Based Indexed addressing
• MOV AX, 50H [BX][SI]
• Effective Address: (10H * DS) + 50H +[BX] +[SI]
B] Branch Category / Control transfer
Inter Segment: Control is transferred to different segment Intra Segment: Same or
within the segment
1) Intra-segment Direct
JMP SHORT NEXT; same segment, NEXT - Label
2) Intra-segment Indirect
JMP [BX]; Jump to effective address stored in BX
3) Intersegment Direct
JMP 5000H:2000H; Jump to effective address 2000H in segment 5000H.
4) Intersegment Indirect
JMP [2000H] ; Jump to an address in the other segment specified at effective
address 2000H in DS, that points to the memory block as shown below:
Address of Destination is at: (10H * DS) + 2000H
Assume DS = 3000H. Therefore at 32000H – 32003 H Locations both segment and
offset address are available
INSTRUCTION SET OF8086
The 8086 instructions are categorized into the following main types.
1. Data Copy / Transfer Instructions
2. Arithmetic and Logical Instructions
3. Shift and Rotate Instructions
4. Loop Instructions
5. Branch Instructions
6. String Instructions
7. Flag Manipulation Instructions
8. Machine Control Instructions
Data Copy / Transfer Instructions:
MOV move byte or word to register or memory
IN,OUT input byte or word from port, output word to port
LEA load effective address
LDS, LES load pointer using data segment, extra segment
PUSH, POP push word onto stack, pop word off stack
XCHG exchange byte or word
XLAT translate byte using look-up table
Arithmetical and Logical Instructions:
ADD, SUB Add, subtract byte or word
ADC, SBB Add, subtract byte or word and carry
INC, DEC increment, decrement byte or word
NEG negate byte or word (two’s complement)
CMP compare byte or word
MUL, DIV multiply, divide byte or word
IMUL, IDIV integer multiply, divide byte or word (Signed)
CBW, CWD convert byte to word, word to double word
AAA,AAS,AAM,AAD Ascii adjust for addition, subtraction, multiplication, division
DAA,DAS Decimal adjust for addition, subtraction
NOT Logical not of byte or word (one’s complement)
AND Logical and of byte or word
OR Logical or of byte or word
XOR Logical x-or of byte or word
TEST test byte of word
Shift and Rotate
SHL,SHR Logical shift left, right byte or word by 1 or CL
SAL,SAR arithmetic shift left, right byte or word by 1 or CL
ROL, ROR Rotate left, right byte or word by 1 or CL
RCL, RCR rotate left, right through carry byte or word by 1 or CL
Loop and Branch Instruction
JMP Unconditional jump
JA (JNBE) Jump if above
JAE Jump if above or equal
JB Jump if below
JBE Jump if below or equal
JE Jump if equal
JG Jump if greater
JGE Jump if greater or equal
CALL, RET Call, return from procedure
INT, INT0 Software interrupt, interrupt if overflow
IRET Return from interrupt
String Instructions
MOVS Move byte or word string
MOVSB,MOVSW Move byte, word string
CMPS Compare byte or word string
SCAS Scan byte or word string
LODS, STOS Load, store byte or word string
REP Repeat
REPE, REPZ Repeat while equal, zero
REPNE,REPNZ Repeat while not equal zero
Processor Control Instructions
STC, CLC, CMC Set, clear, complement carry flag
STD, CLD Set, clear direction flag
STI, CLI Set, clear interrupt enable flag
LAHF,SAHF Load AH from flags, store AH into flags
PUSHF, POPF Push flags onto stack, pop flags off stack
ESC Escape to external processor interface
LOCK Lock bus during next instruction
NOP No operation
WAIT Wait for signal on test input
HLT Halt processor
Assembler directives:
There are some instructions in the assembly language which are not a part of processor
instruction set. These instructions are instructions to the assembler, linker and loader.
These are referred to as pseudo-operations or as assembler directives.
ALIGN – aligns next variable or instruction to byte which is multiple of operand.
ASSUME – selects segment registers to be default for all symbol in segments.
COMMENT- indicates a comment
DB- allocates and optionally initializes bytes of storage
DW-allocates and optionally initializes words of storage
DD-allocates and optionally initializes double words of storage
DQ- allocates and optionally initializes quad words of storage
DT- allocates and optionally initializes 10 byte long storage units
END- terminates assembly; optionally indices program entry point
ENDM- terminates a macro definition
ENDP- marks end of procedure definition
ENDS- marks end of segment or structure
EQU- assigns expression to name
EVEN- aligns next variable or instruction to even byte
EXITM- terminates macro definition
EXTRN- indicates externally defined symbols
LABEL- creates a new label with specified type and current location counter
LOCAL- declares local variable in macro definition
MACRO-starts macro definition
MODEL- specifies mode for assembling the program
ORG-sets locations counter to argument
PAGE-sets length and width of program listing; generates page break PROC- starts
procedure definition
PTR-assigns a specific type to a variable or to a label
PUBLIC- identifies symbols to be visible outside module
TITLE- defines the program listing title.
Assembly language programming:
In any microprocessor system the microprocessor only understands the
instructions in the binary form. There are three language levels that can be used to write
a program.
1. Machine level language programs
2. Assembly language level programs
3. High level language programs.
4. Assembler translates a source file that was created using the editor into machine
language such as binary or object code. First file is object file; second file is assembler
list file.
A linker is a program used to join together several object files into one large object file.
Modular Programming:
Usually, programming task is divided into subtasks, separate modules are
written for performing subtasks. Each module is tested separately. The common
routine required in modules are written in separate module and they are called from
individual modules as per requirements. Programming done in this fashion is called
modular programming.
Advantages:
1. Code is short, simple and easy to understand.
2. The scoping of variables can easily be controlled.
3. Documents can be easily understood.
While designing the modules programmers must consider the two things:
1. Control coupling between modules
2. Data coupling between modules
Control coupling refers to how and under what conditions the modules are entered and
excited.
Data coupling refers to how information is communicated between the modules.
Three assembly language components are used for the development of modular
programs.
1. Structures
2. Procedures or subroutines, Macros.
Linking and Relocation:
Generating machine code from assembly language program manually is very
time consuming and complex process. Thus assembly language tools such as
assembler, linker, loader and debugger are used to develop and execute assembly
language programs.
The first step in the development process is to write an assembly language. It is
input to the assembler. The assembler translates assembly language statements to their
binary equivalents usually known as object code. Time required to translate assembly
code to object code is called assemble time.
Assembler translates a source file that was created using the editor into machine
language such as binary or object code. First file is object file; second file is assembler
list file.
A linker is a program used to join together several object files into one large
object file. At the load time, the program loader copies the program into the computers
main memory and at execution time, the program execution begins.
Segment combination:
The segment with the same name is joined together according to the combined
type specified in the segment derivatives.
The segment derivatives take the form: Segment name Segment combine-type. Segment
with the same name but no combine-type will cause a linker error.
There are five possible combine-types:
1. PUBLIC
2. COMMON
3. STACK
4. AT
5. MEMORY
AT combine- type allows the user to specify the exact starting address of a
segment of code or data. Here the address of Variables and Labels set by the linker
and loader process and they are said to be relocatable.
AT combine- type the address of Variables and Labels set by the Programmer
and Assembler process and such variables and labels are known as absolute variables
and labels.