Professional Documents
Culture Documents
Name:Siddharth Sharma Registration Number:16BCE0188 Microprocessor DA-2
Name:Siddharth Sharma Registration Number:16BCE0188 Microprocessor DA-2
Registration Number:16BCE0188
Microprocessor DA-2
Q1.)
Solution:
DATA SEGMENT
STR1 DB "Hack Rank$"
STR2 DB 10 DUP ('$')
MSG1 DB 10,13,'ENTER ANY STRING : $'
MSG2 DB 10,13,'FOUND AT POS : $'
MSG3 DB 10,13,'$'
MSG4 DB 10,13,'STRINGS DO NOT MATCH$'
MSG5 DB ' CHARACTER(S) FOUND IN THE GIVEN STRING $'
MSG6 DB 10,13,'STORED STRING IN MEMORY IS : $'
MSG7 DB 10,13,'REVERSE STRING IS : $'
MSG8 DB 10,13,'STRING AFTER REPLACING R WITH B : $'
MSG9 DB 10,13,'STRINGS ARE EQUAL$'
CHAR DB 'k'
R DB 'R'
B DB 'B'
COUNT DB 0
POS DB 1
P1 LABEL BYTE
M1 DB 0FFH
L1 DB ?
P11 DB 0FFH DUP ('$')
DATA ENDS
DISPLAY MACRO MSG
MOV AH,9
LEA DX,MSG
INT 21H
ENDM
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
DISPLAY MSG1
DISPLAY STR1
LEA DI,STR1
MOV CX,9
SEARCH:
MOV AL,[DI]
CMP R,AL
JE REPLACE
INC DI
LOOP SEARCH
REPLACE:
MOV AL,B
MOV [DI],AL
DISPLAY MSG3
DISPLAY MSG8
DISPLAY STR1
LEA SI,STR2
LEA DI,STR1
ADD DI,8
MOV CX,9
REVERSE:
MOV AL,[DI]
MOV [SI],AL
INC SI
DEC DI
LOOP REVERSE
DISPLAY MSG3
DISPLAY MSG7
DISPLAY STR2
DISPLAY MSG3
LEA DI,STR1
MOV CX,9
CHECK:
MOV AL,[DI]
CMP CHAR,AL
JNE SKIP
INC COUNT
DISPLAY MSG3
DISPLAY MSG2
MOV DL,POS
ADD DL,30H
MOV AH,2
INT 21H
SKIP:
INC POS
INC DI
LOOP CHECK
CMP COUNT,0
JE NOTFOUND
DISPLAY MSG3
DISPLAY MSG3
MOV DL,COUNT
ADD DL,30H
MOV AH,2
INT 21H
DISPLAY MSG5
DISPLAY MSG3
DISPLAY MSG1
LEA DX,P1
MOV AH,0AH
INT 21H
LEA SI,P11
MOV CX,9
LEA DI,STR1
CHECKEQUAL:
MOV AL,[SI]
MOV CHAR,AL
MOV AL,[DI]
CMP CHAR,AL
JNE NOTFOUND
INC SI
INC DI
LOOP CHECKEQUAL
DISPLAY MSG3
DISPLAY MSG9
JMP EXIT
NOTFOUND:
DISPLAY MSG4
Q2.
Solution:
The format for the control word format for 8255A is shown in figure above. As per the
requirement of the programmer the control word is written into the control word register
of 8255A. No read operation of the control word is allowed.
Bit D0 :
Bit D1:
Bit D2:
Bit D3:
Bit D4:
Bits D5 and D6 :
These two bits are used to determine the I/O mode of port A.
These bits are defined for the various modes of port A as follows:
D6 D5 Mode of port A
0 0 Mode 0
0 1 Mode 1
1 0 or 1 Mode 2
Bit D7:
This bit specifies either I/O function or bit set/reset function (BSR mode). If this bit is set
to 1 then the 8255 will work in I/O mode. If this bit is set to 0 then the 8255 will work in
BSR mode.
There are 16 combinations of control words for various configurations of the ports of
8255 for Mode 0 operations. These control words are shown in table.