SlideShare a Scribd company logo
Flag register
The 16 bit flag register contains status flags as well as control flags
Status flags reflects the
result of the operations
performed by ALU
Bits of the flag register
●
CF: This flag is set whenever there is a carry , either from D7 after an 8-bit
operation, or from D15 after a 16 bit operation
●
PF: This flag indicates the parity of the result's low-byte. If the low-byte has even
no. of 1s , PF = 1, otherwise PF =0
●
AF: If there is a carry from bit D3 to D4 of an operation, AF is set to 1
●
ZF: This flag is set to 1, if the result of an arithmetic or logical operation is zero
●
SF: After arithmetic and logical operations the sign bit of the result is copied into SF
Bits of the flag register
●
TF: Trap flag - When TF =1, the processor enters the single step execution mode
●
IF: Interrupt flag – set/cleared to enable/disable the external maskable interrupts
●
DF: Direction flag – to control the direction of string operations; If DF=0 , the string is
processed in the autoincrementing mode, otherwise in the autodecrementing mode
●
OF: overflow flag – this flag is set whenever the result of a signed operation is too large
so that the high-order bit overflows into the sign bit (will discuss in signed number
arithmetic)
●
All instructions do not affect the flag bits : eg. MOV instructions
Flag register and ADD instruction
●
The flag bits affected by ADD instruction are : CF, PF, AF, ZF, SF and OF
Flag register and ADD instruction
Flag register and ADD instruction
Use of ZF for looping
●
Pgm: Add 5 bytes; CX acts as the counter
8086 Addressing modes
●
Addressing mode indicates how the CPU accesses data or operands
●
8086 provides a total of 7 distinct addressing modes
●
Register
●
Immediate
●
Direct
●
Register indirect
●
Based relative
●
Indexed relative
●
Based indexed relative
Register Addressing mode
●
Uses registers to hold the data to be manipulated
●
Memory is not accessed when instructions of this addressing mode is
executed ; hence relatively fast
●
Examples:
●
MOV BX, DX
●
MOV ES, AX
●
ADD AL, BL
●
ADC AH, BH
Immediate Addressing mode
●
In the immediate addressing mode, the source operand is a constant
●
The data is a part of the instruction
●
Examples:
●
MOV AX, 2550H
●
MOV CX, 625
●
MOV BL, 40H
Direct Addressing mode
●
In the direct addressing mode, the data is in some memory location(s) and the
address of the data comes immediately after the opcode
●
This address is the offset address
●
The physical address will be calculated by combining the DS and the offset
●
Examples
●
MOV DL, [2400]
●
MOV AX,[1520]
●
MOV [3510], AX
Register Indirect Addressing mode
●
The address of the memory location where the operand resides is held by a
register
●
The registers used for this purpose are SI, DI and BX
●
They must be combined with DS in order to generate the 20-bit physical address
●
Examples
●
MOV AL,[BX]
●
MOV AX,[BX]
●
MOV CL, [SI]
●
MOV [DI], AH
●
Assume that DS =1120, SI =2498, and AX =17FE. Show the contents of the
memory locations after the execution of MOV [SI], AX
Based relative Addressing mode
●
In this addressing mode, the base registers BX/BP and an 8-bit or 16-bit
displacement value are used to calculate the offset
●
The default segments used for physical address calculation are DS for BX and SS
for BP
●
Examples
●
MOV CX, [BX]+10 ; move contents of DS: BX+10 and DS: BX+10+1 into CX
●
Alternative coding MOV CX, [BX+10] or MOV CX, 10[BX]
●
MOV AL, [BP]+5 ; move contents of SS: BP+5 into AL
Indexed relative Addressing mode
●
In this addressing mode, the index registers SI/DI and an 8-bit or 16-bit
displacement value are used to calculate the offset
●
The default segment used for physical address calculation is DS
●
Examples
●
MOV DX, [SI]+10 ; move contents of DS: SI+10 and DS: SI+10+1 into DX
●
Alternative coding MOV DX, [SI+10] or MOV DX, 10[SI]
●
MOV AL, [DI]+20
Based Indexed relative Addressing mode
●
In this addressing mode, the base registers BX/BP , index registers SI/DI and 8-
bit or 16-bit displacement value are used to calculate the offset
●
Examples
●
MOV CL, [BX][DI]+8 ; PA = DS(shifted left)+BX+DI+8
●
MOV CH, [BX][SI]+20 ; PA= DS(shifted left)+BX+SI+20
●
MOV AH, [BP][SI]+29 ; PA = SS(shifted left) +BP+SI+29
●
MOV AH, [BP][DI]+12 ; PA = SS(shifted left) +BP+DI+12
●
MOV AX, [SI][DI]+displacement is illegal
●
Even though we showed examples with MOV, there are several other
instructions which supports the above addressing modes
Segment Overrides
●
The 8086 allows overriding the default segment with other segment registers
●
To do that we specify the segment in the code
●
Examples
●
MOV AL,[BX] ; By default PA = DS(shifted left) + BX
●
MOV AL, ES:[BX] ; Overriding the default segment PA = ES(shifted left) + BX
Segment Overrides
Summary of Addressing modes
8086 Assembly language
programming
Programming 8086
●
We are assuming that we are going to assemble and execute the 8086 programs
that we write on a PC with an intel microprocessor 8086 or higher
●
In a PC, memory management is the task of the operating system and hence the
values for the CS, DS and SS registers will be assigned by OS ( As a user we do
not have the knowledge about the actual physical memory locations that are
free )
●
When the user program begins execution, the OS would have already assigned
values to the CS and SS. The DS ( and ES, if used) will be initialized inside the
user program.
Sample Program (adding
two bytes)
.MODEL SMALL
.STACK 64
.DATA
DATA1 DB 52H
DATA2 DB 29H
SUM DB ?
.CODE
MAIN PROC FAR
MOV AX, @DATA
MOV DS, AX
MOV AL, DATA1
MOV BL, DATA2
ADD AL, BL
MOV SUM, AL
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
Components of the sample program
●
.MODEL is an assembler directive; it selects one among the different memory
models SMALL, MEDIUM, COMPACT, LARGE, HUGE etc.
●
The SMALL model uses a maximum of 64 Kbytes for code and another 64 Kbytes
for data
Components of the sample program
●
The ALP statements are grouped into different segments
●
A typical program uses CODE, DATA and STACK segments
●
To mark the beginning of a segment we use an assembler directive
●
.CODE marks the beginning of the code segment
●
.DATA marks the beginning of the data segment
●
.STACK marks the beginning of the stack segment
●
.STACK 64 reserves 64 bytes of memory for the stack
●
Three data items (DATA1, DATA2, and SUM) are defined in the DATA segment of
the program
●
The DB directive allocates a byte of memory
Components of the sample program
●
To allocate 2 bytes, we can use DW directive
●
We can use the labels for the data items DATA1, DATA2, etc. in the code to refer
to their location in the DATA segment
●
Procedure is a group of instructions written to accomplish a specific function
●
Every procedure must have a name (or label ) defined by the PROC FAR/PROC
NEAR directive
●
Every procedure must be closed by the ENDP directive
●
The PROC and the ENDP statements for a procedure must have the same label
●
The entry point to user program must be a FAR procedure (if your code has a
single procedure, it should be a FAR procedure)
Components of the sample program
●
The DS value is initialized by the statements
MOV AX, @DATA
MOV DS, AX
●
The instructions below are used to call an OS function to return the control to
the operating system
●
MOV AH, 4CH
●
INT 21H
●
The last line ends the entire program; the labels for the entry point and END
must match
A sample skeleton for a program
.MODEL SMALL
.STACK 64
.DATA
;
;place data definitions here
;
.CODE
MAIN PROC FAR
MOV AX, @DATA
MOV DS, AX
;
;place code here
;
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
Program to add 5 bytes
(Assume sum <= 255)
.MODEL SMALL
.STACK 64
.DATA
DATA_IN DB 25H, 12H, 15H, 1FH, 2BH
SUM DB ?
.CODE
MAIN PROC FAR
MOV AX, @DATA
MOV DS, AX
MOV CX, 05
MOV BX, OFFSET DATA_IN
MOV AL,0
AGAIN: ADD AL,[BX]
INC BX
DEC CX
JNZ AGAIN
MOV SUM, AL
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
Program to add 4 16-bit words (assume sum < = 65535)
.MODEL SMALL
.STACK 64
.DATA
DATA_IN DW 234DH, 1DE6H, 3BC7H, 566AH
SUM DW ?
.CODE
MAIN PROC FAR
MOV AX, @DATA
MOV DS, AX
MOV CX, 04
MOV DI, OFFSET DATA_IN
MOV BX,0
AGAIN: ADD BX,[DI]
INC DI
INC DI
DEC CX
JNZ AGAIN
MOV SI, OFFSET SUM
MOV [SI], BX
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
Program to copy 6 bytes of data from memory locations with offset 0010H to memory
locations with offset 0028H
.MODEL SMALL
.STACK 64
.DATA
ORG 10H
DATA_IN DB 25H, 4FH, 85H, 1FH, 2BH, 0C4H
ORG 28H
COPY DB 6 DUP(?)
.CODE
MAIN PROC FAR
MOV AX, @DATA
MOV DS, AX
MOV SI, OFFSET DATA_IN
MOV DI, OFFSET COPY
MOV CX, 06H
AGAIN: MOV AL,[SI]
MOV [DI],AL
INC SI
INC DI
DEC CX
JNZ AGAIN
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
Write a program to calculate the
sum of 5 bytes. (result can
exceed 255)
Sum of 5 words of data
(result can exceed 65535)
Sum of two multi-word
numbers
Intel8086_Flags_Addr_Modes_sample_pgms.pdf

