Microprocessor and Interfacing Assignment-3
Microprocessor and Interfacing Assignment-3
Reg.No: 20BCE2049
Slot: L11+L12
.model small
.stack 100h
.data
.code
main proc
mov ax , @data
mov ds , ax
clear :
mov ah , 2
mov dl , 0dh
int 21h
mov dl , 0ah
int 21h
mov ah , 9
lea dx , m1
int 21h
xor bh , bh
input :
mov ah , 1
int 21h
mov ch , al
cmp ch , 0dh
je print
cmp ch,'0'
jl exit
cmp ch,'1'
jg exit
and ch , 15
shl bh , 1
or bh , ch
jmp input
print :
mov ah , 2
mov dl , 0dh
int 21h
mov dl , 0ah
int 21h
mov ah , 9
lea dx , m2
int 21h
mov ah , 2
cmp bh,9
jle number
cmp bh , 15
jle charecter
number :
add bh , 48
mov ah,2
mov dl , bh
int 21h
jmp clear
charecter :
add bh , 55
mov ah,2
mov dl , bh
int 21h
jmp clear
exit:
mov ah , 2
mov di , 0dh
int 21h
mov dl , 0ah
int 21h
mov ah, 9
lea dx , m3
int 21h
mov ah , 4ch
int 21h
main endp
end main
.model small
.stack 100h
.data
NUM DB 10 DUP('$')
RES DB 40 DUP('$')
SIZE DB 0
H0 DB '0000$'
H1 DB '0001$'
H2 DB '0010$'
H3 DB '0011$'
H4 DB '0100$'
H5 DB '0101$'
H6 DB '0110$'
H7 DB '0111$'
H8 DB '1000$'
H9 DB '1001$'
HA DB '1010$'
HB DB '1011$'
HC DB '1100$'
HD DB '1101$'
HE DB '1110$'
HF DB '1111$'
.code
main proc
MOV AX,@data
MOV DS,AX
LEA SI,NUM
MOV CX,0
loop_1:
MOV AH,1h
INT 21h
CMP AL,13
JE NA
INC CL
CMP CL,10
JE NA
CMP AL,57
JG ELSEA1
SUB AL,48
JMP BOTHA1
ELSEA1:
SUB AL,55
BOTHA1:
MOV AH,0H
MOV BL,AL
MOV [SI],AL
INC SI
JMP loop_1
NA:
MOV SIZE,CL
LEA SI,NUM
label_1:
MOV AL,[SI]
CALL val
INC SI
DEC CL
CMP CL,0
JG label_1
MOV AH,02
MOV DX,10
INT 21H
MOV DX,13
INT 21H
MOV CH,0
MOV AH,0
LEA SI,NUM
MOV CL,SIZE
label_2:
MOV AL,[SI]
MOV BL,15
SUB BL,AL
MOV AL,BL
CALL val
INC SI
DEC CL
CMP CL,0
JG label_2
MOV AH,02
MOV DX,10
INT 21H
MOV DX,13
INT 21H
main endp
val proc
CMP AL,0h
JNE N0
LEA DX,H0
JMP LAST
N0:
CMP AL,1
JNE N1
LEA DX,H1
JMP LAST
N1:
CMP AL,2
JNE N2
LEA DX,H2
JMP LAST
N2:
CMP AL,3
JNE N3
LEA DX,H3
JMP LAST
N3:
CMP AL,4
JNE N4
LEA DX,H4
JMP LAST
N4:
CMP AL,5
JNE N5
LEA DX,H5
JMP LAST
N5:
CMP AL,6
JNE N6
LEA DX,H6
JMP LAST
N6:
CMP AL,7
JNE N7
LEA DX,H7
JMP LAST
N7:
CMP AL,8
JNE N8
LEA DX,H8
JMP LAST
N8:
CMP AL,9
JNE N9
LEA DX,H9
JMP LAST
N9:
CMP AL,10
JNE N10
LEA DX,HA
JMP LAST
N10:
CMP AL,11
JNE N11
LEA DX,HB
JMP LAST
N11:
CMP AL,12
JNE N12
LEA DX,HC
JMP LAST
N12:
CMP AL,13
JNE N13
LEA DX,HD
JMP LAST
N13:
CMP AL,14
JNE N14
LEA DX,HE
JMP LAST
N14:
CMP AL,15
JNE N15
LEA DX,HF
JMP LAST
N15:
RET
LAST:
MOV AH,09h
INT 21h
ret
val endp
A)
B)
Question, code and output-3
A)
.MODEL SMALL
.STACK 100H
.DATA
.CODE
MOV AX,@DATA
MOV DS,AX
CALL REVERSE
LEA DX,STRING
INT 21H
INT 21H
MAIN ENDP
REVERSE PROC
MOV CX, 0H
LOOP1:
JE LABEL1
PUSH [SI]
INC SI
INC CX
JMP LOOP1
LABEL1:
LOOP2:
CMP CX,0
JE EXIT
POP DX
XOR DH, DH
MOV [SI], DX
INC SI
DEC CX
JMP LOOP2
EXIT:
RET
REVERSE ENDP
END MAIN
B)
.MODEL SMALL
.STACK 100H
.DATA
org 100h
.data
str_len DW 0
substr_len DW 0
counter DW 0
.code
mov ax,@DATA
mov DS,ax
lea dx,buf1
call Display
mov ah,0Ah
int 21h
mov bl,[str+1]
mov str_len,bx
lea dx,buf2
call display
mov ah,0Ah
int 21h
lea SI,str
add SI,2
lea DI,substr
add DI,2
mov bx,substr_len
cmp str_len,bx
jg G
mov cx,bx
G:
mov cx,str_len
L:
lodsb
cmp al,0Dh
je final
jne next
final:
cmp counter,0
je exit
mov counter,0
lea DI,substr
add DI,2
jmp next1
next:
dec SI
next1:
cmpsb
je h
inc counter
h:
LOOP L
exit:
cmp counter,0
je Found
lea dx,buf4
call Display
jmp terminate
Found:
lea dx,buf3
call Display
terminate:
mov ah,4ch
int 21h
ret
Display PROC
mov ah,09h
int 21h
ret
Display ENDP