SlideShare a Scribd company logo
1 of 36
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 1
MODULE-3
TOPICS
3.1Signed Numbers and Strings
3.1.1 Signed Number Arithmetic operations
3.1.2 String Operations
3.2 Memory and Memory Interfacing
3.2.1 Memory Address Decoding
3.2.2 Data integrity in RAM & ROM
3.2.3 16-bit memory Interfacing
3.3 8255 I/O Programming
3.3.1 I/O addresses MAP of x86 PC’S
3.3.2 Programming and interfacing the 8255
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 2
3.1.1 Signed Number Arithmetic operations:
Signed Numbers:
 MSB bit is used to indicate the sign of the number.
 For positive (+) number, MSB bit is 0
 For Negative (-) number, MSB bit is 1
Signed Byte Operands:
 8-bits are used to represent signed byte operands
 Bit 7 (D7) is the Sign bit
 Bits D0-D6 are used for the magnitude of the number.
 Range of signed byte operands is -128 to +127
Steps to for negative number representation:
1. Write magnitude of the number in 8-bits(no sign)
2. Invert each bit.
3. Add 1 to it.
E.g. 1find the binary representation of -5
1. Write magnitude of number in 8-bits  5 = 0000 0101
2. Invert each bit 1111 1010
3. add 1 1111 1010 + 1 = 1111 1011
Hence -5 = 1111 1011 (hex value = FBH)
E.g.2 Show -34H as it is represented internally
1. Write magnitude of number in 8-bits 0011 0100
2. Invert each bit 1100 1011
3. Add 1 1100 1011 + 1= 1100 1100
Hence -34H = 1100 1100 (hex value = CCH)
E.g. 3 Show the representation for -12810
1. Write magnitude of number in 8-bits128 = 1000 0000
2. Invert each bit0111 1111
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 3
3.Add 1 0111 1111+1 = 1000 0000
Hence -128 = 1000 0000
Word-Sized Signed Numbers:
 16-bits are used for Word-sized signed numbers.
 Bit 15 (D15) is the Sign bit
 Bits D0-D14 are used for the magnitude of the number
 Range of word-sized signed numbers is -32768 to +32767
In 8-bit operations, overflow occurs when
1. There is a carry from D6 to D7 but no carry out of D7
2. There is a carry from D7 out but no carry from D6 to D7
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 4
Overflow in 16-bit operations:
In 16-bit operation, OF is set to 1 in either of two cases
1. There is a carry from D14 to D15 but no carry out from D15
2. There is a carry from D15 out but no carry from D14 to D15
CBW (convert byte to word):
 CBW will copy D7 (sign bit) to all bits of AH
7 0 7 0
AH AL
E.g.1 MOV AL, +96; AL = 0110 0000
CBW ; AH = 0000 0000 and AL = 0110 0000
E.g.2
MOV AL,-2 ; AL = 1111 1110
CBW ; AH = 1111 1111 AL = 1111 1110
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 5
CWD (convert word to Double Word):
 CWD copies D15 of AX to all bits of DX register.
15 0 15 0
DX AX
E.g. MOV AX, +260 ; AX= 0000 0001 0000 0100 or AX = 0104H
CWD ; DX = 0000 0000 0000 0000 = 0000H
Program: To Handle Overflow problem
.MODEL SMALL
.DATA
NUM1 DB +96
NUM2 DB +70
RESULT DB ?
.CODE
MOV AX,@DATA
MOV DS,AX
MOV AH,0 ; AH=0
MOV AL, NUM1 ; AL=+96
MOV BL, NUM2 ;BL=+70
ADD AL,BL ;AL=AL+BL
JNO OVER ; JUMP to OVER if OF=1
MOV AL,DATA2 ; AL=+70
CBW ; AX=+70
MOV BX,AX ;BX=+70
MOV AL,DATA1 ; AL=+96
CBW ;AX=+96
ADD AX,BX ; AX= AX+BX , AX= 166
OVER:MOV RESULT,AX; store AX value to RESULT
INT 3
END
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 6
IDIV (signed number division) : IDIV is used for signed number division.
There are four types of division operations
Division Dividend Divisor Quotient Remainder
Byte / Byte AL =byte CBW Register or memory AL AH
Word / Word AX= word CWD Register or memory AX DX
Word /Byte AX=word Register or memory AL AH
Double word/ Word DX AX = double word Register or memory AX DX
Example for Byte / Byte Division +9 / +2
MOV AL, +9 ;AL = 0000 1001
CBW ;AX= 0000 0000 0000 10001
MOV BL, +2 ;BL = 0000 0010
IDIV BL ;AX / BL AL = +4 AH = +1
Write a Program to find the average of temperature
.MODEL SMALL
.DATA
TEMP DB +13, -10,+19, +14, -18, -9, +12, -19, +16 TEMP si
AVERAGE DW ?
.CODE
MOV AX,@DATA
MOV DS,AX
MOV CX,9 ; CX=9
MOV BX,0; BX is used to store the result
MOV SI, OFFSET TEMP; Si points to location temp
BACK: MOV AL,[SI] ; move data from location pointed by SI
CBW ; convert byte to word
ADD BX, AX ; BX= BX +AX
INC SI ; SI points to next location
LOOP BACK ; decrement CX , jump to BACK if CX≠0
MOV AL,9 ; AL =9
CBW ; AX=9
MOV CX,AX ; CX=9 AVERAGE
MOV AX,BX ; AX = +18
CWD ; DX AX =+18
IDIV CX ; (DX AX) / CX  +18 / 9 AX= +2 DX= 0
MOV ACERAGE, AX ; AVERAGE = +2
MOV AH,4CH
+13
-10
+19
+14
-18
-9
+12
-19
+16
+2
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 7
INT 21H
END
IMUL (Signed Number Multiplication): It is used for signed number multiplication
There are four types of multiplication operations
Multiplication Operand 1 Operand 2 Result
Byte × Byte AL 8-bit register or memory AX
Word × Word AX 16-bit Register or memory DX AX
Word × Byte AL = Byte CBW 16-bit Register or memory DX AX
Signed Number Comparison:
Syntax: CMP Destination, Source
Operation: Destination – Source
Flags Affected: OF, ZF, SF
Case 1: Destination > source OF= SF or ZF =0
Case 2: Destination = source ZF=1
Case 3: Destination < Source OF = negation of SF
Conditional jump instructions used for signed comparison are
Mnemonic Function Condition
JG Jump Greater Jump if OF=SF or ZF=0
JGE Jump greater or Equal Jump if OF=SF
JL Jump Less Jump if OF = inverse of SF
JLE Jump Less or Equal Jump if OF=inverse of SF or ZF=1
JE Jump equal Jump if ZF=1
Program: To find the Lowest temperature
.MODEL SMALL TEMP SI
.DATA
TEMP DB +13, -10, +19, +14, -18, -9, +12, -19, +16
LOWEST DB ?
.CODE
MOV AX, @DATA
MOV DS, AX
MOV CX,8 ; CX=8 , 8 compariosons
MOV SI, OFFSET TEMP ; SI points to location TEMP
MOV AL,[SI] ;moves data to AL from location pointed by SI
BACK: INC SI ; SI points to next location
CMP AL, [SI] ; compare AL with data pointing by SI
JLE SEARCH ;jump to search if AL≤[SI] LOWEST
+13
-10
+19
+14
-18
-9
+12
-19
+16
-19
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 8
MOV AL, [SI] ; move data from location [SI] to AL if SI≤AL
SEARCH: LOOP BACK ; decrement CX and jump to SEARCH if CX≠0
MOV LOWEST, AL ; store the lowest temperature in AL to LOWEST
MOV AH,4CH
INT 21H
END
3.1.2 String operations:
There is a group of instructions to perform operations on strings
SI, DI Registers:
 SI and DI registers ae used by string instructions
 When DF =0 SI and DI automatically increment
 WHEN DF=1 SI and DI automatically decrement.
CLD (clear direction Flag): this instruction is used to clear the direction flag DF=0
STD (set direction flag): this instruction is used to set direction flag DF=1
MOVSB (move string byte):
• This instruction transfers BYTE from the data segment location pointed by SI to extra
segment location pointed by DI.
• After the byte transfer, the contents of SI and DI are incremented if DF = 0 or
decremented if DF = 1.
Syntax: MOVSB
Function: ES : [DI]  DS : [SI]; SI = ± 1, DI = DI ± 1
E.g. If DF flag = 0, SI = 0001H, DS = 1000H, DI=0001 ES=2000H
MOVSB ; the byte data in memory location 10001H will be transferred to location 20001h
and contents of SI and DI increment by 1.
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 9
MOVSW (move string word):
• This instruction transfers word from the data segment location pointed by SI to extra
segment location pointed by DI.
• After the word transfer, the contents of SI and DI are incremented if DF = 0 or
decremented if DF = 1.
Syntax: MOVSW
Function: ES : [DI]  DS : [SI]; SI = ± 2, DI = DI ± 2
E.g. If DF flag = 0, SI = 0001H, DS = 1000H, DI=0001 ES=2000H
MOVSW ; the byte word in memory locations 10001H and 10002H will be transferred to
locations 20001h and 20002H and contents of SI and DI increment by 2.
LODSB:
• LODSB transfers a byte from the data segment memory location pointed by SI to the AL.
• After the byte transfer, the contents of SI increment if D = 0 or contents of SI decrement
if D = 1.
Syntax: LODSB
Function: AL  DS : [SI]; SI = SI ± 1
E.g. If DF flag = 0, SI = 0001H and DS = 1000H
LODSB ; the byte data stored in memory location 10001H will be transferred to
AL, because DF =0 the contents of SI increment by 1.
LODSW:
• LODSW transfers a word from the data segment memory location pointed by SI to the
AX.
• After the word transfer, the contents of SI & DI increment if DF = 0 or contents of SI &
DI decrement if DF = 1.
Syntax: LODSW
Function: AX  DS : [SI]; SI = SI ± 2
E.g. If D flag = 0, SI = 1000H and DS = 1000H
LODSW ; the word data stored in memory location 11000H and 11001H will be
transferred to AX, because D =0 the contents of SI increment by 2.
STOSB:
• STOSB instruction stores byte in AL in to the extra segment memory location addressed
by DI.
• After the byte is stored, the contents of DI increment if DF= 0 or decrement if DF = 1.
Syntax: STOSB
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 10
Function: ES : [DI]  AL; DI = DI ± 1
E.g. If DF=0, ES=2000H and DI=0001H AL =10H
STOSB; it stores the value 10H in location 20001H and DI = 0002H
STOSW:
• STOSW instruction stores word in AX in to the extra segment memory location
addressed by DI.
• After the word is stored, the contents of DI increment if DF= 0 or decrement if DF = 1.
Syntax: STOSW
Function: ES : [DI]  AX; DI = DI ± 2
E.g. If DF=0, ES=2000H and DI=0001H AX =2010H
STOSB; it stores the value 10H in location 20001H and 20H in location 20002Hand DI =0003H
REP (repeat):
 REP (repeat) is a prefix.
 REP is added to any string data transfer instruction except the LODS instruction.
 REP decrements CX by1 each time the string instruction executes.
 After CX decrements the string instruction repeats.
 If CX reaches a value of 0, the string instruction terminates.
