0% found this document useful (0 votes)
51 views29 pages

Micro 5

The document contains 3 assignments related to Microprocessor and Interfacing course. Assignment 1 deals with inputting a binary number and outputting it in decimal. Assignment 2 converts a decimal number to binary and hexadecimal. Assignment 3 contains a program to reverse a string.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views29 pages

Micro 5

The document contains 3 assignments related to Microprocessor and Interfacing course. Assignment 1 deals with inputting a binary number and outputting it in decimal. Assignment 2 converts a decimal number to binary and hexadecimal. Assignment 3 contains a program to reverse a string.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 29

Name: Mallikarjun Hatti

Reg no: 19BCE0889


Course: Microprocessor and Interfacing
Course code: CSE 2006
Slot : L11 +L12
DIGITAL ASSIGNMENT 2
Question1
.MODEL SMALL
.STACK 100H
.DATA
STR DB 0AH,0DH,'Illegal Input. $'
.CODE

MAIN PROC

MOV AX,@DATA
MOV DS,AX

MOV BX,0
MOV CL,1

TOP:
MOV AH,1 ; INPUT CHARACTER
INT 21H ; COMPARE IS CR OR NOT
CMP AL,0DH ; IF EQUAL JUMP TO END IF NO THAN CONTINUE
JE END_

CMP AL,30H ; COMPARE AL CONTAIN 0 OR NOT


JNE CHECK ; IF NO GOTO CHECK
CONTINUE:
SUB AL,30H ;SUBTRACT 30H AND PUT INTO AL
;
SHL BX,CL ; SHIFT BX LEFT 1 TIME
OR BL,AL ; OR BL AND AL

JMP TOP
CHECK:
CMP AL,31H ;COMPARE AL CONTAIN 1 OR NOT
JNE MSG ; IF NO GOTO MSG
JMP CONTINUE ; IF YES THAN GOTO CONTINUE
END_:

MOV AH,2 ;
MOV DL,0AH ;
INT 21H ;NEW LINE
MOV DL,0DH ;
INT 21H

MOV CL,1
MOV CH,0
OUTPUT:
CMP CH,4 ;COMPARE CH IS EQUAL 4
JE FINISH ;IF YES GOTO FINISH
INC CH ;INCREMENT CH

MOV DL,BH ;MOVE BH TO DL


SHR DL,4 ;SHIFT DL 4 TIMES IN THE RIGHT

CMP DL,0AH ;COMPARE DL < 10


JL DIGIT ;IF YES GOTO DIGIT

ADD DL,37H ;ADD DL WITH 37h


MOV AH,2 ;
INT 21H ;PRINTING DL
ROL BX,4 ;ROTATE BX LEFT 4 TIMES
JMP OUTPUT ;JUMP TO OUTPUT

DIGIT:
ADD DL,30H ;ADD DL WITH 30h
MOV AH,2
INT 21H ;PRINTING DL
ROL BX,4 ;ROTATE BX LEFT 4 TIMES
JMP OUTPUT ;JUMP TO OUTPUT
MSG:
MOV AH,9 ;
LEA DX,STR ;ILLEGAL MSG
INT 21H ;

FINISH:
MOV AH,4CH
INT 21H

MAIN ENDP
END MAIN
Question2

.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
QUESTION3
.STACK 100H
.DATA

; The string to be printed


STRING DB 'It is an apple', '$'

.CODE
MAIN PROC FAR
MOV AX,@DATA
MOV DS,AX

; call reverse function


CALL REVERSE
; load address of the string
LEA DX,STRING

; output the string


; loaded in dx
MOV AH, 09H
INT 21H

; interrupt to exit
MOV AH, 4CH
INT 21H

MAIN ENDP
REVERSE PROC
; load the offset of
; the string
MOV SI, OFFSET STRING

; count of characters of the;


;string
MOV CX, 0H

LOOP1:
; compare if this is;
;the last character
MOV AX, [SI]
CMP AL, '$'
JE LABEL1

; else push it in the;


;stack
PUSH [SI]

; increment the pointer;


;and count
INC SI
INC CX
[22:43, 10/4/2022] Mallikarjun HATTI 19BCE08: JMP LOOP1

LABEL1:
; again load the starting;
;address of the string
MOV SI, OFFSET STRING

LOOP2:
;if count not equal to zero
CMP CX,0
JE EXIT

; pop the top of stack


POP DX

; make dh, 0
XOR DH, DH

; put the character of the;


;reversed string
MOV [SI], DX

; increment si and;
;decrement count
INC SI
DEC CX

JMP LOOP2

EXIT:
; add $ to the end of string
MOV [SI],'$ '
RET

REVERSE ENDP
END MAIN
.STACK 100H

.DATA

; The string to be printed

STRING DB 'It is an apple', '$'

.CODE

MAIN PROC FAR

MOV AX,@DATA

MOV DS,AX

; call reverse function

CALL REVERSE

; load address of the string

LEA DX,STRING

; output the string

; loaded in dx

MOV AH, 09H

INT 21H

; interrupt to exit

MOV AH, 4CH

INT 21H

MAIN ENDP

REVERSE PROC

; load the offset of


; the string

MOV SI, OFFSET STRING

; count of characters of the;

;string

MOV CX, 0H

LOOP1:

; compare if this is;

;the last character

MOV AX, [SI]

CMP AL, '$'

JE LABEL1

; else push it in the;

;stack

PUSH [SI]

; increment the pointer;

;and count

INC SI

INC CX

[22:43, 10/4/2022] Mallikarjun HATTI 19BCE08: JMP LOOP1

LABEL1:

; again load the starting;

;address of the string

MOV SI, OFFSET STRING


LOOP2:

;if count not equal to zero

CMP CX,0

JE EXIT

; pop the top of stack

POP DX

; make dh, 0

XOR DH, DH

; put the character of the;

;reversed string

MOV [SI], DX

; increment si and;

;decrement count

INC SI

DEC CX

JMP LOOP2

EXIT:

; add $ to the end of string

MOV [SI],'$ '

RET

REVERSE ENDP
END MAIN

You might also like