Вы находитесь на странице: 1из 8

MICROPROCESSOR AND INTERFACING

DIGITAL ASSIGNMENT- 2
Ishan Kaushik
17BCE2025

1. Write an ALP that perform the following components. (Try to perform


single ALP)
a. Load the string “Hack Rank”
STRING1 DB 'Hack Rank'

b. In that Replace the character “R” with the letter “B”


#include <stdio.h>

int main (void)

char name[] = "Hello World";

_asm

lea eax, name; // EAX = address of name

mov ebx, 'A';

mov [eax], bl;

printf("%s", name);

return 0;

c. Print Reverse a string

.MODEL SMALL

.STACK 100H

.DATA

STRING DB 'This is a sample string', '$'


.CODE

MAIN PROC FAR

MOV AX,@DATA

MOV DS,AX

CALL REVERSE

LEA DX,STRING

MOV AH, 09H

INT 21H

MOV AH, 4CH

INT 21H

MAIN ENDP

REVERSE PROC

MOV SI, OFFSET STRING

MOV CX, 0H

LOOP1:

MOV AX, [SI]

CMP AL, '$'

JE LABEL1

PUSH [SI]

INC SI

INC CX

JMP LOOP1

LABEL1:

MOV SI, OFFSET STRING

LOOP2:

CMP CX,0

JE EXIT
POP DX

XOR DH, DH

MOV [SI], DX

INC SI

DEC CX

JMP LOOP2

EXIT:

MOV [SI],'$ '

RET

REVERSE ENDP

END MAIN

d. No. of recurrences for a character “K” and its positions


DATA SEGMENT
STR1 DB “AXkbkkaf”
A DB 0H
MSG1 DB 10,13,”COUNT OF K’s IS : $”
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
LEA SI,STR1
MOV CX,10
CHECK:
MOV AL,[SI]
CMP AL,’k’
JNE N1
INC A
N1:
CMP AL,’a’
JNE N2
INC A
N2: INC SI
LOOP CHECK
MOV AL,A
DISPLAY MSG1
MOV DL,A
ADD DL,30H
MOV AH,2
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
END START

e. Compare the user input string with the given string and identify whether equal or not.
DATA SEGMENT

STR1 DB "ENTER FIRST STRING HERE ->$"

STR2 DB "ENTER SECOND STRING HERE ->$"

STR11 DB "FIRST STRING : ->$"

STR22 DB "SECOND STRING: ->$"

INSTR1 DB 20 DUP("$")

INSTR2 DB 20 DUP("$")

NEWLINE DB 10,13,"$"

N DB ?

S DB ?

MSG1 DB "BOTH STRING ARE SAME$"

MSG2 DB "BOTH STRING ARE DIFFERENT$"

DATA ENDS

CODE SEGMENT

ASSUME DS:DATA,CS:CODE

START:

MOV AX,DATA
MOV DS,AX

LEA SI,INSTR1

LEA DI,INSTR2

MOV AH,09H

LEA DX,STR1

INT 21H

MOV AH,0AH

MOV DX,SI

INT 21H

MOV AH,09H

LEA DX,NEWLINE

INT 21H

MOV AH,09H

LEA DX,STR2

INT 21H

MOV AH,0AH

MOV DX,DI

INT 21H

MOV AH,09H

LEA DX,NEWLINE

INT 21H

MOV AH,09H

LEA DX,STR11

INT 21H

MOV AH,09H

LEA DX,INSTR1+2

INT 21H

MOV AH,09H
LEA DX,NEWLINE

INT 21H

MOV AH,09H

LEA DX,STR22

INT 21H

MOV AH,09H

LEA DX,INSTR2+2

INT 21H

MOV AH,09H

LEA DX,NEWLINE

INT 21H

MOV BX,00

MOV BL,INSTR1+1

MOV BH,INSTR2+1

CMP BL,BH

JNE L1

ADD SI,2

ADD DI,2

L2:MOV BL,BYTE PTR[SI]

CMP BYTE PTR[DI],BL

JNE L1

INC SI

INC DI

CMP BYTE PTR[DI],"$"

JNE L2

MOV AH,09H

LEA DX,MSG1

INT 21
JMP L5

L1:MOV AH,09H

LEA DX,MSG2

INT 21H

L5:

MOV AH,09H

LEA DX,NEWLINE

INT 21H

MOV AH,4CH

INT 21H

CODE ENDS

END START

2. Write the Control word format of 8255 for I/O Mode. Find the Control word if
a) PA = output
b) PB = input
c) PC0-PC3 = input
d) PC4-PC7= output
Draw an interfacing diagram and write an ALP to perform the 8255 to get data from Port A and send it
to Port B. Also the data from PCL is forward the data to PCU.

Input/output mode (I/O) – This mode is selected when the most significant bit (D7) in the control
register is 1.
Mode 0 – Simple or basic I/O mode:
Port A, B and C can work either as input function or as output function. The outputs are latched but
the inputs are not latched. It has interrupt handling capability.
Mode 1 – Handshake or strobbed I/O:
In this either port A or B can work and port C bits are used to provide handshaking. The outputs as
well as inputs are latched. It has interrupt handling capability. Before actual data transfer there is
transmission of signal to match speed of CPU and printer.

Control Word: 1001 0000 = 90H


ALP to perform the 8255 to get data from Port A and send it to Port B and the data from PCL is forward the
data to PCU.

MOV A, #90H

MOV DPTR, #1003H

MOVX @DPTR, A

MOV DPTR,#1000H

MOVX A,@DPTR

INC @DPTR

MOVX @DPTR, A //MOVES TO PORT B

MOV DPTR, #1002H

MOVX A, @DPTR

ANL A, #0FH

SWAP A

MOVX @DPTR, A

Вам также может понравиться