It2623 Module6
It2623 Module6
TYPES OF PROGRAMMING
LANGUAGE
• Low level language
• Mid level language
• High level language
Advantages of high level Advantages of low level
over low level language over high level language
• Easy to learn • Compact code
• Predefined functions • Speed
• Portability • flexible
Assembly language is
specific to one
ASSEMBLING PROGRAMS
microcontroller
CONDITIONAL FLAGS
1. Carry Flag
2. Auxiliary Flag
3. Sign Flag
4. Parity Flag
5. Zero Flag
6. Overflow Flag
TYPES 14
• Conditional flags
• Control flags
CONDITIONAL FLAGS
• CARRY FLAG - An addition causes this flag to be set to 1 if there is a carry out
of the MSB, and a subtraction causes it to be set to 1 if a borrow is needed.
EXAMPLE:
BAH + 09H
BAH
= 1011 10102
+ 09H
0000 10012
C3H
1100 0011
CF = 0
CONDITIONAL FLAG
Auxiliary Flag - This flag is used exclusively for BCD arithmetic. It is set to 1 if
there is a carry out of bit 3 (b3) during an addition or a borrow by bit 3 during
a subtraction.
CF = 0 AF = 0
CONDITIONAL FLAG
Sign Flag - This is equal to the MSB of the result of the previous operation. 0 if
positive, 1 if negative.
CF = 1 AF = 0 SF =0
CONDITIONAL FLAG
• Parity Flag - This is set to 1 if the low-order 8 bits of the result of the previous
operation contain an even number of 1s. Otherwise, it is reset to 0.
• Example
69H + F8H
CF = 1 SF = 0 (+)
69H 0110 1001
+F8H 1111 1000 AF = 1 PF = 0 (odd)
161H 10110 0001
CONDITIONAL FLAG
Zero Flag - This is set to 1 if the result of the previous operation is zero and 0 if
the result is nonzero.
Example:
8AH – 97H CF = 1 SF = 1 ZF = 0
AF = 0 PF = 1
8AH 1000 1010
-97H - 1001 0111
FF3H 11111 0011
CONDITIONAL FLAG
Overflow Flag - This is set to 1 if an overflow occurs, i.e., a result is out of range.
More specifically, for addition this flag is set to 1 when there is a carry into the
MSB and no carry out of the MSB or vice-versa. For subtraction, it is set to 1,
when the MSB needs a borrow and there is no borrow from the MSB, or vice-
versa.
B7 B6
Example: 1
01
78H 0111 1000 CF = 0 PF = 0 ZF = 0
01
+ 56H 0101 0110 AF = 0 OF = 1 10
SF = 1
CEH 1100 1110
EXAMPLE
Given ABH + 9AH; derive the values of the conditional flags
MEMORY SEGMENTATION
In memory, data is stored as bytes.
Each byte has a specific address.
Intel 8086 has 20 lines address bus.
With 20 address lines, the memory that can be addressed is 220 bytes.
220 = 1,048,576 bytes (1 MB).
8086 can access memory with address ranging from 00000 H to FFFFF H.
26
MEMORY SEGMENTATION
• In 8086, memory has four different types of segments.
• These are:
• Code Segment
• Data Segment
• Stack Segment
• Extra Segment
27
SEGMENT REGISTERS
Each of these segments are addressed by an address stored in
corresponding segment register.
These registers are 16-bit in size.
Each register stores the base address (starting address) of the
corresponding segment.
Because the segment registers cannot store 20 bits, they only store the
upper 16 bits.
28
SEGMENT REGISTERS
How is a 20-bit address obtained if there are only 16-bit registers?
The 20-bit address of a byte is called its Physical Address.
But, it is specified as a Logical Address.
Logical address is in the form of:
Base Address : Offset
EXAMPLE
• The value of Data Segment Register (DS) is 2222 H.
• To convert this 16-bit address into 20-bit, the BIU appends 0H to the LSB of the
address.
• After appending, the starting address of the Data Segment becomes
22220H.
30
EXAMPLE (CONTD.)
• If the data at any location has a logical address specified as:
2222 H : 0016 H
EXAMPLE (CONTD.)
• To calculate the effective address of the memory, BIU uses the following
formula:
Effective Address = Starting Address of Segment + Offset
• To find the starting address of the segment, BIU appends the contents of
Segment Register with 0H.
• Then, it adds offset to it.
32
EXAMPLE (CONTD.)
• Therefore:
• EA = 22220 H
+ 0016 H
------------
22236 H
33
QUESTION
The contents of the following registers are:
CS = 1111 H
DS = 3333 H
SS = 2526 H
IP = 1232 H
SP = 1100 H
DI = 0020 H
Calculate the corresponding physical addresses for the address bytes in CS, DS
and SS.
36
1. CS = 1111 H
SOLUTION
The base address of the code segment is 11110 H.
Effective address of memory is given by 11110H + 1232H =
12342H.
2. DS = 3333 H
The base address of the data segment is 33330 H.
Effective address of memory is given by 33330H + 0020H =
33350H.
3. SS = 2526 H
The base address of the stack segment is 25260 H.
Effective address of memory is given by 25260H + 1100H =
26360H.
GENERATING MEMORY ADDRESS
• Physical Address = Segment address + offset address
Segment Register/ offset Physical Address
DS (data segment) AX, BX, CX,DX, =(DS*10H)+register/OFFSET
displacement, DI, SI
SS(stack segment) BP, SP =(SS*10H) + BP/SP
CS(code segment) IP = (CS*10H) + IP
ES (extra segment) DI = (ES*10H) + DI
EXAMPLE
1. Given the following, compute for the Physical address.
DS = 1234H AX=0500H
Solution:
PA = (DS*10H) + 0500H
= 12340H + 0500H
= 12840H
2. Given SS= 3B0AH; SP = 08ABH
Solution:
PA =(SS*10H) + SP
= 3B0A0H
08ABH
3B94BH ->[LB]
3B94CH ->[HB]
EXAMPLE
Given: ES = 1768H, DI = 0809H, compute for the physical address.
PA = (ES *10H) +DI
= 17680H
+ 00809H
17E89H
LB -> [17E89H]
HB->[17E8AH]
THE STACK
PUSH POP
Bottom of the Stack = SS x 10H + FFFFH Bottom of the Stack = SS x 10H + FFFFH
SS range = SS ~BOS SS range = SS ~BOS
Top of the Stack = SS x 10H + SP Top of the Stack = SS x 10H + SP
LB ->[TOS-2] LB<-[TOS]
HB ->[TOS-1] HB<-[TOS+1]
NEW TOS = TOS -2 NEW SP= [SP+2]
NEW SP = SP-2 NEW TOS = [TOS+2]
EXAMPLE
PUSH BX
Assume: BX = 4567H SS= 2765H SP = 3574H
Determine the address of the ff: BOS, TOS, SS range, New SP, BL and BH
location
TOS = (SS *10H) + SP
Solution: = 27650H
HB ->[TOS-1]
BOS = (SS*10H)+FFFFH + 03574H
BH = 45H ->[2ABC3H]
= 27650H 2ABC4H
+ 0FFFFH New SP = [SP-2]
LB ->[TOS-2] = [3572H]
3764FH BL = 67H ->[2ABC2H]
SS Range: 2765H ~ 3764FH New TOS = [TOS-2]
= [2ABC2H]
THE STACK
• POP CX
• Assume CX = 3467H, SS= 567BH SP=0078H
Compute for the ff: BOS, TOS, SS RANGE, NEW SP, LB AND HB ADDRESS