0% found this document useful (0 votes)
30 views27 pages

Lecture 5 COAL (2) - Pages

Uploaded by

murshadbawag11
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)
30 views27 pages

Lecture 5 COAL (2) - Pages

Uploaded by

murshadbawag11
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
You are on page 1/ 27

Computer Organization &

Assembly Language
Lecture 4
Flags
3

Flags

Carry flag
Overflow
Direction Parity flag

Interrupt enable Auxiliary flag

Trap Zero
6 are status flags
Sign
3 are control flag
4 The Status Flags
1. Carry Flag:
Carry Flag is set to 1 when there is an unsigned overflow. For
example, when you add bytes 255 +
1 (result is not in range 0…255). When there is no overflow,
this flag is set to 0.Examples:
The Carry Flag is set to 1 when there is a carry out from MSB
on addition or there is a borrow into the MSB on subtraction.
Also affected by shift and rotate instructions.
0FFh + 11h = 110h (If a register can store only 1 byte, then
where to store the carry generated by MSB?)
 1000 0001b – 1000 0010b = 11111111b (How processor would know
a borrow is required to perform subtraction?)
5 Contd..
2. Parity Flag:
Parity Flag is set to 1 when there is even number of ones in
result, and to 0 when there is odd number of ones.
PE (Even Parity): If the byte of a result has even number of
one bits. For Even parity, PF = 1
PO (Odd Parity): If the byte of a result has odd number of
one bits. For Even parity, PF = 0
Examples:
1000 0001b – 1000 0010b = 11111111b (Number of one’s in
result = 8, so PF = 1)
6 Contd..
3. Auxiliary Carry Flag:
 Auxiliary Flag is set to 1 when there is an unsigned overflow
for low nibble (4 bits).
 The Auxiliary Carry Flag is set to 1 if there is a carry out from
bit 3 on addition, or a borrow into bit 3 on subtraction.
 Used in Binary Coded Decimal (BCD) Operations.
 Examples:
 1000 0001b – 0000 0010b = 01111111b (Borrow from bit 4 to
bit 3)
7 Contd..
4. Zero Flag:
 Zero Flag is set when the result is zero.
 Zero Flag is unset when result is non zero.
 Examples:
0FFh – 0FFh = 00h
8 Contd..
5. Sign Flag:
 Sign Flag is set to 1 when result is negative. When result is
positive it is set to 0. This flag takes the value of the most
significant bit.
 Examples:
0FFh – 0FFh = 00h (MSB = 0, PF = 0)
Contd..
9
6. Overflow Flag:
Overflow:
Range of numbers that can be represented in a computer is
limited.
Overflow Flag is set to 1 when there is a signed overflow. For
example, when you add bytes 100 + 50 (result is not in range
-128…127).
14 Logic Instructions
 To manipulate individual bits
 Binary Value 0 treated as false
 Binary Value 1 treated as true
 In Assembly Language:
 AND
 OR
 XOR
 NOT
 TEST
15 Truth Tables
a b a AND b a OR b a XOR b
0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0

a NOT a
0 1
1 0
16 Examples
1. 1010 1010 AND 1111 0000 = 1010 0000
2. 1010 1010 OR 1111 0000 = 1111 1010
3. 1010 1010 XOR 1111 0000 = 0101 1010
4. NOT 1010 1010 = 0101 0101
17 Syntax
AND destination, source
OR destination, source
XOR destination, source
 Destination:
 Stores result
 Can be Register or Memory Location
 Source:
 May be a Constant, Register or Memory Location
 Memory to memory operation not allowed
25 NOT Instruction
 Performs the one’s complement operation on the destination.
 Syntax:
NOT destination
 No effect on flags
 Example: Complement the bit in AX:
NOT AX
Multiplication
26
• MUL instruction is used with unsigned operands
• Unsigned multiplication of 128 and 255 = 32, 640.
• 2 bytes multiplied, product = 1 word (16 bits)
• AL is implied destination operand
• Source operand can be a register or variable (8 bits)
• 16-bit output is AX

• 2 words multiplied, product = 1 double word (32 bits)


• AX is implied destination operands
• Source operand can be a register or variable (16 bits)
• 32-bit output is DX:AX
MUL Instruction
27

• 8-bit multiplication:
MUL BL ; product = AX

• 16-bit multiplication:
MUL DX ; product = DX:AX

mov al,5
mov bl,10h
mul bl ; AX = 0050h

mov ax,500h
mov bx,100h
mul bx ; DX:AX = 00050000h
29
DIV Instruction
• Dividend is divided by divisor
• Result: Quotient and Remainder

• Byte Form:
• Dividend is AX
• Divisor can be 8-bit register or variable
• Quotient is AL, Remainder is AH

• Word Form:
• Dividend is DX:AX
• Divisor can be 16-bit register or variable
• Quotient is AX, Remainder is DX

• Status flag values are undefined


DIV Examples
30
mov ax,0083h ; dividend
mov bl,2 ; divisor
div bl ; AL = 41h, AH = 01h

mov dx,0 ; dividend, high


mov ax,8003h ; dividend, low
mov cx,100h ; divisor
div cx ; AX = 0080h, DX = 0003h
Divide Overflow
31

Happens when the quotient is too large to fit in the destination


register. Causes a processor interrupt.

mov dx,0050h ; dividend, high


mov ax,0000h ; dividend, low
mov cx,10h ; divisor
div cx ; quotient= 50000h, cannot
; fit in AX register
MUL (Flags)
32

Carry and Overflow flags are set when the product extends into its high
register:
mov ax,5000h
mov bx,10h
mul bx ; DX:AX = 00050000h
; CF=1, OF=1

mov ax,500h
mov bx,10h
mul bx ; DX:AX = 00005000h
; CF=0, OF=0
Variables In Emu8086

 Variable is a memory location. For a programmer it is much easier to have some value be
kept in a variable named "var1" then at the address 5A73:235B, especially when you
have 10 or more variables.
 name DB value

name DW value

DB - stays for Define Byte.


DW - stays for Define Word.
 name - can be any letter or digit combination, though it should start with a letter. It's
possible to declare unnamed variables by not specifying the name (this variable will have
an address but no name).
 value - can be any numeric value in any supported numbering system (hexadecimal,
binary, or decimal), or "?" symbol for variables that are not initialized.
 VAR1 DB 7
 var2 DW 1234h
 MOV AL, var1
 MOV BX, var2

You might also like