Chap2 - 48086 Architecture and Its Programming
Chap2 - 48086 Architecture and Its Programming
Chap2 - 48086 Architecture and Its Programming
Extra Segment(ES)
• It is used by some string (character data) to handle memory addressing. The string
instructions always use the ES and destination index (DI) to determine 20 bit physical
address.
- BX Register
• BX is known as the base register since it is the only general purpose register
that can be used as an index to extend addressing. The BX register is similar to
the 8085’s H, L register. BX can also be combined with DI or SI as C base
register for special addressing.
-CX register:
• The CX register is known as the counter register because some instructions
such as SHIFT, ROTATE and LOOP use the contents of CX as a Counter.
- DX register:
• The DX register is known as data register. Some I/O operations require its use
and multiply and divide operations that involve large values assume the use of
DX and AX together as a pair. DX comprises the rightmost 16 bits of the 32-bit
EDX.
-Stack Pointer (SP) and Base Pointer (BP):
• Both are used to access data in the stack segment. The SP is used as an offset
from the current stack segment during execution of instructions. The SP’s
contents are automatically updated (increment/decrement) during execution of
a POP and PUSH instructions.
• The BP contains the offset address in the current stack segment. This offset is
used by instructions utilizing the based addressing mode.
- Index register:
• The two index registers SI (Source index) and DI (Destination Index) are used
in indexed addressing. The instructions that process data strings use the SI and
DI index register together with DS and ES respectively, in order to distinguish
between the source and destination address.
-Flag register:
• The 8086 has nine 1 bit flags. Out of 9 six are status and three are control
flags. The control bits in the flag register can be set or reset by the
programmer.
g) INC/DEC (Increment/Decrement by 1)
• INC/DEC reg./mem. (8 bit or 16bit)
• E.g. INC AL
DEC BX
h) NEG- Negate (2’s complement)
i) ASCII-BCD Conversion
AAA: ASCII Adjust after addition
AAS: ASCII Adjust after subtraction
AAM: Adjust after multiplication
AAD: Adjust after division
DAA: Decimal adjust after addition
DAS: Decimal adjust after subtraction
2) Logical/shifting/comparison instructions
a) Logical
• AND/OR/XOR reg/mem, reg/mem/immediate
• NOT reg/mem
• E.g. AND AL, AH
XOR [BX], CL
b) Rotation
• ROL- rotate left, ROR-rotate right
• E.g. ROL AX, 1 ; rotated by 1
ROL AX, CL ; if we need to rotate more than one bit
9) String instructions
a) MOVS/ MOVSB/MOVSW ; Move string
• DS: SI source
• DS: DI destination
• CX: String length
b) CMPS/ CMPSB/CMPW ; Compare string
c) LODS /LODSB/LODW ; Load string
d) REP ; Repeat string
• Operators in 8086
• Operator can be applied in the operand which uses the immediate data/address.
• Being active during assembling and no machine language code is generated.
• Different types of operators are:
1) Arithmetic: + , - , * , /
2) Logical : AND, OR, XOR, NOT
3) SHL and SHR: Shift during assembly
4) [ ]: index
5) HIGH: returns higher byte of an expression
6) LOW: returns lower byte of an expression.
• E.g. NUM EQU 1374 H
MOV AL HIGH Num ; ( [AL] 13 )
7) OFFSET: returns offset address of a variable
8) SEG: returns segment address of a variable
1) Register Addressing:
• For this mode, a register may contain source operand, destination operand or both.
• E.g.
• MOV AH, BL
• MOV DX, CX
2) Immediate Addressing
• In this type of addressing, immediate data is a part of instruction, and
appears in the form of successive byte or bytes. This mode contains a
constant value or an expression.
• E.g.
• MOV AH, 35H
• MOV BX, 7A25H
3) Direct memory addressing:
• In this type of addressing mode, a 16-bit memory address (offset) is
directly specified in the instruction as a part of it. One of the operand
is the direct memory and other operand is the register.
• E.g. ADD AX, [5000H]
• Note: Here data resides in a memory location in the data segment,
whose effective address may be computed using 5000H as the Offset
address and content of DS as segment address. The effective address,
here, is 10H*DS + 5000H
4) Direct offset addressing
• In this addressing, a variation of direct addressing uses arithmetic operators to
modify an address.
• E.g.
• ARR DB 15, 17, 18, 21
• MOV AL, ARR [2] ; MOV AL, 18
• ADD BH, ARR+3 ; ADD BH, 21
• Disadvantages of ALP:
• - Machine dependent.
• - Lengthy code
• - Error prone (likely to generate errors).
Example
TITLE to display a string MAIN PROC FAR
.MODEL SMALL MOV AX, @DATA
MOV DS, AX
.STACK 64 MOV AH, 09H ;display string
.DATA LEA DX, STR
STR DB ‘programming is fun’, ‘$’ INT 21H
MOV AX, 4C00H
.CODE INT 21H
MAIN ENDP
END MAIN
Assembly language features:
• Program comments:
• The use of comments throughout a program can improve its clarity.
• It starts with semicolon (;) and terminates with a new line.
• E.g. ADD AX, BX ; Adds AX & BX
• Reserved words:
• Instructions : Such as MOV and ADD (operations to execute)
• Directives: Such as END, SEGMENT (information to assembler)
• Operators: Such as FAR, SIZE
• Predefined symbols: such as @DATA, @ MODEL
Identifiers:
- An identifier (or symbol) is a name that applies to an item in the program
that expects to reference.
- Two types of identifiers are Name and Label.
- Name refers to the address of a data item such as NUM1 DB 5, COUNT
DB 0
- Label refers to the address of an instruction.
- E. g: MAIN PROC FAR
- L1: ADD BL, 73
Statements:
- ALP consists of a set of statements with two types
- Instructions, e. g. MOV, ADD
- Directives, e. g. define a data item
• Directives:
• The directives are the number of statements that enables us to control the
way in which the source program assembles and lists.
• These statements called directives act only during the assembly of program
and generate no machine-executable code.
• The different types of directives are:
1) The page and title listing directives:
• The page directive defines the maximum number of lines to list as a
page and the maximum number of characters as a line.
• TITLE gives title and place the title on second line of each page of the
program.
• 2) SEGMENT directive
• It gives the start of a segment for stack, data and code.
3) PROC Directives
• The code segment contains the executable code for a program, which
consists of one or more procedures, defined initially with the PROC
directives and ended with the ENDP directive.
• PROC - name PROC [FAR/NEAR]
• PROC - name ENDP
• FAR is used for the first executing procedure and rest procedures call
will be NEAR.
• - Procedure should be within segment.
4) END Directive
• - An END directive ends the entire program and appears as the last
statement.
• - ENDS directive ends a segment and ENDP directive ends a procedure.
END PROC-Name
7) Dn Directive (Defining data types)
• Assembly language has directives to define data syntax [name] Dn
expression.
• The Dn directive can be any one of the following:
• DB Define byte 1 byte
• DW Define word 2 bytes
• DD Define double 4 bytes
• DF defined farword 6 bytes
• DQ Define quadword 8 bytes
• DT Define 10 bytes 10 bytes
8) The EQU directive
- It can be used to assign a name to constants.
- E.g. FACTOR EQU 12
9) DUP Directive
- It can be used to initialize several locations to zero.
- e. g. SUM DW 4 DUP(0)
DOS FUNCTIONS AND INTERRUPTS
• The common software interrupts used here are INT 10H for video services
and INT 21H for DOS services.
• INT 21H: It is called the DOS function call for keyboard operations follow
the function number. The service functions are listed below:
• # 02H- Display single character
- Sends the characters in DL to display.