e.g. MOV CX, 100
REP STOSB ; this instruction repeats 100 times.
Program: (i) use STOSB to store byte AAH in 100 memory locations
(ii) Use LODSB to test contents of each location to see if AAH is there, if test
Fails, system should display the message “Bad Memory”
.MODEL SMALL
.DATA
MSG DB “ Bad Memory$”
MEM_AREA DB 100 DUP(?)
.CODE
MOV AX, @DATA
MOV DS, AX
MOV ES, AX
CLD ; DF=0
MOV CX, 100 ;CX=100
MOV DI, OFFSET MEM_AREA ; DI points to memory area reserved to store AAH
MOV AL, 0AAH ; AL=AAH
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 11
REP STOSB ; stores AAH in memory location ES:[DI] DI = DI +1
MOV SI, OFFSET MEM_AREA ; SI points to memory area in which 100 AAH are stored
MOV CX,100 ;CX=100
AGAIN: LODSB ; it loads value in memory location DS:[SI] to AL
CMP AL, 0AAH ; compare AL value with AAH
JNE OVER ; if AL≠AAH jump to over
LOOP AGAIN ; decrements CX jump to AGAIN if CX≠0
JMP EXIT ; jump to exit
OVER: LEA DX, MSG ; display a message “Bad Memory”
MOV AH,09H
INT 21H
EXIT: MOV AH,4CH ; exit to DOS
INT 21H
END
Program: Using String instructions write a program that transfers a block of 20 bytes of
data
.MODELSMALL
.DATA
BLOCK1 DB ‘ABCDEFGHIJKLMNOPQRST’
BLOCK2 DB 20 DUP (?)
.CODE
MOV AX, @DATA
MOV DS,AX ; Initialize data segment
MOV ES,AX ; initialize extra segment
CLD ; DF=0
MOV SI, OFFSET BLOCK1 ; SI points to BLOCK1
MOV DI, OFFSET BLOCK2 ; DI points to BLOCK2
MOV CX, 20 ; CX=20
REP MOVSB ; moves 20 bytes form data segment to extra segment
MOV AH, 4CH
INT 21H
END
REPE (repeat while equal) or REPZ (repeat while zero) :
• The REPE prefix is used for string instruction.
• REPE causes the string instruction to repeat until CX register reaches 0 or until unequal
condition occurs (ZF=0)
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 12
REPNE (repeat while not equal) or REPNZ (repeat while not zero) :
• The REPNE prefix is used for string instruction.
• REPNE causes the string instruction to repeat until CX register reaches 0 or until equal
condition occurs (ZF=1).
CMPSB (compare string byte):
• This instruction compares the byte in memory location (DS; SI) with the byte in memory
location (ES:DI).
• It performs subtraction of the byte in ES:DI from the byte in DS:SI.
• CMPSB is normally used with REPE or REPNE prefix.
Syntax: CMPSB
Function: flags  DS:SI – ES : DI; SI = SI ± 1; DI = DI ± 1
Flags affected: AF, CF, OF, PF, SF, ZF
Example: write a program to compare the string of length 10 in the Data Segment with the
string of length 10 in the Extra Segment.
MOV SI, OFFSET STR1
MOV DI, OFFSET STR2
CLD
MOV CX, 10
REPE CMPSB
CMPSW (compare string Word):
• This instruction compares the word in memory location (DS; SI) with the word in
memory location (ES:DI).
• It performs subtraction of the word in ES:DI from the word in DS:SI.
• CMPSW is normally used with REPE or REPNE prefix.
Syntax: CMPSW
Function: flags  DS:SI – ES : DI; SI = SI ± 2; DI = DI ± 2
Flags affected: AF, CF, OF, PF, SF, ZF
Program: Assuming there is a spelling of “Europe” in a electronic dictionary and user
types in “Euorope”, write a program that compares these two and displays the following
message, depending on the result
i) if they are equal, display “the spelling is correct”
ii) if they are not equal, display “Wrong spelling”
.MODEL SMALL
.DATA
STR1 DB “Europe”
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 13
STR2 DB “Euorope”
MSG1 DB “ The spelling is correct$”
MSG2 DB “Wrong Spelling$”
.CODE
MOV AX,@DATA
MOV DS,AX
MOV ES,AX
CLD ; DF=0
MOV SI,OFFSET STR1 ; SI points to STR1
MOV DI, OFFSET STR2 ; DI points to STR2
MOV CX,6 ; CX=6
REPE CMPSB ; repeat CMPSB until CX=0 or unequal condition occurs
JE OVER ; if strings are equal jump to OVER
LEA DX, MSG2 ; display message “wrong Spelling”
JMP DISP
OVER: LEA DX,MSG1 ; display message “ the spelling is correct”
DISP: MOV AH, 09H
INT 21H
MOV AH, 4CH
INT 21H
END
SCASB (scan string byte):
• This instruction compares the contents of AL with the contents of memory location (ES:
DI).
• It subtracts the contents of memory location (ES : DI) from AL without affecting AL and
memory location.
Syntax: SCASB
Function: flags  AL - ES :DI , DI = DI ± 1
Flags affected: AF, CF, OF, PF, SF, ZF
Example: program to scan letter ‘G’ in a string “Mr. Gones”
STRING DB ‘Mr. Gones’
CLD
MOV CX, 09
MOV AL, ‘G’
REPNE SCASB
SCASW (scan string word):
• This instruction compares the contents of AX with the contents of memory location (ES :
DI).
• It subtracts the contents of memory location ( ES : DI) from AX without affecting AL
and memory location.
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 14
Syntax: SCASW
Function: flags  AX - ES :DI , DI = DI ± 2
Flags affected: AF, CF, OF, PF, SF, ZF
Replacing the Scanned character: SCASB can be used to search for a character in string, and if
it is found it will be replaced with the desired character.
Program: write a program that scans the string “Mr. Gones” and replaces the “G” with letter “J”
then displays correct name
.MODELSMALL
.DATA
STR DB “Mr. Gones$”
.CODE
MOV AX, @DATA
MOV DS, AX
MOV ES, AX
CLD ; DF=0
MOV DI, OFFSET STR ; DI points to STR
MOV CX,09 ; CX=9, 9 characters to be scanned
MOV AL, ‘G’ ; AL=G
REPNE SCASB ; scan the string until CX=0 or until G is found
JNE OVER ; if G is not found jump to over
DEC DI ; if G is found decrement DI
MOV [DI], ‘J’ ; replace G with J
OVER: LEA DX, STR ; display corrected string
MOV AH,09H
INT 21H
MOV AH, 4CH ; exit to DOS
INT 21H
END
XLAT (translate):
This instruction converts the contents of the AL register into a number stored in a memory table.
1. XLAT first adds the contents of AL to BX to form a memory address within the data
segment.
2. It then copies the contents of this address into AL.
Syntax: XLAT
Operation: AL  DS : [BX+AL]
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 15
E.g. TABLE BX
MOV BX, OFFSET TABLE
MOV AL, 03 ; AL=3
XLAT ; AL=33
In the above example, the data in memory location [AL+BX] 33 is moved to AL
Code conversion using XLAT: ASCII BX
XLAT can be used to translate hex keys to ASCII values
.DATA
ASCII DB ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’
HEX_VALUE DB 4 HEX_VALUE
ASC_VALUE DB ? ASC_VALUE
.CODE
MOV BX, OFFSET ASCII ; BX points to ASCII table
MOV AL, HEX_VALUE ; AL=4
XLAT ; AL= [4+BX] i.e. AL= ascii value of 4 (34)
MOV ASC_VALUE, AL ; 34 is moved to location ASC_VALUE
3.2.1Memory Address Decoding:
Address decoding: Selecting desired location when CPU sends the memory address
Simple Logic Gate as address decoder:
30
31
32
33
34
31
32
33
34
35
36
37
39
41
42
43
30
44
45
46
47
4
34
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 16
 Memory size is 32K ×8 (32K bytes), to access any location in memory the pin CS (Chip
Select) must be activated.
 Data bus is used to connect the CPU to data pins of the memory.
 Control signals MEMR (memory read) and MEMW (memory write) are connect to OE
(output enable) and WR (write) pins of memory.
 The lower address bits (A14- A0) are connected directly to memory.
 The upper address bits (A19-A15) are used to active CS pin.
 To read or write a data into memory CS pin must be activated.
Address range of memory chip in the above figure is
Problem: find the address range of the memory shown below
In the above figure, to activate CS, output of NAND gate must be low, to generate low output
A19-A16 must be equal to 1001, hence starting address is 90000H and end address is 9FFFFH
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 17
To find the size of the memory in the above figure
 Subtract starting address and end address
 Add 1 to result.
 Convert Hexadecimal result to decimal
 Divide the decimal result by 1024 to get the memory size in K bytes.
