Sunteți pe pagina 1din 14

Chapter 4:

(8): Write a program to (a) display a "?", (b) read two decimal digits who.se sum "is less than 10,
(c) display them and their sum on the next line, with an appropriate message. Sample execution: ?
27 '!'HE SlJM OF 2 .'\ND 7 IS 9

.MODEL SMALL
.STACK 100H
.DATA
STR1 DB 0AH,0DH,'THE SUM OF '
a DB ?
STR2 DB ' AND '
b DB ?
STR3 DB ' IS '
ANS DB ?
STR4 DB ' $'
.CODE
MAIN PROC

MOV AX,@DATA
MOV DS,AX

MOV AH,2
MOV DL,3FH
INT 21H

MOV AH,1
INT 21H
MOV BL,AL
MOV a,AL
INT 21H
MOV b,AL

ADD BL,AL
SUB BL,30H
MOV ANS,BL

MOV AH,9
LEA DX,STR1
INT 21H

MOV AH,4CH
INT 21H

MAIN ENDP
END MAIN

(9): Write a program to (a) prompt the user, (b) read first, middle, and last initials of a person's
name, and (c) display them duwn the left margin. Sample execution:

ENTER THEIR INITIALS: JFK

.MODEL SMALL
.STACK 100H
.DATA
a DB 'Enter three initials : $'
b DB 10d,13d,'The initials are :',10d,13d,'$'
c DB 10d,13d,'$'
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX

MOV Dl, offset a


MOV AH, 09h
INT 21H

MOV AH, 01h


INT 21H

MOV BL, AL

MOV AH, 01h


INT 21H

MOV BH, AL

MOV AH, 01h


INT 21H

MOV CL, AL
MOV Dl, offset b
MOV AH, 09h
INT 21H

MOV AH, 02h


MOV DL, BL
INT 21H

MOV Dl, offset c


MOV AH, 09h
INT 21H

MOV AH, 02h


MOV DL, BH
INT 21H

MOV Dl, offset c


MOV AH, 09h
INT 21H

MOV AH, 02h


MOV DL, CL
INT 21H
MOV AH, 04CH
INT 21H

(10): Write· a program to read one of the hex digits A-F, and Display it

on the next line in decimal.

Sample execution:ENTER A HEX DIGIT: C

IN DECIMAL IT IS 12

.MODEL SMALL
.STACK 100H
.DATA
STR1 DB 'ENTER A HEX DIGIT: $'
STR2 DB 0AH,0DH,'IN DECIMAL IT IS 1'
ANS DB ?
STR3 DB '$'
.CODE
MAIN PROC

MOV AX,@DATA
MOV DS,AX

MOV AH,9
LEA DX,STR1
INT 21H

MOV AH,1
INT 21H

SUB AL,11H
MOV ANS,AL

MOV AH,9
LEA DX,STR2
INT 21H

MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN

(11): Write a program to display a t 0 x 10 solid box of asterisks. Hint: declare a string in the data
segment that specifies the box, and display it with INT 2lh, function 9h.
.MODEL SMALL
.STACK 100H
.DATA
a DB 10d,13d,"**********$"
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX

MOV DX, offset a


MOV AH, 09h
INT 21H
INT 21H
INT 21H
INT 21H
INT 21H
INT 21H
INT 21H
INT 21H
INT 21H
INT 21H

MOV AH, 04CH

Using loop:

.MODEL SMALL
.DATA
a DB 10D,13D, "**********$"
.CODE

MOV AX, @DATA


MOV DS, AX
MOV Cx,10
MOV Ah,09h
LEA Dx,a

TOP:
INT 21H
Loop TOP
MOV Ah,04CH
INT 21h
END

(12): Write a program to (a) display"?",


(b) read three initials,
(c) display them in the middle of an 11 x 11 box of astc:ri5ks, and
(d) beep the computer.

.MODEL SMALL
.STACK 100H

.DATA
a DB 0DH,0AH,'Enter three initials : $'
b DB '***********',0DH,0AH,'$'
newline DB 0DH,0AH,"$"

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

MOV AH, 2
MOV DL, "?"
INT 21H
LEA DX, a
MOV AH, 9
INT 21H

MOV AH, 1
INT 21H

MOV BL, AL

INT 21H

MOV BH, AL