More Related Content

PPTX
Assembly language.pptx
PDF
110 ec0644
PPTX
Introduction of 8086 micro processor .
PPT
Wk1to4
PPTX
PPT
microprocessor
PPTX
UNIT 1.pptx
PPT
intel 8086 introduction
Assembly language.pptx
110 ec0644
Introduction of 8086 micro processor .
Wk1to4
microprocessor
UNIT 1.pptx
intel 8086 introduction

Similar to Intel8086_Flags_Addr_Modes_sample_pgms.pdf (20)

PPTX
PPTX
Micro-Processor and Micro-Controller subject
PPTX
Coal (1)
PPTX
Mastering Assembly Language: Programming with 8086
PDF
8086 Microprocessors and Microcontrollers
PDF
Intrl 8086 instruction set
PPTX
Lecture_about spm and related issues 3_COAL.pptx
PPTX
UNIT 1.pptx
PPTX
31. 8086 addressing modes
PDF
Lecture6.pdf computer architecture for computer science
PPTX
Lecture_3.1 Registers.pptx....................
PPTX
Chapter 1 archietecture of 8086
PDF
05operand
PDF
8086 microprocessor and interfacing ppt about all thing pdf
PPTX
Microprocessor Miscellaneous datatrans+directives
DOC
3 organization of intel 8086
PPT
Unit 3 assembler and processor
PDF
8086 Assembler Tutorial For Beginners (Part 1
PDF
8086 Microprocessor
PPTX
Register Organisation of 8086 Microprocessor
Micro-Processor and Micro-Controller subject
Coal (1)
Mastering Assembly Language: Programming with 8086
8086 Microprocessors and Microcontrollers
Intrl 8086 instruction set
Lecture_about spm and related issues 3_COAL.pptx
UNIT 1.pptx
31. 8086 addressing modes
Lecture6.pdf computer architecture for computer science
Lecture_3.1 Registers.pptx....................
Chapter 1 archietecture of 8086
05operand
8086 microprocessor and interfacing ppt about all thing pdf
Microprocessor Miscellaneous datatrans+directives
3 organization of intel 8086
Unit 3 assembler and processor
8086 Assembler Tutorial For Beginners (Part 1
8086 Microprocessor
Register Organisation of 8086 Microprocessor
Ad

Recently uploaded (20)

PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
PPT on Performance Review to get promotions
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
Sustainable Sites - Green Building Construction
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
OOP with Java - Java Introduction (Basics)
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
Well-logging-methods_new................
PPTX
Welding lecture in detail for understanding
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PDF
composite construction of structures.pdf
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
Geodesy 1.pptx...............................................
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPT on Performance Review to get promotions
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Sustainable Sites - Green Building Construction
Operating System & Kernel Study Guide-1 - converted.pdf
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
OOP with Java - Java Introduction (Basics)
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Well-logging-methods_new................
Welding lecture in detail for understanding
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
composite construction of structures.pdf
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Geodesy 1.pptx...............................................
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Ad

Intel8086_Flags_Addr_Modes_sample_pgms.pdf

  • 1. Flag register The 16 bit flag register contains status flags as well as control flags Status flags reflects the result of the operations performed by ALU
  • 2. Bits of the flag register ● CF: This flag is set whenever there is a carry , either from D7 after an 8-bit operation, or from D15 after a 16 bit operation ● PF: This flag indicates the parity of the result's low-byte. If the low-byte has even no. of 1s , PF = 1, otherwise PF =0 ● AF: If there is a carry from bit D3 to D4 of an operation, AF is set to 1 ● ZF: This flag is set to 1, if the result of an arithmetic or logical operation is zero ● SF: After arithmetic and logical operations the sign bit of the result is copied into SF
  • 3. Bits of the flag register ● TF: Trap flag - When TF =1, the processor enters the single step execution mode ● IF: Interrupt flag – set/cleared to enable/disable the external maskable interrupts ● DF: Direction flag – to control the direction of string operations; If DF=0 , the string is processed in the autoincrementing mode, otherwise in the autodecrementing mode ● OF: overflow flag – this flag is set whenever the result of a signed operation is too large so that the high-order bit overflows into the sign bit (will discuss in signed number arithmetic) ● All instructions do not affect the flag bits : eg. MOV instructions
  • 4. Flag register and ADD instruction ● The flag bits affected by ADD instruction are : CF, PF, AF, ZF, SF and OF
  • 5. Flag register and ADD instruction
  • 6. Flag register and ADD instruction
  • 7. Use of ZF for looping ● Pgm: Add 5 bytes; CX acts as the counter
  • 8. 8086 Addressing modes ● Addressing mode indicates how the CPU accesses data or operands ● 8086 provides a total of 7 distinct addressing modes ● Register ● Immediate ● Direct ● Register indirect ● Based relative ● Indexed relative ● Based indexed relative
  • 9. Register Addressing mode ● Uses registers to hold the data to be manipulated ● Memory is not accessed when instructions of this addressing mode is executed ; hence relatively fast ● Examples: ● MOV BX, DX ● MOV ES, AX ● ADD AL, BL ● ADC AH, BH
  • 10. Immediate Addressing mode ● In the immediate addressing mode, the source operand is a constant ● The data is a part of the instruction ● Examples: ● MOV AX, 2550H ● MOV CX, 625 ● MOV BL, 40H
  • 11. Direct Addressing mode ● In the direct addressing mode, the data is in some memory location(s) and the address of the data comes immediately after the opcode ● This address is the offset address ● The physical address will be calculated by combining the DS and the offset ● Examples ● MOV DL, [2400] ● MOV AX,[1520] ● MOV [3510], AX
  • 12. Register Indirect Addressing mode ● The address of the memory location where the operand resides is held by a register ● The registers used for this purpose are SI, DI and BX ● They must be combined with DS in order to generate the 20-bit physical address ● Examples ● MOV AL,[BX] ● MOV AX,[BX] ● MOV CL, [SI] ● MOV [DI], AH ● Assume that DS =1120, SI =2498, and AX =17FE. Show the contents of the memory locations after the execution of MOV [SI], AX
  • 13. Based relative Addressing mode ● In this addressing mode, the base registers BX/BP and an 8-bit or 16-bit displacement value are used to calculate the offset ● The default segments used for physical address calculation are DS for BX and SS for BP ● Examples ● MOV CX, [BX]+10 ; move contents of DS: BX+10 and DS: BX+10+1 into CX ● Alternative coding MOV CX, [BX+10] or MOV CX, 10[BX] ● MOV AL, [BP]+5 ; move contents of SS: BP+5 into AL
  • 14. Indexed relative Addressing mode ● In this addressing mode, the index registers SI/DI and an 8-bit or 16-bit displacement value are used to calculate the offset ● The default segment used for physical address calculation is DS ● Examples ● MOV DX, [SI]+10 ; move contents of DS: SI+10 and DS: SI+10+1 into DX ● Alternative coding MOV DX, [SI+10] or MOV DX, 10[SI] ● MOV AL, [DI]+20
  • 15. Based Indexed relative Addressing mode ● In this addressing mode, the base registers BX/BP , index registers SI/DI and 8- bit or 16-bit displacement value are used to calculate the offset ● Examples ● MOV CL, [BX][DI]+8 ; PA = DS(shifted left)+BX+DI+8 ● MOV CH, [BX][SI]+20 ; PA= DS(shifted left)+BX+SI+20 ● MOV AH, [BP][SI]+29 ; PA = SS(shifted left) +BP+SI+29 ● MOV AH, [BP][DI]+12 ; PA = SS(shifted left) +BP+DI+12 ● MOV AX, [SI][DI]+displacement is illegal ● Even though we showed examples with MOV, there are several other instructions which supports the above addressing modes
  • 16. Segment Overrides ● The 8086 allows overriding the default segment with other segment registers ● To do that we specify the segment in the code ● Examples ● MOV AL,[BX] ; By default PA = DS(shifted left) + BX ● MOV AL, ES:[BX] ; Overriding the default segment PA = ES(shifted left) + BX
  • 20. Programming 8086 ● We are assuming that we are going to assemble and execute the 8086 programs that we write on a PC with an intel microprocessor 8086 or higher ● In a PC, memory management is the task of the operating system and hence the values for the CS, DS and SS registers will be assigned by OS ( As a user we do not have the knowledge about the actual physical memory locations that are free ) ● When the user program begins execution, the OS would have already assigned values to the CS and SS. The DS ( and ES, if used) will be initialized inside the user program.
  • 21. Sample Program (adding two bytes) .MODEL SMALL .STACK 64 .DATA DATA1 DB 52H DATA2 DB 29H SUM DB ? .CODE MAIN PROC FAR MOV AX, @DATA MOV DS, AX MOV AL, DATA1 MOV BL, DATA2 ADD AL, BL MOV SUM, AL MOV AH, 4CH INT 21H MAIN ENDP END MAIN
  • 22. Components of the sample program ● .MODEL is an assembler directive; it selects one among the different memory models SMALL, MEDIUM, COMPACT, LARGE, HUGE etc. ● The SMALL model uses a maximum of 64 Kbytes for code and another 64 Kbytes for data
  • 23. Components of the sample program ● The ALP statements are grouped into different segments ● A typical program uses CODE, DATA and STACK segments ● To mark the beginning of a segment we use an assembler directive ● .CODE marks the beginning of the code segment ● .DATA marks the beginning of the data segment ● .STACK marks the beginning of the stack segment ● .STACK 64 reserves 64 bytes of memory for the stack ● Three data items (DATA1, DATA2, and SUM) are defined in the DATA segment of the program ● The DB directive allocates a byte of memory
  • 24. Components of the sample program ● To allocate 2 bytes, we can use DW directive ● We can use the labels for the data items DATA1, DATA2, etc. in the code to refer to their location in the DATA segment ● Procedure is a group of instructions written to accomplish a specific function ● Every procedure must have a name (or label ) defined by the PROC FAR/PROC NEAR directive ● Every procedure must be closed by the ENDP directive ● The PROC and the ENDP statements for a procedure must have the same label ● The entry point to user program must be a FAR procedure (if your code has a single procedure, it should be a FAR procedure)
  • 25. Components of the sample program ● The DS value is initialized by the statements MOV AX, @DATA MOV DS, AX ● The instructions below are used to call an OS function to return the control to the operating system ● MOV AH, 4CH ● INT 21H ● The last line ends the entire program; the labels for the entry point and END must match
  • 26. A sample skeleton for a program .MODEL SMALL .STACK 64 .DATA ; ;place data definitions here ; .CODE MAIN PROC FAR MOV AX, @DATA MOV DS, AX ; ;place code here ; MOV AH, 4CH INT 21H MAIN ENDP END MAIN
  • 27. Program to add 5 bytes (Assume sum <= 255) .MODEL SMALL .STACK 64 .DATA DATA_IN DB 25H, 12H, 15H, 1FH, 2BH SUM DB ? .CODE MAIN PROC FAR MOV AX, @DATA MOV DS, AX MOV CX, 05 MOV BX, OFFSET DATA_IN MOV AL,0 AGAIN: ADD AL,[BX] INC BX DEC CX JNZ AGAIN MOV SUM, AL MOV AH, 4CH INT 21H MAIN ENDP END MAIN
  • 28. Program to add 4 16-bit words (assume sum < = 65535) .MODEL SMALL .STACK 64 .DATA DATA_IN DW 234DH, 1DE6H, 3BC7H, 566AH SUM DW ? .CODE MAIN PROC FAR MOV AX, @DATA MOV DS, AX MOV CX, 04 MOV DI, OFFSET DATA_IN MOV BX,0 AGAIN: ADD BX,[DI] INC DI INC DI DEC CX JNZ AGAIN MOV SI, OFFSET SUM MOV [SI], BX MOV AH, 4CH INT 21H MAIN ENDP END MAIN
  • 29. Program to copy 6 bytes of data from memory locations with offset 0010H to memory locations with offset 0028H .MODEL SMALL .STACK 64 .DATA ORG 10H DATA_IN DB 25H, 4FH, 85H, 1FH, 2BH, 0C4H ORG 28H COPY DB 6 DUP(?) .CODE MAIN PROC FAR MOV AX, @DATA MOV DS, AX MOV SI, OFFSET DATA_IN MOV DI, OFFSET COPY MOV CX, 06H AGAIN: MOV AL,[SI] MOV [DI],AL INC SI INC DI DEC CX JNZ AGAIN MOV AH, 4CH INT 21H MAIN ENDP END MAIN
  • 30. Write a program to calculate the sum of 5 bytes. (result can exceed 255)
  • 31. Sum of 5 words of data (result can exceed 65535)
  • 32. Sum of two multi-word numbers