9FFFFH-90000H = 0FFFFH + 1 = 10000H
Decimal value of 10000H is 65,536
65536 / 1024 = 64 K bytes
74LS138 Chip:
 74LS138 chip has 3 inputs A, B and C and 8 outputs (Y7 – Y0)
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 18
 Eight Y outputs can be connected to 8 memory blocks.
 G2A, G2B and G1 pins can be used to select address or control signal.
Using 74LS138 as Decoder:
 A15- A0 from CPU are connected directly to memory.
 A18-A16 are connected to A, B and C inputs of 74LS138
 A19 is connected to G1 pin.
 G2A, G2B are grounded.
 Output Y4 is connected to CS or CE pin of memory.
 To select Y4 , C=1 B=0 A=0 i.e. 100 (4)
Address range of the memory chip is
First address = C0000H
End Address=CFFFFH
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 19
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 20
3.2.2Data Integrity in RAM and ROM:
• Ensuring data retrieved is same as the data stored is called data integrity.
• There are many ways to maintain data integrity based on the type of storage.
• CHECKSUM method is used for ROM, PARITY BIT method is used for DRAM
• For mass storage devices like Hard disks CRC (cyclic redundancy check) method is used.
Checksum Byte Method:
• One of the causes of ROM corruption is current surge, either when PC is ON or during
operation.
• Checksum method used checksum byte, it is a byte that is added to the end of a series of
bytes of data.
Steps to calculate Checksum Byte:
1. Add the bytes together and drop the carries
2. Take the 2’s complement of the total sum, and that is the checksum byte, which is last
byte of the stored information.
Checksum Operation:
Add all bytes including checksum byte, the result must be zero, if it is not zero, one or
more bytes have been changed (corrupted).
Problem: Assume that we have 4 bytes of hexadecimal data: 25H, 62H, 3FH, 52H
i) find checksum byte
ii) Perform checksum operation to ensure data integrity.
iii) If the second byte 62H had been changed to 22h, show how checksum detects the error.
Solution:
i) Checksum byte is calculated by adding all the bytes by dropping carries and take 2’s
complement of the result
25H
62H
3FH
52H
1 18H
Ignore the carry 1, and 2’s complement of 18H is E8H
Hence, checksum byte = E8H
ii) to perform check sum operation, all bytes including checksum byte is added by dropping
carries if result is 0 no byte is corrupted.
25H+62H+3FH+52H+E8H= 00H
iii) if second byte is changed from 62H to 22H
25H+22H+3FH+52H+E8H= C0H  result is not zero, hence some byte is corrupted
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 21
Problem: Assuming that the last byte of the following data is the checksum byte, show whether
data has been corrupted or not: 28H, C4H, BFH, 9EH, 87H, 65H, 83H, 50H, A7H and 51H
Sol) if the sum of all bytes including checksum byte is 0, no byte is corrupted.
28H+C4H+ BFH+ 9EH+87H+ 65H+83H+50H+A7H+51H = 00H (data not corrupted)
DRAM Memory Banks:
The arrangement of DRAM chips on the system is called as DRAM memory banks
e.g. 64K bytes of DRAM can be arranged as one bank of 8 IC chips of 64K×1
OR
4 banks of 16×8 organization
Figure below shows the memory banks of 640K bytes of DRAM using 256K and 1M DRAM
chips.
Use of parity bit in DRAM error detection:
 A parity bit is added to every byte in memory to ensure data integrity.
 Parity bit method is used for error detection in DRAM
Types of errors in DRAM:
There are two types of errors in DRAM,
1. Soft error
2. Hard Error
Soft Error: if a single bit is changed from 1 to 0 or from 0 to 1 is called soft error
Hard Error: if few bits or entire row of bits get stuck to 1 or 0 permanently is called hard error.
74S280 parity bit generator and checker:
 This chip has 9 inputs (A-I) and 2 outputs.
 If 9 inputs have an odd number of 1s, the odd output is high.
 If 9 inputs have even number of 1s, the even output is high
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 22
The truth table of 74280 is shown below.
3.2.3 16-bit Memory Interfacing:
• In 16-bit CPU, the memory locations 00000H – FFFFFH are arranged as ODD and
EVEN bytes as shown below
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 23
• A0 and BHE (Bus high enable) can be used to select ODD or EVEN byte.
Memory cycle time and inserting wait states:
• The fixed amount of time provided by CPU to access memory is called Bus Cycle time
or Memory Cycle Time.
• The time from when CPU provides the address at its address pins to when data is
expected at its data pins is called Memory Read Cycle Time.
• Memory cycle time is 2 clocks
• If memory is slow, extra time can be requested, this extra time is called Wait State (WS)
e.g. if clock frequency or speed = 20MHZ
clock time = 1 / 20MHz = 50ns
Memory cycle time = 2 × 50ns = 100ns
Factors slow down the CPU:
• The time taken for address signals to go from CPU to memory, plus time taken by data to
travel from memory to CPU, this delay is called path delay.
• The time required to get the data out of memory chip.
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 24
Accessing word in 8-bit system:
 In 8-bit system, two memory cycles are required to access any word (odd or even)
Figure below shows the accessing word in 8-bit system
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 25
Accessing Word in 16-bit system:
 In 16-bit system, one memory cycle is required to access word at even memory address.
 Two memory cycles are required to access a word at odd address.
Example: MOV AX, [F617], assume that DS= F000H
The above instruction moves the contents of ,memory locations FF617H and FF618H are
moved to register AX, in the first cycle, the contents of location FF617H are moved to AL
and contents of location FF618H are moved to register AH
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 26
BUS Bandwidth:
• The rate of data transfer is called Bus Bandwidth.
• The wider the data bus the higher the bus bandwidth.
Two ways to increase the bandwidth:
 Use wider data bus
 Reduce the bus cycle time
Bus Bandwidth = (1/ bus cycle time) × bus width in bytes
8088/8086 Input & output instructions:
IN for 8-bit ports:
• This instruction transfers data from an external input device into register AL.
• Port address is specified in the instruction
Format: IN AL, port # ; port # is the address of the port
E.g. IN AL, 22H; it moves 8-bit data from the port 22H to AL
IN for 16-bit ports:
 This instruction transfers data from an external input device into register AL.
 DX contains 16-bit port address.
Format: MOV DX, port# ; move 16-bit port address to DX
IN AL, DX ; transfers a byte from the port (DX contains port address) to AL
E.g MOV DX, 1234H
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 27
IN AL, DX ; it moves 8-bit data from port 1234H to AL
OUT for 8-bit ports:
 This instruction transfers data from AL to an external output device
Format: OUT port #, AL ; port# is address of the port
e.g. OUT 55H, AL; moves 8-bit data from AL to port 55H
OUT for16-bit ports:
 This instruction transfers data from AL to an external output device
Format: MOV DX, PORT# ; move 16-bit port address to DX
OUT DX, AL ;transfers byte from AL to port (DX contains port address)
E.g. MOV DX, 4321H ; move 16-bit port address (4321H) to DX
OUT DX, AL ; transfers 8-bit data from AL to port 4321H
Program: transfer the value 36H to port 43H
MOV AL, 36H ; move the value 36H to AL
OUT 43H, AL ; transfers AL content to port 43H
Program to send values 55H and AAH to port address 300H (16-bit address)
BACK:MOV DX, 300H
MOV AL, 55H
OUT DX,AL
MOV AL,0AAH
OUT DX, AL
JMP BACK
Program to get data from port address 300H and send it to port address 302H
MOV DX, 300H
IN AL, DX
MOV DX, 302H
OUT DX, AL
Program: In a given 8088 based system, port address 22H is an input port for
monitoring the temperature, write assembly language instructions to monitor that port
continuously for the temperature of 100 degrees, if it reaches 100, BH should contain
‘Y’
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 28
BACK: IN AL, 22H ; get temperature from port 22H
CMP AL, 100 ; compare temperature in AL with 100
JNZ BACK ; if temp≠100 jump back
MOV BH, ‘Y’ ; if temp = 100 move ‘Y’ to BH
3.3.2 Programming and Interfacing the 8255: (very important question)
• It is 40-pin chip
• It has three ports A, B C
• Each port can be used as either input or output
Pin diagram of 8255:
PortA (PA7-PA0): This 8-bit port can be used as either input or output
PortB (PB7-PB0): It can be used as either input or output
PortC(PC7-PC0):
 It can be used as either input or output
 It can also be split into two parts CU (upper bits PC7-PC4) CL ( lower bits PC3-PC0)
D0-D7 data pin:
 The data pins of the 8255 are connected to the data pins of the microprocessor allowing it
to send data back and forth between the microprocessor and the 8255 chip.
A0, A1 and CS:
 CS (chip select) selects the entire chip.
 Address pins A0 and A1 select specific port with in 8255
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 29
RD and WR:
 These two are active low inputs to 8255
 RD enables the read operation of 8255
 WR enables the write operation of 8255
RESET:
 This is active high input of 8255
 When reset is activated, all ports are initialized as input ports.
Mode selection of 8255:
The ports of the 8255 can be programmed in three different modes.
1) Mode 0
2) Mode 1
3) Mode 2
Mode 0:
 In this mode, any of the ports A,B, CL and CU can be programmed as input or output.
Mode 1:
 In this mode, ports A and B can be used as input or output ports with handshaking
capabilities.
 Handshaking signals are provided by the bits of port C.
Mode 2:
 In this mode, port A can be used as bidirectional port with handshaking capabilities