INT 21H

MOV CL, AL

LEA DX, newline


MOV AH, 9
INT 21H
INT 21H

LEA DX, b
MOV AH, 9

INT 21H
INT 21H
INT 21H
INT 21H
INT 21H

MOV b+4, BL
MOV b+5, BH
MOV b+6, CL

INT 21H

MOV b+4, "*"


MOV b+5, "*"
MOV b+6, "*"

INT 21H
INT 21H
INT 21H
INT 21H
INT 21H

MOV AH, 2
MOV DL, 7H
INT 21H
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN

Chapter 6:

(8)Write a program to display a "?", read two capital letters, and display them on the next line In
alphabetical order

.MODEL SMALL
.STACK 100H
.DATA
st DB " first letter : $\"
stt DB " second letter : $\"
sttt DB "The given letters in alphabetical order are : $\"
n DB 13D,10D, "$\"
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX

MOV AH, 2
MOV DL, "?"
INT 21H

MOV AH, 9

LEA DX, n
INT 21H
LEA DX, st
INT 21H

MOV AH, 1
INT 21H

MOV BL, AL
MOV AH, 9
LEA DX, n
INT 21H

LEA DX, stt


INT 21H

MOV AH, 1
INT 21H

MOV BH, AL
MOV AH, 9
LEA DX, n
INT 21H

LEA DX, sttt


INT 21H

MOV AH, 2
CMP BL, BH
JAE @GREATER
MOV DL, BL
INT 21H

MOV DL, BH
INT 21H

JMP @END

@GREATER:
MOV DL, BH
INT 21H

MOV DL, BL
INT 21H

@END:

MOV AH, 4CH


INT 21H
MAIN ENDP
END MAIN
(9):
Write a program to display the extended ASCII characters (ASCJI codes 80h to FF_h). Display 10
characters per line, separated by blanks. Stop after the extended characters have been displayed
once.

.MODEL SMALL
.STACK 100H

.CODE

MAIN PROC

MOV BL,80H
MOV CL,0
TOP:
CMP CL,10
JE NEWLINE

INC CL

MOV AH,2
MOV DL,BL
INT 21H
INC BL

CMP BL,0FFH
JE END_

JMP TOP
NEWLINE:
MOV AH,2
MOV DL,0AH
INT 21H
MOV DL,0DH
INT 21H
MOV CL,0
JMP TOP
END_:

MOV AH,4CH
INT 21H

MAIN ENDP
END MAIN

(10):
Write a program that will prompt the user to enter a hex digit
character ("0"·... "9" or "A" ... "F"), display it on the next line
in decimal, and ask the user i.i he or she wants to do it again. If
the user types "y" or "Y", the ·program repeats; If the user types
anything else, the program terminates. If the user enters an illegal
character, prompt the user to try again.

.MODEL SMALL
.STACK 100H
.DATA
MSG DB 'TRY AGAIN.$'
aa DB 'ENTER A HEX DIGIT "0"..."9" OR "A".."F": $'
bb DB 0AH,0DH,'OUTPUT: $'
input DB 0AH,0DH,'DO YOU WANT ANOTHER INPUT: $'
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX

TOP:
MOV AH,9
LEA DX,aa
INT 21H

MOV AH,1
INT 21H
MOV BL,AL

CMP BL,30H
JL TRY_MSG

CMP BL,46H
JG TRY_MSG

CMP BL,39H
JLE DIGIT

MOV AH,9
LEA DX,bb
INT 21H

SUB BL,11H

MOV AH,2
MOV DL,31H
INT 21H
MOV DL,BL
INT 21H
AGAIN:
MOV AH,9
LEA DX,input
INT 21H

MOV AH,1
INT 21H
MOV BH,AL
MOV AH,2
MOV DL,0AH
INT 21H
MOV DL,0DH
INT 21H

CMP BH,'Y'
JE TOP
CMP BH,'y'
JE TOP
JMP END_
DIGIT:
MOV AH,9
LEA DX,bb
INT 21H

MOV AH,2
MOV DL,BL
INT 21H

JMP AGAIN
TRY_MSG:
MOV AH,9
LEA DX, MSG
INT 21H
JMP TOP
END_:

MOV AH,4CH
INT 21H

MAIN ENDP
END MAIN

S-ar putea să vă placă și