SS
(64K)
• How 32 bit address converted into 20bits address.
-For conversion segment address is multiplied by 10h (shift left one time) and then adds offset to it.
To get physical address.
1000 x 10 10000
1F00 offset address
BIU
Segment Registers
Instruction Register
EU
Decoder
General Purpose Register
Special Registers
Flag Registers
AH AL
BH BL
CH CL
DH DL
• Index Registers
DI Destination Index and SI Source Index registers are used to hold address.
• Special Purpose Registers
IP Instruction Pointer is used to hold the address of the next instruction to be executed.
SP Stack Pointer is used to hold the address of the top of stack.
BP Base pointer is used to hold address.
• FLAG Register
A 16-bit register, each bit reflects some condition and can be accessed individually. Each bit is called a flag which is set
(1) or clear /Reset(0).
Flags
X X X X O D I T S Z X A X P X C
• Control Flags
DF used for specifying the direction of copying a string.
0=Left to Right 1=Right to Left
IF used to enable or disable interrupts.
0=Interrupt Enable 1=Interrupt Disable
TF used to debug one instruction at a time.
0=Normal Execution 1=Step by Step Execution
• Status Flags
CF set when carry generated and clear otherwise.
AH=0FFh AH +1 =00000000 and carry generated.
OF set when results overflow into sign bit and reset otherwise.
BH=7Fh BH +1 =80 OF=set
SF set when result is –ve and reset otherwise.
ZF set when result of computation is zero and reset otherwise.
AF set when carry generated out of lower nibble to higher nibble and reset otherwise.
0000 1001 + 0000 1000 AC
PF set when parity (no of 1’s ) is Even and reset otherwise.
• Control Signals
4 to 10 parallel signal lines. CPU sends signals on control bus.
-read signal ,write signal ,clock signal, reset signal ,memory signal ,IO device signal, Bus Requested and Bus Granted
signal.
• Program Structure
Title 128 characters long title (optional)
Dosseg Directs Assembler to arranger segments in order (optional)
.Model Specifies one of the following memory models
Tiny Code Segment + Data Segment together must not be exceed 64k
Small One of the Code Segment or Data Segment can exceed 64k
Medium Code Segment can exceed 64k
Compact Data Segment can exceed 64k
Large Both code and Data Segment can exceed 64k
Huge All available memory can be used.
.Stack 10h Specifies space for stack (optional)
.Code Specifies the start of code Segment
Main Proc Indicates start of main procedure
Instructions
Main Endp
Other procedures
.data Specifies start of data Segment
Data Definitions
End Main
• Instruction Format
Uni-operand Instructions
have single operand. One operand can be Register or Memory.
Bi- operand Instructions have two operands. Following can be combinations of operands.
- register, register
- register, memory
- register, constant
- Memory, register
- memory, constant
Syntax
Possible moves
.Syntax
XCHG operand1,operand2
Mov AL,VAR1
XCHG AL,VAR2
MOV VAR1,AL
• Addressing modes
Flexible ways to access memory. Bx, Bp, Si and Di are the registers used by user to access memory.
Bx ,Bp Base register
Si ,DI Index Register.
mov dl,[1234]
mov al,[3475]
mov [1234],al
mov [FFFF],var1
If bx =0010 al
Si = 0010
disp=0020 disp
Mov al, [bx+SI+disp]
SI
Mov al,[0010+0010+0020]
Mov al,[0040] Bx
Mov al , [bx+Si+disp]
Mov al, disp[bx+Si]
Mov al , disp[bx[[Si]
[ bx ] [ Si ]
Displacement
[ bp ] [ di ]
Hardware Interrupt occurs when only h/w device needs attention from microprocessor.
-Controlled by 8259A PIC (Programmable Interrupt Controller).
-Each H/w has its own interrupt request pin attached to PIC.
-Only one interrupt can be passed to microprocessor at one time.
-Interrupt pin can be enabled or disabled by changing the interrupt flag.
Software Interrupt
-Calls to subroutines located in operating system or BIOS.
-Generated by user through instructions
-Execute predefined code
-Subroutines are identified by a number in range 0-FFh.
-Addresses of routines are saved in IVT (interrupt vector table).
-Lowest 1024 bytes of memory.
-Contains addresses of all interrupts.
-Each entry of IVT is of 32 bits.
segment : offset (address of interrupt).
32bits = 4bytes.
No. of entries =1024 /4 = 256
Process fallowed by an INT
-S/w Interrupts called by instruction int
Syntax
int number
-Each interrupt is further divided into smaller routines called services. Int 21h
-Each service is assigned a number.
-No. must be loaded into AH register before calling interrupt. 0
111
1
12
mov ah,3
int 21h 3
• Services of DOS int 21h
1.Char input with echo
Service no. 1
mov ah,1
int 21h
mov char, al
-character input by the user would be available in al register after above two instructions, and then it is moved to any
char variable for its further use.
2.Char output
Service no. 2
mov ah,2
mov dl, ‘ * ’ ;dl must be loaded before calling int with character.
int 21h
Example
mov ah, 1
int 21h
mov dl , al
int 21 h
3.Char input without echo
Service no. 3
mov ah,7
int 21h
-character input by user would be contained in al
4.String output
Service no. 9
-offset of string must be loaded into dx.
mov ah,9
mov dx, offset str1
int 21h
.data
str1 db ‘----------’
-String terminator is $
-Each string must include $ for proper output.
-ASCII control characters:
-0Dh used for carriage return (cursor go at the start of that line)
-0Ah used for line feed (cursor move to next line)
5.Buffered String input
Service 0Ah
-Input a string up to 255 characters.
-Maximum limit should be given first
-Actual input is stored automatically.
-Offset of buffer must be loaded in dx.
-One space is reserved for enter key rest of space is available to store string entered by user.
Example
.data
max db 6 0 1 2 3 4 5 6 7
Input
input actual db? max
actual
string db 6 dup(0)
-one character less than the maximum length is stored.
Service 4
mov dl =(bit data)
mov ah=4
int 21h
-Outputs a character to the current auxiliary device.
7. Normal Termination
Service 4c00h
mov ax,4c00h
int 21h
ADD instruction
-Adds an operand (source operand 8/16bit) to destination operand of same size.
Syntax
add destination, source
Possible adds
Limitations
J = K +M A= B +C +D+E
mov ax ,K mov ax , B
add ax, M add ax , C
mov J , ax add ax, D
add ax, E
mov A ,ax
INC Instruction
-adds 1 to destination operand.
-uni-operand instruction
Syntax
inc dest
-dest = dest +1
Possible increments
-inc register (8/16 bit)
-inc memory (8/16 bit)
Subtract Instruction
Syntax
sub destination, source
-dest = dest – source
-source remains unchanged.
Possible subtracts
Limitations
mov al ,4
sub al ,8
al =0000 0100
0000 1000
1111 1100
0000 0011
1
0000 0100
DEC Instruction
-subtracts 1 from destination operand.
-uni-operand instruction
Syntax
dec dest
dest = dest -1
Possible increments
-dec register (8/16 bit)
-dec memory (8/16 bit)
FLAG Effected ZF=1 AC =1 CF =1
• EQUATES
- Used to give symbolic names to constants.
1. EQUAL SIGN
-redefined able equate
Syntax
name=expression
count=50
2. EQU
-non-redefined able equate
-assigns name to a string or numeric constants.
Syntax
name equ string/constant
.code
move ax, bx
move bx, address string
• Operators
3. Arithmetic Operators
+ , - , * , / ,Mod,+, -.
Precedence ( ) ,* ,/,Mod, +,_
7. Offset Operator
-return offset (address) of variable.
-e.g. mov bx , offset array
inc [bx]
inc byte ptr [bx] or inc word ptr [bx]
Transfer of control instruction normal execution of program is in sequence ,this sequence of
execution can be altered.
TOC Instructions
Jumps Loops
Jumps (unconditional)
-CPU causes or start execution at a new location.
-Location is specified by a label ,converted into address by assembler.
Unconditional jumps
Syntax
jmp destination
or
-destination is a label.
-label must be in range of -128 - +127 bytes from the point of the jmp.
-It can be a forward or backward jump.
-8 bits signed value move to IP.
Example Example
mov ah,1 mov dx , offset str1
mov al,2 mov ah,9
jmp F1 int 21h
mov bh,7 F2:
mov bl,8 move ah,1
F1: int 21h
mov ah,2 jmp F2
mov dl , ‘@’
int 21h
Syntax
jmp dest
or
jmp near ptr dest
-destination is specified by a label.
-label must be within same segment.
-16 bits displacement address to IP.
-If we don’t use short or near ptr assembler automatically converts it into short or near.
-If intrasegment jumps only IP is changed.
i.e
IP =IP + dest
Or
IP =IP - dest
Inter-Segment Jumps
FAR JUMPS