whose signals are provided by port C.
Control word Format (I/O mode):
 Control register is used to the select operation mode of the ports.
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 30
Problem: write a control word if PA = out, PB = IN , PC0-PC3 =IN and PC4-PC7 = OUT.
Control word = D7 D6 D5 D4 D3 D2 D1 D0
1 0 0 0 0 0 1 1
Control word = 8 3H
Write a program to get data from port A and send it to port B, In addition data from PCL
is sent out to the PCU, use port address 300H-303H for the 8255 chip.
Program:
.MODEL SMALL
.DATA
PA EQU 300H
PB EQU 301H
PC EQU 302H
CR EQU 303H
.CODE
MOV AX, @DATA
MOV DS, AX
MOV AL, 83H ; move control word (83H) to AL
MOV DX, CR ; move control register address to DX
OUT DX, AL ; transfer AL value to Control register ( DX contains CR address)
MOV DX, PA ; move port A address to DX
IN AL, DX ; transfer data from port A to AL
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 31
MOV DX, PB ; move port B address to DX
OUT DX, AL ; transfer Al value to port B
MOV DX, PC ; move port C address to DX
IN AL, DX ; transfer data from Port C to Al
AND AL, 0FH ; mask upper bits of AL
MOV CL, 4 ; CL=4
ROL AL, CL ; rotate AL contents left side by 4 positions
OUT DX, AL ; send AL value to Port C
MOV AH, 4CH
INT 21H
END
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 32
b) control word to set port A as input, B as output and all bits of port C as output is 90H
D7 D0
1 0 0 1 0 0 0 0
c) .MODEL SMALL
.DATA
PA EQU 310H
PB EQU 311H
PC EQU 312H
CR EQU 313H
.CODE
MOV AX, @DATA
MOV DS, AX
MOV AL, 90H ; move control word (90H) to AL
MOV DX, CR ; move control register address to DX
OUT DX, AL ; transfer AL value to Control register ( DX contains CR address)
MOV DX, PA ; move port A address to DX
IN AL, DX ; transfer port A data to AL
MOV DX, PB ; move port B address to DX
OUT DX, AL ; transfer AL content to port B
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 33
MOV DX, PC ; move port C address to DX
OUT DX, AL ; transfer AL content to port C
MOV AH,4CH
INT 21H
END
Show the address decoding where port A of the 8255 has an address of 300H.
Sol: port A address= 300H, port B address =301H , Port C =302H Control register = 303H
Address Port CS A1 A0
300H Port A 11000000 0 0
301H Port B 11000000 0 1
302H Port C 11000000 1 0
303H Control register 11000000 1 1
Address decoding circuit:
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 34
Write a program to toggle all bits of Port A continuously with some delay, Use INT 16H to
exit if there is a key press.
Instructions to check whether key is pressed or not
MOV AH, 01H
INT 16H; If key is pressed ZF=0, if key is not pressed ZF=1
Program:
.MODEL SMALL
.DATA
PA EQU 300H
PB EQU 301H
PC EQU 302H
CR EQU 303H
.CODE
MOV AX, @DATA
MOV DS, AX
MOV AL, 80H ; move control word (80H) to AL
MOV DX, CR ; move control register address to DX
OUT DX, AL ; transfer AL value to Control register ( DX contains CR address)
AGAIN:MOV DX, PA ; move port a address to DX
MOV AL, 55H ; move 55H to AL
OUT DX, AL ; transfer AL value to port A
CALL DELAY ; call delay procedure
MOV AL,0AAH ; move AAH to AL
OUT DX, AL ; transfer AL value to port A
MOV AH,01H ; check whether key is pressed or not
INT 16H
JZ AGAIN ; if key is not pressed jump AGAIN
MOV AH, 4CH
INT 21H
DELAY PROC
PUSH CX
PUSH BX
MOV CX, 1000H
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 35
LOOP2:MOV BX, 0FFFFH
LOOP1:DEC BX
JNZ LOOP1
LOOP LOOP2
POP BX
POP CX
RET
DELAY ENDP
END
Important Questions
1. With an example explain STOS, LODS, MOVS instructions.
2. With neat diagram explain NAND gate address decoder and 74LS138 address decoder.
3. Explain the pin diagram of 8255
4. Explain mode selection of 8255 and control register format.
5. Explain XLAT instruction with an example
6. With block diagram, explain EVEN and ODD banks memory organization in 8086.
7. Explain the following instructions i) CBW ii) CWD iii) IDIV iv) IMUL
8. Assuming there is a spelling of “Europe” in a electronic dictionary and user types in
“Euorope”, write a program that compares these two and displays the following message,
depending on the result
i) if they are equal, display “the spelling is correct”
ii) if they are not equal, display “Wrong spelling”
9. Write a program to find the average of the temperatures (+13, -10,+19, +14, -18, -9, +12, -19,
+16).
10. Explain REP, REPZ, REPNZ prefixes.
11. Explain CMPSB with an example.
12. write a program that scans the string “Mr. Gones” and replaces the “G” with letter “J” then
displays correct name
13. Explain checksum byte method with an example.
14. Assume that we have 4 bytes of hexadecimal data: 25H, 62H, 3FH, 52H
i) find checksum byte
ii) Perform checksum operation to ensure data integrity.
iii) If the second byte 62H had been changed to 22h, show how checksum detects the error.
15. In a given 8088 based system, port address 22H is an input port for monitoring the
temperature, write assembly language instructions to monitor that port continuously for the
temperature of 100 degrees, if it reaches 100, BH should contain ‘Y’
16. find the address range for Y4, Y2, and Y7 in below figure and verify block size controlled by
each Y.
15CS44 Microprocessors & Microcontrollers
Kishore Kumar R RLJIT Page 36
17. write a program (i) use STOSB to store byte AAH in 100 memory locations
(ii) Use LODSB to test contents of each location to see if AAH is there, if test
Fails, system should display the message “Bad Memory”
18. Assuming that the last byte of the following data is the checksum byte, show whether data
has been corrupted or not: 28H, C4H, BFH, 9EH, 87H, 65H, 83H, 50H, A7H and 51H
Sol) if the sum of all bytes including checksum byte is 0, no byte is corrupted.
19. Organize memory banks of 640K bytes of DRAM using 256K bit and 1M bit DRAM chips.
20. Calculate the memory cycle time of a 20 MHz 8386 system with
i) 0WS
ii) 1 WS
iii) 2 WS

More Related Content

What's hot

CNIT 141: 6. Hash Functions
CNIT 141: 6. Hash FunctionsCNIT 141: 6. Hash Functions
CNIT 141: 6. Hash FunctionsSam Bowne
 
Instruction Set Architecture
Instruction  Set ArchitectureInstruction  Set Architecture
Instruction Set ArchitectureHaris456
 
Register transfer language & its micro operations
Register transfer language & its micro operationsRegister transfer language & its micro operations
Register transfer language & its micro operationsLakshya Sharma
 
Intel 64bit Architecture
Intel 64bit ArchitectureIntel 64bit Architecture
Intel 64bit ArchitectureMotaz Saad
 
8086 instruction set (with simulator)
8086 instruction set (with simulator)8086 instruction set (with simulator)
8086 instruction set (with simulator)Aswini Dharmaraj
 
Chapter 2 instructions language of the computer
Chapter 2 instructions language of the computerChapter 2 instructions language of the computer
Chapter 2 instructions language of the computerBATMUNHMUNHZAYA
 
Fixed Point Conversion
Fixed Point ConversionFixed Point Conversion
Fixed Point ConversionRajesh Sharma
 
Evolution of Intel Processors
Evolution of Intel ProcessorsEvolution of Intel Processors
Evolution of Intel ProcessorsShad Ahmad Zaidi
 
Arm instruction set
Arm instruction setArm instruction set
Arm instruction setRavi Babu
 
8086 instruction set with types
8086 instruction set with types8086 instruction set with types
8086 instruction set with typesRavinder Rautela
 
Unit II arm 7 Instruction Set
Unit II arm 7 Instruction SetUnit II arm 7 Instruction Set
Unit II arm 7 Instruction SetDr. Pankaj Zope
 
44CON 2014 - Stupid PCIe Tricks, Joe Fitzpatrick
44CON 2014 - Stupid PCIe Tricks, Joe Fitzpatrick44CON 2014 - Stupid PCIe Tricks, Joe Fitzpatrick
44CON 2014 - Stupid PCIe Tricks, Joe Fitzpatrick44CON
 
Multiplication & division instructions microprocessor 8086
Multiplication & division instructions microprocessor 8086Multiplication & division instructions microprocessor 8086
Multiplication & division instructions microprocessor 8086University of Gujrat, Pakistan
 

What's hot (20)

Binary codes
Binary codesBinary codes
Binary codes
 
Addressing modes
Addressing modesAddressing modes
Addressing modes
 
CNIT 141: 6. Hash Functions
CNIT 141: 6. Hash FunctionsCNIT 141: 6. Hash Functions
CNIT 141: 6. Hash Functions
 
Instruction Set Architecture
Instruction  Set ArchitectureInstruction  Set Architecture
Instruction Set Architecture
 
8086 Microprocessor
8086 Microprocessor8086 Microprocessor
8086 Microprocessor
 
Register transfer language & its micro operations
Register transfer language & its micro operationsRegister transfer language & its micro operations
Register transfer language & its micro operations
 
Pentium ii
Pentium iiPentium ii
Pentium ii
 
Intel 64bit Architecture
Intel 64bit ArchitectureIntel 64bit Architecture
Intel 64bit Architecture
 
8086 instruction set
8086  instruction set8086  instruction set
8086 instruction set
 
Register & Memory
Register & MemoryRegister & Memory
Register & Memory
 
8086 instruction set (with simulator)
8086 instruction set (with simulator)8086 instruction set (with simulator)
8086 instruction set (with simulator)
 
Chapter 2 instructions language of the computer
Chapter 2 instructions language of the computerChapter 2 instructions language of the computer
Chapter 2 instructions language of the computer
 
Fixed Point Conversion
Fixed Point ConversionFixed Point Conversion
Fixed Point Conversion
 
Evolution of Intel Processors
Evolution of Intel ProcessorsEvolution of Intel Processors
Evolution of Intel Processors
 
