Chapter 4 8. Write a program to (a) display a "?", (b) read two decimal digits who.se sum "is less than 1, (c) display them and their sum on the ne!t line, with an appropriate message. ample e!ecution# ?$% THE SUM OF 2 AND 7 IS 9 .model small .stack 100h .data msg db 'THE SUM OF$' msg1 db ' $' msg2 db 'AND$' msg db '!S$' .code ma"# %oc mo& dl'(' mo& ah2 "#t 21h mo& ah1 "#t 21h mo& blal mo& ah1 "#t 21h mo& clal
mo& ah2 mo& dl0dh "#t 21h
) ca%%"age %et*%#
mo& dl0ah "#t 21h
)#e+ l"#e
mo& a,-data a,-data )"#"t"al"e data segmet mo& dsa, lea d,msg mo& ah/ "#t 21h
lea d,msg1 mo& ah/ "#t 21h mo& ah2 mo& dlbl "#t 21h lea d,msg1 mo& ah/ "#t 21h lea d,msg2 mo& ah/ "#t 21h lea d,msg1 mo& ah/ "#t 21h mo& ah2 mo& dlcl "#t 21h lea d,msg1 mo& ah/ "#t 21h lea d,msg mo& ah/ "#t 21h lea d,msg1 mo& ah/
"#t 21h add blcl )s*m s*b bld )co#&e%t to asc"" #*mbe% mo& dlbl mo& ah2 "#t 21h mo& ahch "#t 21h ma"# e#d e#d ma"#
Output:
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: E!E" !#"l::E $$!$%&S: J F K
.model small .stack 100h .data msg db 'ENTE THEE !N!T!A345 $' .code ma"# %oc mo& a,-data a,-data )"#"t"al"e data segme#t mo& dsa, lea d,msg mo& ah/ "#t 21h mo& ah1 "#t 21h mo& blal mo& ah1 "#t 21h mo& clal mo& ah1 "#t 21h mo& bhal mo& ah2 mo& dl0dh )caa%"age %et*%# "#t 21h mo& dl0ah )#e+ l"#e "#t 21h
mo& ah2 mo& dlbl "#t 21h
mo& dl0dh "#t 21h mo& dl0ah "#t 21h mo& ah2 mo& dlcl "#t 21h mo& dl0dh "#t 21h mo& dl0ah "#t 21h mo& ah2 mo& dlbh "#t 21h mo& ahch "#t 21h ma"# e#d e#d ma"#
Output:
*+. Write a program to read one of the hex digits A-F, A-F, and display it on the next line in decimal. Sample execution:
&'& * #E- +-# IN /E$0%& IT rs *1
.model small .stack 100h .data msg1 db 'E#te% a he, d"g"t5 $' msg2 db '!# dec"mal "t "s5 $' .code ma"# %oc mo& a,-data mo& dsa, lea d,msg1 mo& ah/ "#t 21h mo& ah1 "#t 21h mo& blal s*b bl16d ) co#&e%t to co%%eso#d"#g he, &al*e as 7896. So 96:168;08<2< mo& ah2 mo& dl0dh "#t 21h mo& dl0ah "#t 21h lea d,msg2 mo& ah/ "#t 21h
mo& dl/d dl/d )%"#t 1 at ="%st ="%st mo& ah2 "#t 21h mo& dlbl mo& ah2 ) %"#t #e,t &al*e o= he, a=te% 1 "#t 21h
ma"# e#d e#d ma"# Output:
**. Write a program to display a t + x *+ solid 2ox of asteris3s. Hint: declare a string in the data segment that specifies the 2ox, and display it with $! 1lh, function 9h.
.model small .stack 100h .data msg1 db '>>>>>>>>>>$' .code ma"# %oc mo& a,-data mo& dsa, lea d,msg1 mo& ah/ "#t 21h mo& ah2 mo& dl0dh "#t 21h
)%"#t 10 t"mes
mo& dl0ah "#t 21h lea d,msg1 mo& ah/ "#t 21h mo& ah2 mo& dl0dh "#t 21h mo& dl0ah "#t 21h lea d,msg1 mo& ah/ "#t 21h mo& ah2 mo& dl0dh "#t 21h mo& dl0ah "#t 21h lea d,msg1 mo& ah/ "#t 21h mo& ah2 mo& dl0dh "#t 21h mo& dl0ah "#t 21h lea d,msg1 mo& ah/ "#t 21h mo& ah2 mo& dl0dh "#t 21h mo& dl0ah "#t 21h lea d,msg1 mo& ah/ "#t 21h mo& ah2 mo& dl0dh "#t 21h mo& dl0ah "#t 21h lea d,msg1
mo& ah/ "#t 21h mo& ah2 mo& dl0dh "#t 21h mo& dl0ah "#t 21h lea d,msg1 mo& ah/ "#t 21h mo& ah2 mo& dl0dh "#t 21h mo& dl0ah "#t 21h lea d,msg1 mo& ah/ "#t 21h mo& ah2 mo& dl0dh "#t 21h mo& dl0ah "#t 21h lea d,msg1 mo& ah/ "#t 21h mo& ahch "#t 21h ma"# e#d e#d ma"#
Output:
1$. Write a program to (a) display"?", (b) read three initials,(/) display them in the middle o0 an 11 ! 11 bo! o0 asteri!, and (d) beep the computer. .model small .stack 100h .data msg1 db '***********$' msg2 db '****$' .code main proc mov dl,'?' mov ah,2 int 21h mov ah,1 int 21h mov bl,al mov ah,1 int 21h mov cl,al mov ah,1 int 21h
mov bh,al mov ah,2 mov dl,0dh int 21h mov dl,0ah int 21h mov ax,@data mov ds,ax lea dx,msg1 mov ah,9 int 21h mov ah,2 mov dl,0dh int 21h mov dl,0ah int 21h lea dx,msg1 mov ah,9 int 21h mov ah,2 mov dl,0dh int 21h mov dl,0ah int 21h lea dx,msg1 mov ah,9 int 21h mov ah,2 mov dl,0dh int 21h mov dl,0ah int 21h lea dx,msg1 mov ah,9 int 21h mov ah,2 mov dl,0dh int 21h mov dl,0ah int 21h
lea dx,msg1 mov ah,9 int 21h mov ah,2 mov dl,0dh int 21h mov dl,0ah int 21h lea dx,msg2 printing less star to p!t the scanned val!e mov ah,9 int 21h
mov dl,bl mov ah,2 int 21h
printing scanned val!e
mov dl,cl int 21h printing scanned val!e mov dl,bh printing scanned val!e int 21h lea dx,msg2 mov ah,9 int 21h mov ah,2 mov dl,0dh int 21h mov dl,0ah int 21h lea dx,msg1 mov ah,9 int 21h mov ah,2 mov dl,0dh int 21h
mov dl,0ah int 21h lea dx,msg1 mov ah,9 int 21h mov ah,2 mov dl,0dh int 21h mov dl,0ah int 21h lea dx,msg1 mov ah,9 int 21h mov ah,2 mov dl,0dh int 21h mov dl,0ah int 21h lea dx,msg1 mov ah,9 int 21h mov ah,2 mov dl,0dh int 21h mov dl,0ah int 21h lea dx,msg1 mov ah,9 int 21h
mov ah,2 mov dl,0"h int 21h mov ah,#ch int 21h main endp end main
utput#
Chapter 2 4. Write a program to display a 565, read two capital letters, and display them on the next line $n alpha2etical order.
.model small .stack 100h .data msg db 10,1,'?$' msg1 db 10,1,'%nter t&o capital letter$' msg2 db 10,1,'(!tp!t is$' .code mov ax,@data mov ds,ax
lea dx,msg mov ah,9 int 21h lea dx,msg1 mov ah,9 int 21h mov ah,1 int 21h mov bl,al
mov ah,1 int 21h mov cl,al lea dx,msg2 mov ah,9 int 21h cmp bl,cl )a go mov dl,bl mov ah,2 int 21h mov dl,cl int 21h )mp exit exit
go mov dl,cl mov ah,2 int 21h mov dl,bl int 21h
i bl+cl
)mp exit exit exit utput#
3. Write a program to display the e!tended *C characters (*C codes 8h to 556h). +isplay 1 characters per line, separated by blan7s. top a0ter the e!tended characters hae been displayed once. .model small .stack 100h .data .code main proc mov cx,12" initiali-e n!mber o character mov bl,0 print mov ah,2 inc cx
cmp cx,2 )a exit mov dx,cx int 21h mov dx,2d int 21h )mp go
giving space
go inc bl cmp bl,10 10 char per line )e nl )mp print nl mov ah,2 mov dl,0dh int 21h mov dl,0ah int 21h mov bl,0 )mp print exit utput
1. Write a program that will prompt the user to enter a
he! digit character (""9 ... "3" or "*" ... "5"), display it on the ne!t line in decimal, and as7 the user i.i he or she wants to do it again. 0 the user types "y" or ":", the 9program repeats/ 0 the user types anything else, the program terminates. 0 the t he user enters an illegal character, prompt the user to try again. .model small .stack 100h .data msg1 db 10,1,'%/% 3%4 5676$' msg2 db 10,1,'6/ 5%86: 6; 6$' msg db 10,1,'5( <(= >/ ( 5( 6 76/?$' msg# db 10,1,'6::%7: 838% %/% 09 ( $' .code again mov ax,@data mov ds,ax lea dx,msg1 mov ah,9 int 21h mov ah,1 int 21h mov bl,al )mp go
go
cmp bl,'9' )a hex i bl+9 go t hex label )b n!m )e n!m
hex cmp bl,'' )a illegal i bl+ illegal lea dx,msg2 mov ah,9 int 21h mov dl,#9d mov ah,2 int 21h s!b bl,1"d convert to letter mov dl,bl mov ah,2 int 21h )mp inp
inp lea dx,msg mov ah,9 int 21h mov ah,1 int 21h mov cl,al
cmp cl,'A' )e again cmp cl,'<' )e again )mp exit n!m cmp bl,'0' )b illegal lea dx,msg2 mov ah,9 int 21h mov dl,bl mov ah,2 int 21h )mp inp
illegal lea dx,msg# mov ah,9 int 21h mov ah,1 int 21h mov bl,al )mp go exit
**. /o programming exercise *+, except that if the user fails to enter a hex7digit character $n three tries, display a message and terminate the program.
.model small .stack 100h .data msg1 db 101'ENTE A HE? D!4!T5$' msg2 db 101'!N DE7!MA3 !S !T5$' msg db 101'DO 1 01'DO @OU ANT TO DO !T A4A!N($' A4A!N($' msg db 101'!33E4A3 7HAA7TE: ENTE 0:/ O A:F5$' msg; db 101'Too Ma#B T%B$' .code
aga"#5 mo& c,0 mo& a,-data mo& dsa, lea d,msg1 mo& ah/
"#t 21h mo& ah1 "#t 21h mo& blal Cm go go5 cm bl'/' Ca he, Cb #*m Ce #*m
he,5 cm bl'F' Ca "llegal lea d,msg2 mo& ah/ "#t 21h mo& dl/d mo& ah2 "#t 21h s*b bl16d mo& dlbl mo& ah2 "#t 21h Cm "#
"#5 lea d,msg
mo& ah/ "#t 21h mo& ah1 "#t 21h mo& clal cm cl'B' Ce aga"# cm cl'@' Ce aga"# Cm e,"t #*m5 cm bl'0' Cb "llegal lea d,msg2 mo& ah/ "#t 21h mo& dlbl mo& ah2 "#t 21h Cm "#
"llegal5 "#c c, cm c, Ce "2 lea d,msg mo& ah/ "#t 21h mo& ah1 "#t 21h mo& blal
Cm go
"25 lea d,msg; mo& ah/ "#t 21h Cm e,"t e,"t5
Chapter % 8. Write a program thC;t prompts the user to enter a character, and on subse
o0 1 bits n ts *C code. Sample execution: :=& * C>**C&# * >& *C C+& 5 * ' '*: 11 >& '@A& 5 l $ .model small .stack 100h .data msg1 5B '
mov cx,D limit or loop iED or D bit mov bh,0 binarA shl bl,1 )nc -ero 80 inc bh mov dl,1h )mp displaA -ero mov dl,0h displaA mov ah,2 int 21h loop binarA 55 bh,0h lea dx,msg# mov ah,9 int 21h mov dl,bh mov ah,2 int 21h
loop &ill be terminated &hile cx+D
9. Write a program that prompts the user to enter a character and prints the %S$$ code of the character in hex on the next line. "epeat this process until the user types a carriage return. Sample execution: !8E % #%"%!E": !#E %S$$ ;/E ; $ #E- $S <% !8E % #%"%!E":
.model small .stack 100h .data msg1 db 10,1,'Ape 10,1,'Ape a character$' c haracter$' msg2 db 10,1,'he scii code o $' msg db ' in hex is$' .code main proc mov ax,@data mov ds,ax
inp!t lea dx,msg1 mov ah,9 int 21h mov ah,1 int 21h mov bl,al cmp bl,0dh )e end lea dx,msg2 mov ah,9 int 21h mov dl,bl mov ah,2 int 21h lea dx,msg mov ah,9 int 21h mov cx,# convert mov dl,bh shr dl,1 shit let # times shr dl,1 shr dl,1 shr dl,1 cmp dl,9 )be n!m add dl,d )mp displaA n!m add dl,0h
displaA mov ah,2 int 21h rcl bx,1 rcl bx,1 rcl bx,1 rcl bx,1
rotate carrA let # times
loop convert )mp inp!t inp!t end (F 3,#83 6/ 213 6/ %/5C %/5 6/ utput#
1. Write a program that prompts the user to type a he! number o0 0our he! digits or less, and outputs it n binary on the ne!t line. 0 the user enters an illegal character, he or she should be 9 prompted to begin again. *ccept only uppercase letters. Sample exenitio11: :=& * >&B '@A& ( 5555)# la &-* >&B +-, : *-*'# l*C ' '*=: 11111111 11111111 .model small .stack 100h .data msg1 db 10,1,' Ape a hex n!mber G0 to H$' msg2 db 10,1,'6llegal hex digit,trA again$' msg db 10,1,'6n BinarA it is $' .code mov ax,@data mov ds,ax )mp inp!t inp!t invalid lea dx, msg2 mov ah,9 int 21h inp!t lea dx,msg1 mov ah,9 int 21h xor bx,bx mov cl,# mov ah,1 int 21h
convert cmp al,0dh )e endIinp!t cmp al,'0' )b invalid cmp al,'' )a invalid cmp al,9h )a letter and al,0h )mp let letter s!b al,d convert char to binarA let shl bx,cl or bl,al mov ah,1 int 21h )mp convert endIinp!t lea dx,msg mov ah,9 int 21h xor dx,dx mov cx,1J printIbinarA
shl bx,1 catch bx bit )c one c1 mov dl,0h )mp displaA one mov dl,1h displaA mov ah,2 int 21h loop printIbinarA main endp end main
**. Write a program that.prompts the user to type a 2inary num2er of *= digits or less, and outputs $t $n hex on the next line. $f the user enters an illegal character, he or she should 2e prompted to 2egin again .
... . .. ·- -·!8E A BINA! NUMBE" > !; #$ /$?$!S: ###%%%%# $ #E- $! $S El
.model small .stack 100h .data msg1 db 'Ape 'Ape a binarA n!mber !pto 1J digits$' msg2 db 10,1,'in hex it is$' .code main proc mov ax,@data mov ds,ax lea dx,msg1 mov ah,9 int 21h xor bx,bx mov ah,1 int 21h inp!t cmp al,0dh )e exit and al,0h shl bx,1 or bl,al int 21h )mp inp!t inp!t exit lea dx,msg2
mov ah,9 int 21h mov cx,# convert mov dl,bh shr dl,1 shr dl,1 shr dl,1 shr dl,1 cmp dl,9 )be n!m add dl,d )mp displaA n!m add dl,0h
displaA mov ah,2 int 21h rcl bx,1 rcl bx,1 rcl bx,1 rcl bx,1 loop convert main endp end main
*1. Write a program that prompts the user to enter two.2inary num2ers of up to 4 digits each, and prints their sum on the next line in 2inary. $f the user enters an illegal character, he or she should 2e prompted to 2egin again. Each input ends with a carriage return. !8E '% @$%"8 >0@E", > !; 4 /$?$!S: **++*+*+ !8E '% @$%"8 >0@E", > !; 4 /$?$!S: *++***++ !#E @$%"8 S>0 *+**++**+
.model small .stack 100h .data msg1 db 10,13,'Type a binary number upto 8 digits:$' msg2 db 10,13,'The binary sum is:$' .code main proc
mo a!,"data mo ds,a! lea d!,msg1 mo ah,# int 21h mo ah,1 int 21h !or b!,b! mo c!,8 input1: mo ah,1 int 21h cmp al,0dh e break and al,0%h &conert to binary shl bl,1 &make room %or ne alue or bl,al &insert alue loop input1 break: lea d!,msg1 mo ah,# int 21h mo c!,8 input2: mo ah,1 int 21h cmp al,0dh e break2 and al,0%h shl bh,1
&conert to binary &make room %or ne alue
or bh,al
&insert alue
loop input2
break2: lea d!,msg2 mo ah,# int 21h sum: add bl,bh &sum binary 00000011(00000010, bl)000000101 nc *ero &i% sum has no carry then no need to print *ero mo dl,31h mo ah,2 int 21h &i% sum has carry 1 then need to print 1 *ero: mo dl,30h mo c!,8 print: shl bl,1 &sending one by onee bit to print 000000101 nc * mo dl,31h mp display *: mo dl,30h display: mo ah,2 int 21h loop print main endp end main
;utput