0% found this document useful (0 votes)
5 views26 pages

Lecture 2

The document provides an overview of the 80x86 microprocessor, focusing on assembly programming, program segments, and addressing modes. It explains the structure of assembly language, including instructions like MOV and ADD, and details about segments such as code, data, and stack segments. Additionally, it discusses various addressing modes used in the 8086 architecture, highlighting their significance in data access and manipulation.

Uploaded by

zagham.muhiodin
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)
5 views26 pages

Lecture 2

The document provides an overview of the 80x86 microprocessor, focusing on assembly programming, program segments, and addressing modes. It explains the structure of assembly language, including instructions like MOV and ADD, and details about segments such as code, data, and stack segments. Additionally, it discusses various addressing modes used in the 8086 architecture, highlighting their significance in data access and manipulation.

Uploaded by

zagham.muhiodin
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

EE-328 Modern Microprocessor system

Resource Person: Engr. Zagham Muhio Din


Today, Topic
The 80x86 Microprocessor
• Introduction to Assembly Programming
• Introduction to Program Segments
• More About segments in 80x86
• 80x86 Addressing Modes
Introduction to Assembly Programming
• A program that consists of 0s and Is is called machine language
• Although the hexadecimal system was used as a more efficient way to represent
binary numbers, the process of working in machine code was still cumbersome
for humans.
• Eventually, Assembly languages were developed, which provided mnemonics
for the machine code instructions, plus other features that made programming
faster and less prone to error.
• The term mnemonic is typically used in computer science and engineering
literature to refer to codes and abbreviations that are relatively easy to
remember.
• Assembly language programs must be translated into machine code. by a
program called an assembler. Assembly language is referred to as a low-level
language because it deals directly with the internal structure of the CPU.
• To program in Assembly language, the programmer must know the number of
registers and their size, as well as other details of the CPU:
Introduction to Assembly Programming
Instruction for Assembly Programming
Write the instruction in 𝜇𝑃 in this way
Instruction Destination Source
; is used for write the comment during assembly language code
Mov Instruction: Simply stated, the MOV instruction copies data from one location to another. It has
the following format:
MOV Destination source ;copy source operand to destination
Example
MOV DX, CX ; copy CX to DX
Write the Program in Assembly language to loads 8bit CL with value of 55H, then moves this value
around to various register like DL,AH,AL, BH and CH.
MOV CL,55H ; Move 55H into register CL
MOV DL,CL ; copy the contents of CL into DL (now DL=CL=55H)
MOV AH,DL ; copy the contents of DL into AH (now AH=DL=55H)
MOV AL, AH ; copy the contents of AH into AL (now AL=AH=55H)
MOV BH,AL ; copy the contents of BH into AL (now BH=AL=55H)
MOV CH,BH ; copy the contents of CH into BH (now CH=BH=55H)
Introduction to Assembly Programming
Write the Program in Assembly language to loads 16bit CX with value of 468FH,
then moves this value around to various register step by step like ,AX,DX, BX,DI,
SI,DS and BP.
MOV CX,468FH ; Move 468FH into register CX
MOV AX,CX ; copy the contents of CX into AX (now AX=CX=468FH)
MOV DX,AX ; copy the contents of AX into DX (now DX=AX=468FH)
MOV BX, DX ; copy the contents of DX into BX (now BX=DX=468FH)
MOV DI,BX ; copy the contents of BX into DI (now DI=BX=468FH)
MOV SI,DI ; copy the contents of DI into SI (now SI=DI=468FH)
MOV DS,SI ; copy the contents of SI into DS (now DS=SI=468FH)
MOV BP,DS; copy the contents of DS into BP (now BP=DS=468FH)
Introduction to Assembly Programming
Ligal and illegal instruction
MOV AX,58FCH ; (legal because AX is 16bit register and 58FC is also 16bit)
MOV DX, 6678H; (legal because DX is 16bit register and 6678 is also 16bit)
MOV SI, 924BH; (legal because SI is 16bit register and 924B is also 16bit)
MOV BP, 2459H; ((legal because BP is 16bit register and 2459 is also 16bit)
• Data can be moved directly into non-segment registers only, using the MOV
instruction.
• MOV DS, 2341H; (illegal because data only moved into non-segment register)
• MOV CS, 3F47H; (illegal because data only moved into non-segment register)
Solution of the above problem is values cannot be loaded directly into any segment register (CS, DS,
ES, or SS). To load a value into a segment register, first load it to a non segment register and then
move it to the segment register.
• MOV AX, 2345H
• MOV DS,AX
• If a value less than FFH is moved into a 16-bit register, the rest of the bits are assumed
to be all zeros. For example, in "MOV Bx,5 the result will be BX = 0005; that is, BH = 00
and BL = 05.
Introduction to Assembly Programming
ADD Instruction: Is used to Add the Destination and Source and store the results into
the destination.
ADD destination, source ; ADD the source operand to the destination
Write a program in Assembly Language in which store the 25H into AL and 34H into
BL then add the both of them and store the result in AL and what’s results store in AL.
MOV AL,25H ;move 25 into AL;
MOV BL,34H ;move 35 into BL;
ADD AL,BL ;AL=AL+BL=25H+34H=59H
Write a program in Assembly Language in which store 25H into DH and add 34H
directly with DH and store the results in DH.
MOV DH,25H ;move 25 into DH and DH=25H
ADD DH,34H ; DH=DH+34H=25H+34H=59H
General-purpose registers are typically used in arithmetic operations. Register AX is
sometimes referred to as the accumulator.
Introduction to Program Segment
• A typical Assembly language program consists of at least three segments: a code
segment, a data segment, and a stack segment. A segment is an area of memory that
includes up to 64K bytes and begins on an address evenly divisible by 16.
• In the 8086/8088 each segment register has 64KB
20
of memory (Means that CS,DS,SS
has 64KB of memory) and 20 address pins (2 = 1𝑀𝐵).
• Logical and Physical Address: In the 8086/8088 has three type of address
• Physical Address: 20-bit address that is actually put on the address pins in 8086 𝜇𝑝. This Address
ranges from 00000H to FFFFFH
• Offset: The offset address is a location within a 64K-byte segment range. Therefore, an offset
address can range from 0000H to FFFFH.
• Logical Address: The logical address consists of a segment value and an offset address.
• Code Segment: Contains the Assembly language instructions that perform the tasks
that the program was designed to accomplish.
• Logical Address of Code segment can be calculated by this formate CS:IP.
• The physical address for the location of the instruction is generated by shifting the CS left one hex
digit and then adding it to the IP.
• IP contains the offset address.
Introduction to Program Segment
Introduction to Program Segment
Example:1-1: If CS = 24F6H and IP = 634AH, show (a) the logical address, and (b)
the offset address. Calculate (c) the physical address, (d) the lower range, and (e)
the upper range of the code segment.
Solution: Physical Address
24F60H
(a) Logical Address=CS:IP=24F6H:634AH +634AH
(b) Offset Address=IP=634AH 2B2AAH
F+3=15+3=18-16=2
(c)Physical Address 1+4+6=11=B
First shift the CS left with Hexadecimal digit CS=24F60 Upper Range

Now Physical Address=CS+IP=24F60H+634AH=2B2AAH 24F60H


+ FFFFH
(d) Lower Range=CS+00000H=24F60H+0000H=24F60H 34F5FH
(e) Upper Range=CS+FFFFFH= 24F60H+FFFFH F+6=15+6=21-16=5
1+F+F=1+15+15=31-16=15=F
1+4+F=1+4+15=20-16=4
Introduction to Program Segment
Data segment: is used to store information (data) that needs to be processed by the instructions in the code
segment.
If the DS address written in form of assembly language by below code is
MOV AL,0H ; Clear the AL register
ADD, AL, [200H]; The contents of DS:200 to AL
200H is the offset address but written in assembly language with square bracket, if we use offset without square
bracket then it consider the data store in register instead of offset address.
Write an assembly language program that initializes the AL register to zero, loads the starting memory address
200H into BX, and then uses BX as a pointer to consecutively access four bytes from memory. After each byte is
accessed, add it to AL and increment BX to point to the next memory location.
MOV AL,0 ;initializing the AL
MOV BX, 200H ; Load the offset address into the BX that is BX=200H
ADD AL,[BX] ; Add the first byte to AL
INC BX ; Increment the value store in BX so BX=200H+1H=201H
ADD AL, [BX] ; Add the Next byte to AL
INC BX; Increment the value store in BX so BX=201H+1H=202H
ADD AL, [BX] ; Add the Next byte to AL
INC BX; Increment the value store in BX so BX=202H+1H=203H
ADD AL, [BX] ; Add the Next byte to AL
Introduction to Program Segment
Example 1-2: Assume that DS is 5000 and the offset is 1950. Calculate the physical address.
Solution:

1. Shift DS left.

2. Add the Offset

The physical address will be 50000 + 1950 = 51950


Example 1-3: If DS = 7FA2H and the offset is 438EH, calculate (a) the physical address, (b) the lower range, and (c)
the upper range of the data segment. Show (d) the logical address. (Self Assessment)
Introduction to Program Segment
Example 1-5: Assume memory locations with the following contents: DS:6826 = 48 and DS:6827 =
22. Show the contents of register BX in the instruction “MOV BX,[6826]”.
Solution:
DS:6826=48 that is low order byte therefore BL=48
DS:6827=22 that is higher order byte so BH=22
Stack Segment: The stack is a section of read/write memory (RAM) used by the CPU to store
information temporarily.
The storing of a CPU register in the stack is called a push, and loading the contents of the stack
into the CPU register is called a pop.
When an instruction pushes or pops a general-purpose register, it must be the entire 16-bit
register. In other words, one must code "PUSH Ax"; there are no instructions such as "PUSH AL"
or "PUSH AH".
Example: 1-6: Assuming that SP = 1236, AX = 24B6, DI = 85C2, and DX = 5F93, show the contents
of the stack as each of the following instructions is executed.
PUSH AX
PUSH DI
PUSH DX
More about Program segment
More about Program segment
Example1-7: Assuming that the stack is as shown below, and SP = 18FA, show the
contents of the stack and registers as each of the following instructions is executed:
POP CX; POP DX; POPBX
More about Program segment
Example1-8: If SS = 3500H and the SP is FFFEH, (a) Calculate the physical address
of the stack. (b) Calculate the lower range. (c) Calculate the upper range of the
stack segment. (d) Show the stack’s logical address.
(Self Assessment)
Example 1-9: Show how the flag register is affected by the addition of 38H and
2FH.
38H
Solution: +2FH
67H
MOV AL,38H 8+F=8+15=23-16=7
1+3+2=6
ADD AL,2FH
CF=0, PF=0, AF=1, ZF=0
SF=0,
More about Program segment
Example:1-11: Show how the flag register is affected by
MOV AL, 9CH ; AL=9CH 9CH
MOV DH,64H; DH=64H +64H
00H
ADD AL,DH; AL=0H C+4=12+4=16=16-16=0
Solution: CF=1, AF=1, ZF=1 1+9+6=16-16=0
1
SF=0, PF=1
Example:1-12: Show how the flag register is affected by
MOV AX, 34F5H; AX=34F5H
ADD AX,95EBH ;now AX=CAE0H
Solution: (Self Assessment)
Example 1-13: Show how the flag register is affected by
MOV BX,AAAAH ;BX=AAAAH
ADD BX,5556H ;BX=0000H
Solution: (Self Assessment)
More about Program segment
Example #1-14: Show how the flag register is affected by
MOV AX,94C2H ;AX=94C2H
MOV BX,323EH ;BX=323EH
94C2H
ADD AX,BX ;AX=AX+BX=94C2H+323EH=C700H +323EH
MOV DX,AX ; DX=AX=C700 C700H
2+E=2+14=16-16=0
MOV CX,DX ; CX=DX=C700 1+C+3=1+12+3=16-16=0
1+4+2=7
Solution: 9+3=12=C
CF=0, AF=1, SF=1
ZF=0, PF=1
Addressing Mode in 8086
What is an addressing ?
Addressing modes are the techniques used by the CPU to identify where the data
needed for an operation is stored. They provide rules for interpreting or
modifying the address field in an instruction before accessing the operand.
In a one instruction there is two parts (i) Opcode (ii) Operands
• Opcode: what operation to be performed
• Operands: What Date will be performing the operation.
Types of Addressing Modes
• Implied mode: In implied addressing the operand is specified in the instruction itself. In
this mode the data is 8 bits or 16 bits long and data is the part of instruction. Zero address
instruction are designed with implied addressing mode.
Addressing Mode in 8086
Types of Addressing Modes
• Immediate addressing mode (symbol #): In this mode data is present in address field of
instruction .Designed like one address instruction format. Note: Limitation in the
immediate mode is that the range of constants are restricted by size of address field.

• Register mode: In register addressing the operand is placed in one of 8 bit or 16 bit
general purpose registers. The data is in the register that is specified by the instruction.
Here one register reference is required to access the data.
Addressing Mode in 8086
Types of Addressing Modes
• Register Indirect mode: In this addressing the operand’s offset is placed in any one of the
registers BX,BP,SI,DI as specified in the instruction. The effective address of the data is in
the base register or an index register that is specified by the instruction. Here two register
reference is required to access the data.

• Auto Indexed (increment mode): Effective address of the operand is the contents of a
register specified in the instruction. After accessing the operand, the contents of this
register are automatically incremented to point to the next consecutive memory
location.(R1)+. Here one register reference, one memory reference and one ALU
operation is required to access the data.
• Auto indexed ( decrement mode): Effective address of the operand is the contents of a
register specified in the instruction. Before accessing the operand, the contents of this
register are automatically decremented to point to the previous consecutive memory
location. -(R1)Here one register reference, one memory reference and one ALU operation
is required to access the data.
Addressing Mode in 8086
Types of Addressing Modes
• Direct addressing/ Absolute addressing Mode (symbol [ ]): The operand’s offset is given in the
instruction as an 8 bit or 16-bit displacement element. In this addressing mode the 16-bit effective
address of the data is the part of the instruction. Here only one memory reference operation is
required to access the data.

• Indirect addressing Mode (symbol @ or () ): In this mode address field of instruction contains
the address of effective address. Here two references are required. 1st reference to get effective
address. 2nd reference to access the data.
• Register Indirect: In this mode effective address is in the register, and corresponding register name will be
maintained in the address field of an instruction. Here one register reference, one memory reference is
required to access the data.
• Memory Indirect: In this mode effective address is in the memory, and corresponding memory address will
be maintained in the address field of an instruction. Here two memory reference is required to access the data.
• Base register addressing mode: Base register addressing mode is used to implement inter segment transfer
of control. In this mode effective address is obtained by adding base register value to address field value.
Addressing Mode in 8086
Types of Addressing Modes
• Indexed addressing mode: The operand’s offset is the sum of the content of an index
register SI or DI and an 8 bit or 16-bit displacement.
• Based Indexed Addressing: The operand’s offset is sum of the content of a base register
BX and an index register SI or DI.
Addressing Mode in 8086
Addressing Mode in 8086
Addressing Mode in 8086
Example:1-15: Find the physical address of the memory location and its contents
after the execution of the following, assuming that DS = 1512H.
MOV AL,99H
MOV [3518],AL
Solution:
AL=99H is data store in AL
AL=99H is located at 3518 Address
DS:3518
Logical address=1512:3518
Shift the DS into left side that is 15120H
Physical Address= 15120+3518=18638H
the memory location with address 18638H will contain the value 99H.

You might also like