Arm instruction set
Arm instruction setArm instruction set
Arm instruction set
 
8086 instruction set with types
8086 instruction set with types8086 instruction set with types
8086 instruction set with types
 
Unit II arm 7 Instruction Set
Unit II arm 7 Instruction SetUnit II arm 7 Instruction Set
Unit II arm 7 Instruction Set
 
ARM Fundamentals
ARM FundamentalsARM Fundamentals
ARM Fundamentals
 
44CON 2014 - Stupid PCIe Tricks, Joe Fitzpatrick
44CON 2014 - Stupid PCIe Tricks, Joe Fitzpatrick44CON 2014 - Stupid PCIe Tricks, Joe Fitzpatrick
44CON 2014 - Stupid PCIe Tricks, Joe Fitzpatrick
 
Multiplication & division instructions microprocessor 8086
Multiplication & division instructions microprocessor 8086Multiplication & division instructions microprocessor 8086
Multiplication & division instructions microprocessor 8086
 

Similar to 15CS44 MP &MC Module 3

8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-pptjemimajerome
 
Basic arithmetic, instruction execution and program
Basic arithmetic, instruction execution and programBasic arithmetic, instruction execution and program
Basic arithmetic, instruction execution and programJyotiprakashMishra18
 
8086 arch instns
8086 arch instns8086 arch instns
8086 arch instnsRam Babu
 
Assembly Language Lecture 4
Assembly Language Lecture 4Assembly Language Lecture 4
Assembly Language Lecture 4Motaz Saad
 
microcomputer architecture - Arithmetic instruction
microcomputer architecture - Arithmetic instructionmicrocomputer architecture - Arithmetic instruction
microcomputer architecture - Arithmetic instructionramya marichamy
 
Microprocessor 8086-lab-mannual
Microprocessor 8086-lab-mannualMicroprocessor 8086-lab-mannual
Microprocessor 8086-lab-mannualyeshwant gadave
 
Chap 3_2.ppt
Chap 3_2.pptChap 3_2.ppt
Chap 3_2.pptinian2
 
Assembly language-lab9
Assembly language-lab9Assembly language-lab9
Assembly language-lab9AjEcuacion
 
Home works summary.pptx
Home works summary.pptxHome works summary.pptx
Home works summary.pptxHebaEng
 
8086 instructions
8086 instructions8086 instructions
8086 instructionsRavi Anand
 
16-bit microprocessors
16-bit microprocessors16-bit microprocessors
16-bit microprocessorsZahra Sadeghi
 

Similar to 15CS44 MP &MC Module 3 (20)

8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-ppt
 
8086 Instruction set
8086 Instruction set8086 Instruction set
8086 Instruction set
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 
Instruction formats-in-8086
Instruction formats-in-8086Instruction formats-in-8086
Instruction formats-in-8086
 
Arithmetic instrctions
Arithmetic instrctionsArithmetic instrctions
Arithmetic instrctions
 
Basic arithmetic, instruction execution and program
Basic arithmetic, instruction execution and programBasic arithmetic, instruction execution and program
Basic arithmetic, instruction execution and program
 
8086 arch instns
8086 arch instns8086 arch instns
8086 arch instns
 
Assembly Language Lecture 4
Assembly Language Lecture 4Assembly Language Lecture 4
Assembly Language Lecture 4
 
microcomputer architecture - Arithmetic instruction
microcomputer architecture - Arithmetic instructionmicrocomputer architecture - Arithmetic instruction
microcomputer architecture - Arithmetic instruction
 
Microprocessor 8086-lab-mannual
Microprocessor 8086-lab-mannualMicroprocessor 8086-lab-mannual
Microprocessor 8086-lab-mannual
 
mm_1.pdf
mm_1.pdfmm_1.pdf
mm_1.pdf
 
Instruction set
Instruction setInstruction set
Instruction set
 
Chap 3_2.ppt
Chap 3_2.pptChap 3_2.ppt
Chap 3_2.ppt
 
Assembly language-lab9
Assembly language-lab9Assembly language-lab9
Assembly language-lab9
 
Home works summary.pptx
Home works summary.pptxHome works summary.pptx
Home works summary.pptx
 
8086 instructions
8086 instructions8086 instructions
8086 instructions
 
16-bit microprocessors
16-bit microprocessors16-bit microprocessors
16-bit microprocessors
 
Chap3 8086 artithmetic
Chap3 8086 artithmeticChap3 8086 artithmetic
Chap3 8086 artithmetic
 
8086 ins2 math
8086 ins2 math8086 ins2 math
8086 ins2 math
 
Chapter 3 8086 ins2 math
Chapter 3 8086 ins2 mathChapter 3 8086 ins2 math
Chapter 3 8086 ins2 math
 

Recently uploaded

main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacingjaychoudhary37
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 

Recently uploaded (20)

Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacing
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 

15CS44 MP &MC Module 3

  • 1. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 1 MODULE-3 TOPICS 3.1Signed Numbers and Strings 3.1.1 Signed Number Arithmetic operations 3.1.2 String Operations 3.2 Memory and Memory Interfacing 3.2.1 Memory Address Decoding 3.2.2 Data integrity in RAM & ROM 3.2.3 16-bit memory Interfacing 3.3 8255 I/O Programming 3.3.1 I/O addresses MAP of x86 PC’S 3.3.2 Programming and interfacing the 8255
  • 2. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 2 3.1.1 Signed Number Arithmetic operations: Signed Numbers:  MSB bit is used to indicate the sign of the number.  For positive (+) number, MSB bit is 0  For Negative (-) number, MSB bit is 1 Signed Byte Operands:  8-bits are used to represent signed byte operands  Bit 7 (D7) is the Sign bit  Bits D0-D6 are used for the magnitude of the number.  Range of signed byte operands is -128 to +127 Steps to for negative number representation: 1. Write magnitude of the number in 8-bits(no sign) 2. Invert each bit. 3. Add 1 to it. E.g. 1find the binary representation of -5 1. Write magnitude of number in 8-bits  5 = 0000 0101 2. Invert each bit 1111 1010 3. add 1 1111 1010 + 1 = 1111 1011 Hence -5 = 1111 1011 (hex value = FBH) E.g.2 Show -34H as it is represented internally 1. Write magnitude of number in 8-bits 0011 0100 2. Invert each bit 1100 1011 3. Add 1 1100 1011 + 1= 1100 1100 Hence -34H = 1100 1100 (hex value = CCH) E.g. 3 Show the representation for -12810 1. Write magnitude of number in 8-bits128 = 1000 0000 2. Invert each bit0111 1111
  • 3. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 3 3.Add 1 0111 1111+1 = 1000 0000 Hence -128 = 1000 0000 Word-Sized Signed Numbers:  16-bits are used for Word-sized signed numbers.  Bit 15 (D15) is the Sign bit  Bits D0-D14 are used for the magnitude of the number  Range of word-sized signed numbers is -32768 to +32767 In 8-bit operations, overflow occurs when 1. There is a carry from D6 to D7 but no carry out of D7 2. There is a carry from D7 out but no carry from D6 to D7
  • 4. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 4 Overflow in 16-bit operations: In 16-bit operation, OF is set to 1 in either of two cases 1. There is a carry from D14 to D15 but no carry out from D15 2. There is a carry from D15 out but no carry from D14 to D15 CBW (convert byte to word):  CBW will copy D7 (sign bit) to all bits of AH 7 0 7 0 AH AL E.g.1 MOV AL, +96; AL = 0110 0000 CBW ; AH = 0000 0000 and AL = 0110 0000 E.g.2 MOV AL,-2 ; AL = 1111 1110 CBW ; AH = 1111 1111 AL = 1111 1110
  • 5. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 5 CWD (convert word to Double Word):  CWD copies D15 of AX to all bits of DX register. 15 0 15 0 DX AX E.g. MOV AX, +260 ; AX= 0000 0001 0000 0100 or AX = 0104H CWD ; DX = 0000 0000 0000 0000 = 0000H Program: To Handle Overflow problem .MODEL SMALL .DATA NUM1 DB +96 NUM2 DB +70 RESULT DB ? .CODE MOV AX,@DATA MOV DS,AX MOV AH,0 ; AH=0 MOV AL, NUM1 ; AL=+96 MOV BL, NUM2 ;BL=+70 ADD AL,BL ;AL=AL+BL JNO OVER ; JUMP to OVER if OF=1 MOV AL,DATA2 ; AL=+70 CBW ; AX=+70 MOV BX,AX ;BX=+70 MOV AL,DATA1 ; AL=+96 CBW ;AX=+96 ADD AX,BX ; AX= AX+BX , AX= 166 OVER:MOV RESULT,AX; store AX value to RESULT INT 3 END
  • 6. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 6 IDIV (signed number division) : IDIV is used for signed number division. There are four types of division operations Division Dividend Divisor Quotient Remainder Byte / Byte AL =byte CBW Register or memory AL AH Word / Word AX= word CWD Register or memory AX DX Word /Byte AX=word Register or memory AL AH Double word/ Word DX AX = double word Register or memory AX DX Example for Byte / Byte Division +9 / +2 MOV AL, +9 ;AL = 0000 1001 CBW ;AX= 0000 0000 0000 10001 MOV BL, +2 ;BL = 0000 0010 IDIV BL ;AX / BL AL = +4 AH = +1 Write a Program to find the average of temperature .MODEL SMALL .DATA TEMP DB +13, -10,+19, +14, -18, -9, +12, -19, +16 TEMP si AVERAGE DW ? .CODE MOV AX,@DATA MOV DS,AX MOV CX,9 ; CX=9 MOV BX,0; BX is used to store the result MOV SI, OFFSET TEMP; Si points to location temp BACK: MOV AL,[SI] ; move data from location pointed by SI CBW ; convert byte to word ADD BX, AX ; BX= BX +AX INC SI ; SI points to next location LOOP BACK ; decrement CX , jump to BACK if CX≠0 MOV AL,9 ; AL =9 CBW ; AX=9 MOV CX,AX ; CX=9 AVERAGE MOV AX,BX ; AX = +18 CWD ; DX AX =+18 IDIV CX ; (DX AX) / CX  +18 / 9 AX= +2 DX= 0 MOV ACERAGE, AX ; AVERAGE = +2 MOV AH,4CH +13 -10 +19 +14 -18 -9 +12 -19 +16 +2
  • 7. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 7 INT 21H END IMUL (Signed Number Multiplication): It is used for signed number multiplication There are four types of multiplication operations Multiplication Operand 1 Operand 2 Result Byte × Byte AL 8-bit register or memory AX Word × Word AX 16-bit Register or memory DX AX Word × Byte AL = Byte CBW 16-bit Register or memory DX AX Signed Number Comparison: Syntax: CMP Destination, Source Operation: Destination – Source Flags Affected: OF, ZF, SF Case 1: Destination > source OF= SF or ZF =0 Case 2: Destination = source ZF=1 Case 3: Destination < Source OF = negation of SF Conditional jump instructions used for signed comparison are Mnemonic Function Condition JG Jump Greater Jump if OF=SF or ZF=0 JGE Jump greater or Equal Jump if OF=SF JL Jump Less Jump if OF = inverse of SF JLE Jump Less or Equal Jump if OF=inverse of SF or ZF=1 JE Jump equal Jump if ZF=1 Program: To find the Lowest temperature .MODEL SMALL TEMP SI .DATA TEMP DB +13, -10, +19, +14, -18, -9, +12, -19, +16 LOWEST DB ? .CODE MOV AX, @DATA MOV DS, AX MOV CX,8 ; CX=8 , 8 compariosons MOV SI, OFFSET TEMP ; SI points to location TEMP MOV AL,[SI] ;moves data to AL from location pointed by SI BACK: INC SI ; SI points to next location CMP AL, [SI] ; compare AL with data pointing by SI JLE SEARCH ;jump to search if AL≤[SI] LOWEST +13 -10 +19 +14 -18 -9 +12 -19 +16 -19
  • 8. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 8 MOV AL, [SI] ; move data from location [SI] to AL if SI≤AL SEARCH: LOOP BACK ; decrement CX and jump to SEARCH if CX≠0 MOV LOWEST, AL ; store the lowest temperature in AL to LOWEST MOV AH,4CH INT 21H END 3.1.2 String operations: There is a group of instructions to perform operations on strings SI, DI Registers:  SI and DI registers ae used by string instructions  When DF =0 SI and DI automatically increment  WHEN DF=1 SI and DI automatically decrement. CLD (clear direction Flag): this instruction is used to clear the direction flag DF=0 STD (set direction flag): this instruction is used to set direction flag DF=1 MOVSB (move string byte): • This instruction transfers BYTE from the data segment location pointed by SI to extra segment location pointed by DI. • After the byte transfer, the contents of SI and DI are incremented if DF = 0 or decremented if DF = 1. Syntax: MOVSB Function: ES : [DI]  DS : [SI]; SI = ± 1, DI = DI ± 1 E.g. If DF flag = 0, SI = 0001H, DS = 1000H, DI=0001 ES=2000H MOVSB ; the byte data in memory location 10001H will be transferred to location 20001h and contents of SI and DI increment by 1.
  • 9. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 9 MOVSW (move string word): • This instruction transfers word from the data segment location pointed by SI to extra segment location pointed by DI. • After the word transfer, the contents of SI and DI are incremented if DF = 0 or decremented if DF = 1. Syntax: MOVSW Function: ES : [DI]  DS : [SI]; SI = ± 2, DI = DI ± 2 E.g. If DF flag = 0, SI = 0001H, DS = 1000H, DI=0001 ES=2000H MOVSW ; the byte word in memory locations 10001H and 10002H will be transferred to locations 20001h and 20002H and contents of SI and DI increment by 2. LODSB: • LODSB transfers a byte from the data segment memory location pointed by SI to the AL. • After the byte transfer, the contents of SI increment if D = 0 or contents of SI decrement if D = 1. Syntax: LODSB Function: AL  DS : [SI]; SI = SI ± 1 E.g. If DF flag = 0, SI = 0001H and DS = 1000H LODSB ; the byte data stored in memory location 10001H will be transferred to AL, because DF =0 the contents of SI increment by 1. LODSW: • LODSW transfers a word from the data segment memory location pointed by SI to the AX. • After the word transfer, the contents of SI & DI increment if DF = 0 or contents of SI & DI decrement if DF = 1. Syntax: LODSW Function: AX  DS : [SI]; SI = SI ± 2 E.g. If D flag = 0, SI = 1000H and DS = 1000H LODSW ; the word data stored in memory location 11000H and 11001H will be transferred to AX, because D =0 the contents of SI increment by 2. STOSB: • STOSB instruction stores byte in AL in to the extra segment memory location addressed by DI. • After the byte is stored, the contents of DI increment if DF= 0 or decrement if DF = 1. Syntax: STOSB
  • 10. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 10 Function: ES : [DI]  AL; DI = DI ± 1 E.g. If DF=0, ES=2000H and DI=0001H AL =10H STOSB; it stores the value 10H in location 20001H and DI = 0002H STOSW: • STOSW instruction stores word in AX in to the extra segment memory location addressed by DI. • After the word is stored, the contents of DI increment if DF= 0 or decrement if DF = 1. Syntax: STOSW Function: ES : [DI]  AX; DI = DI ± 2 E.g. If DF=0, ES=2000H and DI=0001H AX =2010H STOSB; it stores the value 10H in location 20001H and 20H in location 20002Hand DI =0003H REP (repeat):  REP (repeat) is a prefix.  REP is added to any string data transfer instruction except the LODS instruction.  REP decrements CX by1 each time the string instruction executes.  After CX decrements the string instruction repeats.  If CX reaches a value of 0, the string instruction terminates. e.g. MOV CX, 100 REP STOSB ; this instruction repeats 100 times. Program: (i) use STOSB to store byte AAH in 100 memory locations (ii) Use LODSB to test contents of each location to see if AAH is there, if test Fails, system should display the message “Bad Memory” .MODEL SMALL .DATA MSG DB “ Bad Memory$” MEM_AREA DB 100 DUP(?) .CODE MOV AX, @DATA MOV DS, AX MOV ES, AX CLD ; DF=0 MOV CX, 100 ;CX=100 MOV DI, OFFSET MEM_AREA ; DI points to memory area reserved to store AAH MOV AL, 0AAH ; AL=AAH
  • 11. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 11 REP STOSB ; stores AAH in memory location ES:[DI] DI = DI +1 MOV SI, OFFSET MEM_AREA ; SI points to memory area in which 100 AAH are stored MOV CX,100 ;CX=100 AGAIN: LODSB ; it loads value in memory location DS:[SI] to AL CMP AL, 0AAH ; compare AL value with AAH JNE OVER ; if AL≠AAH jump to over LOOP AGAIN ; decrements CX jump to AGAIN if CX≠0 JMP EXIT ; jump to exit OVER: LEA DX, MSG ; display a message “Bad Memory” MOV AH,09H INT 21H EXIT: MOV AH,4CH ; exit to DOS INT 21H END Program: Using String instructions write a program that transfers a block of 20 bytes of data .MODELSMALL .DATA BLOCK1 DB ‘ABCDEFGHIJKLMNOPQRST’ BLOCK2 DB 20 DUP (?) .CODE MOV AX, @DATA MOV DS,AX ; Initialize data segment MOV ES,AX ; initialize extra segment CLD ; DF=0 MOV SI, OFFSET BLOCK1 ; SI points to BLOCK1 MOV DI, OFFSET BLOCK2 ; DI points to BLOCK2 MOV CX, 20 ; CX=20 REP MOVSB ; moves 20 bytes form data segment to extra segment MOV AH, 4CH INT 21H END REPE (repeat while equal) or REPZ (repeat while zero) : • The REPE prefix is used for string instruction. • REPE causes the string instruction to repeat until CX register reaches 0 or until unequal condition occurs (ZF=0)
  • 12. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 12 REPNE (repeat while not equal) or REPNZ (repeat while not zero) : • The REPNE prefix is used for string instruction. • REPNE causes the string instruction to repeat until CX register reaches 0 or until equal condition occurs (ZF=1). CMPSB (compare string byte): • This instruction compares the byte in memory location (DS; SI) with the byte in memory location (ES:DI). • It performs subtraction of the byte in ES:DI from the byte in DS:SI. • CMPSB is normally used with REPE or REPNE prefix. Syntax: CMPSB Function: flags  DS:SI – ES : DI; SI = SI ± 1; DI = DI ± 1 Flags affected: AF, CF, OF, PF, SF, ZF Example: write a program to compare the string of length 10 in the Data Segment with the string of length 10 in the Extra Segment. MOV SI, OFFSET STR1 MOV DI, OFFSET STR2 CLD MOV CX, 10 REPE CMPSB CMPSW (compare string Word): • This instruction compares the word in memory location (DS; SI) with the word in memory location (ES:DI). • It performs subtraction of the word in ES:DI from the word in DS:SI. • CMPSW is normally used with REPE or REPNE prefix. Syntax: CMPSW Function: flags  DS:SI – ES : DI; SI = SI ± 2; DI = DI ± 2 Flags affected: AF, CF, OF, PF, SF, ZF Program: Assuming there is a spelling of “Europe” in a electronic dictionary and user types in “Euorope”, write a program that compares these two and displays the following message, depending on the result i) if they are equal, display “the spelling is correct” ii) if they are not equal, display “Wrong spelling” .MODEL SMALL .DATA STR1 DB “Europe”
  • 13. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 13 STR2 DB “Euorope” MSG1 DB “ The spelling is correct$” MSG2 DB “Wrong Spelling$” .CODE MOV AX,@DATA MOV DS,AX MOV ES,AX CLD ; DF=0 MOV SI,OFFSET STR1 ; SI points to STR1 MOV DI, OFFSET STR2 ; DI points to STR2 MOV CX,6 ; CX=6 REPE CMPSB ; repeat CMPSB until CX=0 or unequal condition occurs JE OVER ; if strings are equal jump to OVER LEA DX, MSG2 ; display message “wrong Spelling” JMP DISP OVER: LEA DX,MSG1 ; display message “ the spelling is correct” DISP: MOV AH, 09H INT 21H MOV AH, 4CH INT 21H END SCASB (scan string byte): • This instruction compares the contents of AL with the contents of memory location (ES: DI). • It subtracts the contents of memory location (ES : DI) from AL without affecting AL and memory location. Syntax: SCASB Function: flags  AL - ES :DI , DI = DI ± 1 Flags affected: AF, CF, OF, PF, SF, ZF Example: program to scan letter ‘G’ in a string “Mr. Gones” STRING DB ‘Mr. Gones’ CLD MOV CX, 09 MOV AL, ‘G’ REPNE SCASB SCASW (scan string word): • This instruction compares the contents of AX with the contents of memory location (ES : DI). • It subtracts the contents of memory location ( ES : DI) from AX without affecting AL and memory location.
  • 14. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 14 Syntax: SCASW Function: flags  AX - ES :DI , DI = DI ± 2 Flags affected: AF, CF, OF, PF, SF, ZF Replacing the Scanned character: SCASB can be used to search for a character in string, and if it is found it will be replaced with the desired character. Program: write a program that scans the string “Mr. Gones” and replaces the “G” with letter “J” then displays correct name .MODELSMALL .DATA STR DB “Mr. Gones$” .CODE MOV AX, @DATA MOV DS, AX MOV ES, AX CLD ; DF=0 MOV DI, OFFSET STR ; DI points to STR MOV CX,09 ; CX=9, 9 characters to be scanned MOV AL, ‘G’ ; AL=G REPNE SCASB ; scan the string until CX=0 or until G is found JNE OVER ; if G is not found jump to over DEC DI ; if G is found decrement DI MOV [DI], ‘J’ ; replace G with J OVER: LEA DX, STR ; display corrected string MOV AH,09H INT 21H MOV AH, 4CH ; exit to DOS INT 21H END XLAT (translate): This instruction converts the contents of the AL register into a number stored in a memory table. 1. XLAT first adds the contents of AL to BX to form a memory address within the data segment. 2. It then copies the contents of this address into AL. Syntax: XLAT Operation: AL  DS : [BX+AL]
  • 15. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 15 E.g. TABLE BX MOV BX, OFFSET TABLE MOV AL, 03 ; AL=3 XLAT ; AL=33 In the above example, the data in memory location [AL+BX] 33 is moved to AL Code conversion using XLAT: ASCII BX XLAT can be used to translate hex keys to ASCII values .DATA ASCII DB ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’ HEX_VALUE DB 4 HEX_VALUE ASC_VALUE DB ? ASC_VALUE .CODE MOV BX, OFFSET ASCII ; BX points to ASCII table MOV AL, HEX_VALUE ; AL=4 XLAT ; AL= [4+BX] i.e. AL= ascii value of 4 (34) MOV ASC_VALUE, AL ; 34 is moved to location ASC_VALUE 3.2.1Memory Address Decoding: Address decoding: Selecting desired location when CPU sends the memory address Simple Logic Gate as address decoder: 30 31 32 33 34 31 32 33 34 35 36 37 39 41 42 43 30 44 45 46 47 4 34
  • 16. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 16  Memory size is 32K ×8 (32K bytes), to access any location in memory the pin CS (Chip Select) must be activated.  Data bus is used to connect the CPU to data pins of the memory.  Control signals MEMR (memory read) and MEMW (memory write) are connect to OE (output enable) and WR (write) pins of memory.  The lower address bits (A14- A0) are connected directly to memory.  The upper address bits (A19-A15) are used to active CS pin.  To read or write a data into memory CS pin must be activated. Address range of memory chip in the above figure is Problem: find the address range of the memory shown below In the above figure, to activate CS, output of NAND gate must be low, to generate low output A19-A16 must be equal to 1001, hence starting address is 90000H and end address is 9FFFFH
  • 17. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 17 To find the size of the memory in the above figure  Subtract starting address and end address  Add 1 to result.  Convert Hexadecimal result to decimal  Divide the decimal result by 1024 to get the memory size in K bytes. 9FFFFH-90000H = 0FFFFH + 1 = 10000H Decimal value of 10000H is 65,536 65536 / 1024 = 64 K bytes 74LS138 Chip:  74LS138 chip has 3 inputs A, B and C and 8 outputs (Y7 – Y0)
  • 18. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 18  Eight Y outputs can be connected to 8 memory blocks.  G2A, G2B and G1 pins can be used to select address or control signal. Using 74LS138 as Decoder:  A15- A0 from CPU are connected directly to memory.  A18-A16 are connected to A, B and C inputs of 74LS138  A19 is connected to G1 pin.  G2A, G2B are grounded.  Output Y4 is connected to CS or CE pin of memory.  To select Y4 , C=1 B=0 A=0 i.e. 100 (4) Address range of the memory chip is First address = C0000H End Address=CFFFFH
  • 19. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 19
  • 20. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 20 3.2.2Data Integrity in RAM and ROM: • Ensuring data retrieved is same as the data stored is called data integrity. • There are many ways to maintain data integrity based on the type of storage. • CHECKSUM method is used for ROM, PARITY BIT method is used for DRAM • For mass storage devices like Hard disks CRC (cyclic redundancy check) method is used. Checksum Byte Method: • One of the causes of ROM corruption is current surge, either when PC is ON or during operation. • Checksum method used checksum byte, it is a byte that is added to the end of a series of bytes of data. Steps to calculate Checksum Byte: 1. Add the bytes together and drop the carries 2. Take the 2’s complement of the total sum, and that is the checksum byte, which is last byte of the stored information. Checksum Operation: Add all bytes including checksum byte, the result must be zero, if it is not zero, one or more bytes have been changed (corrupted). Problem: Assume that we have 4 bytes of hexadecimal data: 25H, 62H, 3FH, 52H i) find checksum byte ii) Perform checksum operation to ensure data integrity. iii) If the second byte 62H had been changed to 22h, show how checksum detects the error. Solution: i) Checksum byte is calculated by adding all the bytes by dropping carries and take 2’s complement of the result 25H 62H 3FH 52H 1 18H Ignore the carry 1, and 2’s complement of 18H is E8H Hence, checksum byte = E8H ii) to perform check sum operation, all bytes including checksum byte is added by dropping carries if result is 0 no byte is corrupted. 25H+62H+3FH+52H+E8H= 00H iii) if second byte is changed from 62H to 22H 25H+22H+3FH+52H+E8H= C0H  result is not zero, hence some byte is corrupted
  • 21. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 21 Problem: Assuming that the last byte of the following data is the checksum byte, show whether data has been corrupted or not: 28H, C4H, BFH, 9EH, 87H, 65H, 83H, 50H, A7H and 51H Sol) if the sum of all bytes including checksum byte is 0, no byte is corrupted. 28H+C4H+ BFH+ 9EH+87H+ 65H+83H+50H+A7H+51H = 00H (data not corrupted) DRAM Memory Banks: The arrangement of DRAM chips on the system is called as DRAM memory banks e.g. 64K bytes of DRAM can be arranged as one bank of 8 IC chips of 64K×1 OR 4 banks of 16×8 organization Figure below shows the memory banks of 640K bytes of DRAM using 256K and 1M DRAM chips. Use of parity bit in DRAM error detection:  A parity bit is added to every byte in memory to ensure data integrity.  Parity bit method is used for error detection in DRAM Types of errors in DRAM: There are two types of errors in DRAM, 1. Soft error 2. Hard Error Soft Error: if a single bit is changed from 1 to 0 or from 0 to 1 is called soft error Hard Error: if few bits or entire row of bits get stuck to 1 or 0 permanently is called hard error. 74S280 parity bit generator and checker:  This chip has 9 inputs (A-I) and 2 outputs.  If 9 inputs have an odd number of 1s, the odd output is high.  If 9 inputs have even number of 1s, the even output is high
  • 22. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 22 The truth table of 74280 is shown below. 3.2.3 16-bit Memory Interfacing: • In 16-bit CPU, the memory locations 00000H – FFFFFH are arranged as ODD and EVEN bytes as shown below
  • 23. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 23 • A0 and BHE (Bus high enable) can be used to select ODD or EVEN byte. Memory cycle time and inserting wait states: • The fixed amount of time provided by CPU to access memory is called Bus Cycle time or Memory Cycle Time. • The time from when CPU provides the address at its address pins to when data is expected at its data pins is called Memory Read Cycle Time. • Memory cycle time is 2 clocks • If memory is slow, extra time can be requested, this extra time is called Wait State (WS) e.g. if clock frequency or speed = 20MHZ clock time = 1 / 20MHz = 50ns Memory cycle time = 2 × 50ns = 100ns Factors slow down the CPU: • The time taken for address signals to go from CPU to memory, plus time taken by data to travel from memory to CPU, this delay is called path delay. • The time required to get the data out of memory chip.
  • 24. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 24 Accessing word in 8-bit system:  In 8-bit system, two memory cycles are required to access any word (odd or even) Figure below shows the accessing word in 8-bit system
  • 25. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 25 Accessing Word in 16-bit system:  In 16-bit system, one memory cycle is required to access word at even memory address.  Two memory cycles are required to access a word at odd address. Example: MOV AX, [F617], assume that DS= F000H The above instruction moves the contents of ,memory locations FF617H and FF618H are moved to register AX, in the first cycle, the contents of location FF617H are moved to AL and contents of location FF618H are moved to register AH
  • 26. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 26 BUS Bandwidth: • The rate of data transfer is called Bus Bandwidth. • The wider the data bus the higher the bus bandwidth. Two ways to increase the bandwidth:  Use wider data bus  Reduce the bus cycle time Bus Bandwidth = (1/ bus cycle time) × bus width in bytes 8088/8086 Input & output instructions: IN for 8-bit ports: • This instruction transfers data from an external input device into register AL. • Port address is specified in the instruction Format: IN AL, port # ; port # is the address of the port E.g. IN AL, 22H; it moves 8-bit data from the port 22H to AL IN for 16-bit ports:  This instruction transfers data from an external input device into register AL.  DX contains 16-bit port address. Format: MOV DX, port# ; move 16-bit port address to DX IN AL, DX ; transfers a byte from the port (DX contains port address) to AL E.g MOV DX, 1234H
  • 27. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 27 IN AL, DX ; it moves 8-bit data from port 1234H to AL OUT for 8-bit ports:  This instruction transfers data from AL to an external output device Format: OUT port #, AL ; port# is address of the port e.g. OUT 55H, AL; moves 8-bit data from AL to port 55H OUT for16-bit ports:  This instruction transfers data from AL to an external output device Format: MOV DX, PORT# ; move 16-bit port address to DX OUT DX, AL ;transfers byte from AL to port (DX contains port address) E.g. MOV DX, 4321H ; move 16-bit port address (4321H) to DX OUT DX, AL ; transfers 8-bit data from AL to port 4321H Program: transfer the value 36H to port 43H MOV AL, 36H ; move the value 36H to AL OUT 43H, AL ; transfers AL content to port 43H Program to send values 55H and AAH to port address 300H (16-bit address) BACK:MOV DX, 300H MOV AL, 55H OUT DX,AL MOV AL,0AAH OUT DX, AL JMP BACK Program to get data from port address 300H and send it to port address 302H MOV DX, 300H IN AL, DX MOV DX, 302H OUT DX, AL Program: In a given 8088 based system, port address 22H is an input port for monitoring the temperature, write assembly language instructions to monitor that port continuously for the temperature of 100 degrees, if it reaches 100, BH should contain ‘Y’
  • 28. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 28 BACK: IN AL, 22H ; get temperature from port 22H CMP AL, 100 ; compare temperature in AL with 100 JNZ BACK ; if temp≠100 jump back MOV BH, ‘Y’ ; if temp = 100 move ‘Y’ to BH 3.3.2 Programming and Interfacing the 8255: (very important question) • It is 40-pin chip • It has three ports A, B C • Each port can be used as either input or output Pin diagram of 8255: PortA (PA7-PA0): This 8-bit port can be used as either input or output PortB (PB7-PB0): It can be used as either input or output PortC(PC7-PC0):  It can be used as either input or output  It can also be split into two parts CU (upper bits PC7-PC4) CL ( lower bits PC3-PC0) D0-D7 data pin:  The data pins of the 8255 are connected to the data pins of the microprocessor allowing it to send data back and forth between the microprocessor and the 8255 chip. A0, A1 and CS:  CS (chip select) selects the entire chip.  Address pins A0 and A1 select specific port with in 8255
  • 29. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 29 RD and WR:  These two are active low inputs to 8255  RD enables the read operation of 8255  WR enables the write operation of 8255 RESET:  This is active high input of 8255  When reset is activated, all ports are initialized as input ports. Mode selection of 8255: The ports of the 8255 can be programmed in three different modes. 1) Mode 0 2) Mode 1 3) Mode 2 Mode 0:  In this mode, any of the ports A,B, CL and CU can be programmed as input or output. Mode 1:  In this mode, ports A and B can be used as input or output ports with handshaking capabilities.  Handshaking signals are provided by the bits of port C. Mode 2:  In this mode, port A can be used as bidirectional port with handshaking capabilities whose signals are provided by port C. Control word Format (I/O mode):  Control register is used to the select operation mode of the ports.
  • 30. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 30 Problem: write a control word if PA = out, PB = IN , PC0-PC3 =IN and PC4-PC7 = OUT. Control word = D7 D6 D5 D4 D3 D2 D1 D0 1 0 0 0 0 0 1 1 Control word = 8 3H Write a program to get data from port A and send it to port B, In addition data from PCL is sent out to the PCU, use port address 300H-303H for the 8255 chip. Program: .MODEL SMALL .DATA PA EQU 300H PB EQU 301H PC EQU 302H CR EQU 303H .CODE MOV AX, @DATA MOV DS, AX MOV AL, 83H ; move control word (83H) to AL MOV DX, CR ; move control register address to DX OUT DX, AL ; transfer AL value to Control register ( DX contains CR address) MOV DX, PA ; move port A address to DX IN AL, DX ; transfer data from port A to AL
  • 31. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 31 MOV DX, PB ; move port B address to DX OUT DX, AL ; transfer Al value to port B MOV DX, PC ; move port C address to DX IN AL, DX ; transfer data from Port C to Al AND AL, 0FH ; mask upper bits of AL MOV CL, 4 ; CL=4 ROL AL, CL ; rotate AL contents left side by 4 positions OUT DX, AL ; send AL value to Port C MOV AH, 4CH INT 21H END
  • 32. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 32 b) control word to set port A as input, B as output and all bits of port C as output is 90H D7 D0 1 0 0 1 0 0 0 0 c) .MODEL SMALL .DATA PA EQU 310H PB EQU 311H PC EQU 312H CR EQU 313H .CODE MOV AX, @DATA MOV DS, AX MOV AL, 90H ; move control word (90H) to AL MOV DX, CR ; move control register address to DX OUT DX, AL ; transfer AL value to Control register ( DX contains CR address) MOV DX, PA ; move port A address to DX IN AL, DX ; transfer port A data to AL MOV DX, PB ; move port B address to DX OUT DX, AL ; transfer AL content to port B
  • 33. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 33 MOV DX, PC ; move port C address to DX OUT DX, AL ; transfer AL content to port C MOV AH,4CH INT 21H END Show the address decoding where port A of the 8255 has an address of 300H. Sol: port A address= 300H, port B address =301H , Port C =302H Control register = 303H Address Port CS A1 A0 300H Port A 11000000 0 0 301H Port B 11000000 0 1 302H Port C 11000000 1 0 303H Control register 11000000 1 1 Address decoding circuit:
  • 34. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 34 Write a program to toggle all bits of Port A continuously with some delay, Use INT 16H to exit if there is a key press. Instructions to check whether key is pressed or not MOV AH, 01H INT 16H; If key is pressed ZF=0, if key is not pressed ZF=1 Program: .MODEL SMALL .DATA PA EQU 300H PB EQU 301H PC EQU 302H CR EQU 303H .CODE MOV AX, @DATA MOV DS, AX MOV AL, 80H ; move control word (80H) to AL MOV DX, CR ; move control register address to DX OUT DX, AL ; transfer AL value to Control register ( DX contains CR address) AGAIN:MOV DX, PA ; move port a address to DX MOV AL, 55H ; move 55H to AL OUT DX, AL ; transfer AL value to port A CALL DELAY ; call delay procedure MOV AL,0AAH ; move AAH to AL OUT DX, AL ; transfer AL value to port A MOV AH,01H ; check whether key is pressed or not INT 16H JZ AGAIN ; if key is not pressed jump AGAIN MOV AH, 4CH INT 21H DELAY PROC PUSH CX PUSH BX MOV CX, 1000H
  • 35. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 35 LOOP2:MOV BX, 0FFFFH LOOP1:DEC BX JNZ LOOP1 LOOP LOOP2 POP BX POP CX RET DELAY ENDP END Important Questions 1. With an example explain STOS, LODS, MOVS instructions. 2. With neat diagram explain NAND gate address decoder and 74LS138 address decoder. 3. Explain the pin diagram of 8255 4. Explain mode selection of 8255 and control register format. 5. Explain XLAT instruction with an example 6. With block diagram, explain EVEN and ODD banks memory organization in 8086. 7. Explain the following instructions i) CBW ii) CWD iii) IDIV iv) IMUL 8. Assuming there is a spelling of “Europe” in a electronic dictionary and user types in “Euorope”, write a program that compares these two and displays the following message, depending on the result i) if they are equal, display “the spelling is correct” ii) if they are not equal, display “Wrong spelling” 9. Write a program to find the average of the temperatures (+13, -10,+19, +14, -18, -9, +12, -19, +16). 10. Explain REP, REPZ, REPNZ prefixes. 11. Explain CMPSB with an example. 12. write a program that scans the string “Mr. Gones” and replaces the “G” with letter “J” then displays correct name 13. Explain checksum byte method with an example. 14. Assume that we have 4 bytes of hexadecimal data: 25H, 62H, 3FH, 52H i) find checksum byte ii) Perform checksum operation to ensure data integrity. iii) If the second byte 62H had been changed to 22h, show how checksum detects the error. 15. In a given 8088 based system, port address 22H is an input port for monitoring the temperature, write assembly language instructions to monitor that port continuously for the temperature of 100 degrees, if it reaches 100, BH should contain ‘Y’ 16. find the address range for Y4, Y2, and Y7 in below figure and verify block size controlled by each Y.
  • 36. 15CS44 Microprocessors & Microcontrollers Kishore Kumar R RLJIT Page 36 17. write a program (i) use STOSB to store byte AAH in 100 memory locations (ii) Use LODSB to test contents of each location to see if AAH is there, if test Fails, system should display the message “Bad Memory” 18. Assuming that the last byte of the following data is the checksum byte, show whether data has been corrupted or not: 28H, C4H, BFH, 9EH, 87H, 65H, 83H, 50H, A7H and 51H Sol) if the sum of all bytes including checksum byte is 0, no byte is corrupted. 19. Organize memory banks of 640K bytes of DRAM using 256K bit and 1M bit DRAM chips. 20. Calculate the memory cycle time of a 20 MHz 8386 system with i) 0WS ii) 1 WS iii) 2 WS