SlideShare uma empresa Scribd logo
1 de 17
Baixar para ler offline
A solution manual to
Assembly language
Programming
and the organization of
the IBM PC
Chapter 6
Flow control instructions
BY:- Ytha Yu & Charles Marut
prepared by :
Warda Aziz
Wardaaziz555@gmail.com
Question 1:
Write assembly code for each of the following decision structures.
A) IF AX<0
THEN
PUT -1 IN BX
END_IF
SOLUTION:
;this is just an instruction, editing is required while implementing
CMP AX, 0 ;condition if(ax<0)
JL loop_ ;goto loop
JMP end_if
Loop_: ;loop:
MOV BX,-1 ;loop body
end_if: ;else {}
;DOS EXIT ;return 0
B) IF AL<0
THEN
Put FFh in AH
ELSE
Put 0 in AH
END_IF
SOLUTION:
;this is just an instruction, editing is required while implementing
CMP AL,0
JL loop_
JMP loop1
Loop_:
MOV AH, 0FFh
JMP end_if
Loop1:
MOV AH, 0
JMP end_if
end_if:
;DOS EXIT
C) Suppose DL contains the ASCII code of a character.
(IF DL>= “A”) AND (DL<= “Z”)
THEN
Display DL
END_IF
Solution:
No editing required, just add the format of assembly
MOV AH,1
INT 21h
MOV dl, al
CMP dl,"A"
JGE jump
JMP exit
jump:
CMP DL, 'Z'
JLE jumpe
JMP exit
jumpe:
MOV AH,2
INT 21H
JMP exit
exit:
;DOS exit
D) if AX<BX
THEN
IF BX<CX
THEN
PUT 0 IN AX
ELSE
Put 0 in BX
End_ifEnd_if
Solution:
MOV AX,5
MOV BX,6
MOV CX,7
CMP AX,BX ;if ax is less then bx , then check another condition
JB label
JMP end_if
MOV AX, 0
Label:
CMP BX, CX ;if BX<CX satisfies then mov 0 in ax and terminate the code
JB label2
MOV BX,0
JMP end_if
Label2:
MOV AX,0
JMP end_if
end_if:
MOV ah,4ch
INT 21h
E) if(AX<BX) OR (BX<CX)
Then
Put 0 in DX
Else
Put 1in DX
End_if
Solution:
No editing required
MOV AX,7
MOV BX,6
MOV CX,5
CMP AX,BX ;if ax is less then bx , mov 0 in dx
JB label
CMP BX, CX ; OR if BX<CX satisfies then mov 0 in dx
JB label
MOV DX,1 ;else mov 1 in dx
JMP end_if
Label:
MOV DX,0
JMP end_if
end_if:
MOV AH,4ch
INT 21h
F) if AX<BX
THEN
Put 0 in AX
Else
If(BX<CX)
Then
Put 0 in BX
Else
Put 0 in cx
end_if
End_if
Solution:
MOV AX,7
MOV BX,6
MOV CX,5
CMP AX,BX ;if ax is less then bx , mov 0 in ax
JB label
CMP BX, CX ;else if ax is greater then bx then perform this section
JB label2 ;if bx<cx , mov 0 in bx
MOV CX,0 ;else mov 0 in cx
JMP end_if
label: ;label
MOV AX , 0
JMP end_if
Label2: ;label 2
MOV BX,0
JMP end_if
end_if:
MOV AH,4Ch
INT 21h
Question 2:
Use a CASE structure to code the following:
 Read a chracter.
 If it’s ‘A’, then execute carriage return
 If it’s ‘B’, then execute line feed
 If it’s any other chracter , then return to DOS
ANS:
MOV AH, 1
INT 21h
MOV BL,AL ;reading a character and storing in another register
CMP Bl, 'A' ;IF character = A
JE carriage ;jump carriage
CMP Bl,'B' ;else if character=B
JE line ;jump to line
JMP exit ;else exit
carriage:
MOV AH,2
MOV DL, 0Dh
INT 21h
MOV DL, BL
INT 21H
JMP exit
line:
MOV AH,2
MOV DL, 0Ah
INT 21H
MOV DL, BL
INT 21H
exit:
MOV AH,4ch
INT 21h
Question 3:
Write a sequence of instruction to code each of the following
A) Put the sum 1+4+7+…+148 in AX
B) Put the sum 100+95+90+…+5 in AX
Solution:
A)
;Put the sum 1+4+7+...+148 in AX main endp
MOV CX, 49;counter for FOR LOOP
MOV AX,1 ;adds the sum of series and store the result
MOV BX,1 ;used to move the series 3 steps forward forward
Label:
ADD AX,BX
ADD BX,3
LOOP Label
;DOS exit
INT 21H
MOV AH,4CH
INT 21H
B) Put the sum 100+95+90+…+5 in AX
MOV CX, 19;counter for FOR LOOP
MOV AX,100 ;adds the sum of series and store the result
MOV BX,100 ;used to move the series 3 steps forward forward
Label:
ADD AX,BX
SUB BX,3
LOOP Label
;DOS exit
INT 21H
MOV AH,4CH
INT 21H
Question 4:
Employee LOOP to do the following:
 Put the sum of the first 50 terms of the arithmetic sequence
1,5,9,13,… in DX
 Read a character and display it 80 times on the next line
 Read a five character password and overprint it by executing
a carriage return and display five X’s. you need not store the
input characters anywhere.
Put the sum of the first 50 terms of the arithmetic sequence 1,5,9,13,… in DX
MOV CX,50
MOV BX,1
MOV DX,1
label:
ADD DX,BX
ADD BX, 4
LOOP label
Read a character and display it 80 times on the next line
MOV CX, 80
MOV AH,1
INT 21h
MOV AH,2
MOV DL,AL
label:
INT 21H
LOOP label
Read a five character password and overprint it by executing a carriage return
and display five X’s. you need not store the input characters anywhere.
MOV AH,7
INT 21H
INT 21H
INT 21H
INT 21H
INT 21H
MOV AH,2
MOV DL,0DH
INT 21H
MOV CX,5
LABEL:
MOV DL,'X'
INT 21H
LOOP LABEL
Question 5:
The following algorithm may be used to carry out division of two
non-negative numbers by repeated subtraction
;let AX contains the quotient
;BX contains dividend
;DX contains divisor then
MOV AX,0
LABEL:
CMP BX,DX
JGE label2
JMP end
LABEL2:
INC AX
SUB DX,BX
JMP label
EXIT:
;DOS exit
Question 6:
The following algorithm may be used to carry out multiplication
of two positive numbers M and N by repeated addition:
Initialize product to 0
Repeat
Add m to product
Decrement N
Untill n=0
Write a sequence of instructions to multiplay AX by BX and put
the product in CX. You may ignore the possibility of overflow
Let ax contains the product
MOV CX,0
LABEL:
ADD CX,AX
DEC BX
CMP BX,0
JNE label
Question 7:
It is possible to setup a count controlled loop that will continue to
execute as long as some condition is satisfied. Using LOOPE, LOOPZ,
LOOPNE, LOOPNZ do the following :
a) Write instructions to read characters until either a non blank
character is typed , or 80 characters have been typed. Use
LOOPE
b) Write instructions to read characters until either a carriage
return is typed , or 80 characters have been typed. Use LOOPNE
Write instructions to read characters until either a non blank character is typed ,
or 80 characters have been typed. Use LOOPE
MOV CX,80
MOV AH,1
Label:
INT 21h
CMP AL, 20h
LOOPE EXIT
LOOP LABEL
EXIT:
MOV AH,4CH
INT 21H
Write instructions to read characters until either a carriage return is typed , or
80 characters have been typed. Use LOOPNE
MOV CX,80
MOV AH,1
Label:
INT 21h
CMP AL, 0Dh
LOOPNE LABEL
EXIT:
MOV AH,4CH
INT 21H
Question 8:
Write a program to display a “?”, read two capital letters, and
display them on the next line in alphabetical order.
CODE:
.MODEL SMALL
.STACK 100h
.DATA
ms db 'Enter two letters $'
ch1 DB ?
ch2 DB ?
.CODE
MAIN PROC
MOV AX,@data
MOV DS, AX
;prompt the user
MOV AH, 9
LEA DX, ms
INT 21h
; read two characters
MOV AH, 1
INT 21h
MOV ch1,AL
INT 21h
MOV ch2, AL
;comparing the values
CMP ch1, AL
JB ascending
JA descending
JMP exit
ascending:
MOV AH,2
MOV DL, ch1
INT 21h
MOV DL, ch2
INT 21H
JMP exit
descending:
MOV AH,2
MOV DL, ch2
INT 21h
MOV DL, ch1
INT 21H
JMP exit
exit:
MOV ah,4ch
INT 21h
MAIN ENDP
END MAIN
Output:
Question 9:
Write a program to display the extended ASCII characters
(ASCII codes 80h to FFh). display 10 characters per line, separated
by blanks. Stop after the extended characters have been displayed
once.
Solution:
.MODEL SMALL
.STACK 100h
.DATA
.CODE
MAIN PROC
;prompt the user
MOV AH, 2
MOV CL, 0 ;for space
MOV DL, 80H ;initializing dl and bl to character at address 80h
MOV BL,80h
WHILE_:
MOV DL,BL ;restoring in dl for displaying
INT 21H
CMP DL, 0FFh
JE exit
INC Dl
MOV BL,DL ;temporarily storing dl
MOV DL,20h ;for space
INT 21h
INC CL ;incrementing in char for space
CMP cl, 10
JE line
MOV DL,BL
JMP WHILE_
line:
MOV dl,0ah
INT 21h
MOV dl,0dh
INT 21h
MOV cl,0
JMP while_
exit:
MOV ah,4ch
INT 21h
MAIN ENDP
END MAIN
Output
Question 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 if he want 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.
Solution:
CODE:
.MODEL SMALL
.STACK 100h
.DATA
msg DB 0AH,0DH,'Enter a hex character from ‘0’,…, ‘9’ or ‘A’,…, ‘F’$'
ch1 DB ?
ch2 DB ?
msg1 DB 0AH,0DH,"in decimal it is "
ch3 DB ?, "$"
msg2 DB 0AH,0DH,"In decimal it is: 1"
C2 DB ?,'$ '
msg3 DB 0AH,0DH,"do you want to check more results?",0ah,0dh,"type y for
yes , n for no "
c3 DB ?, "$"
msg4 DB 0AH,0DH,"invlaid input try again $"
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS, AX
again:
;prompt the user
MOV AH, 9
LEA dx, msg
INT 21h
; read a character
MOV AH, 1
INT 21h
MOV ch1,AL
;CHECKING the hex character
CMP ch1, 39h ;39h=9
JBE dig
CMP ch1, 46h ;46H=F
JBE character
MOV AH,9
LEA DX, msg4
INT 21h
JMP again
input:
;if user want to take next input
MOV AH,9
LEA DX,msg3
INT 21h
MOV AH,1
INT 21h
MOV c3, AL
CMP c3, 'y'
JE again
CMP c3, 'Y'
JE again
JMP exit
character:
;CALCULATION for hex character
SUB AL, 11h
MOV C2,AL
MOV AH,9
LEA DX, msg2
INT 21H
JMP input
dig:
MOV AH,9
LEA DX, msg1
INT 21h
MOV AH,2
MOV DL, ch1
INT 21H
JMP input
exit:
MOV ah,4ch
INT 21h
MAIN ENDP
END MAIN
OUTPUT:
Question 11:
Do programming exercise 10, except that if the user fails to enter
a hex-digit character in three tries, display a message and terminates
the program.
CODE:
.MODEL SMALL
.STACK 100h
.DATA
msg DB 0AH,0DH,'Enter a hex character $'
ch1 DB ?
ch2 DB ?
msg1 DB 0AH,0DH,"in decimal it is "
ch3 DB ?, "$"
msg2 DB 0AH,0DH,"In decimal it is: 1"
C2 DB ?,'$ '
msg3 DB 0AH,0DH,"do you want to check more results?",0ah,0dh,"type y
for yes , n for no "
c3 DB ?, "$"
msg4 DB 0AH,0DH,"invalid input! $"
msg5 DB 0AH,0DH ,"Entered invalid input for three times! $"
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS, AX
MOV BL,0
again:
;prompt the user
MOV AH, 9
LEA DX, msg
INT 21h
; read a character
MOV AH, 1
INT 21h
MOV ch1,AL
;CHECKING the hex character
CMP ch1, 39h ;39h=9
JBE dig
CMP ch1, 46h ;46H=F
JBE character
MOV AH,9
LEA DX, msg4 ;invalid input try again
INT 21h
INC bl
CMP BL,3
JE DISP
JMP again
DISP:
MOV AH,9
LEA DX, msg5
INT 21h
JMP exit
input:
;if user want to take next input
MOV AH,9
LEA DX,msg3
INT 21h
MOV AH,1
INT 21h
MOV c3, AL
CMP c3, 'y'
JE again
CMP c3, 'Y'
JE again
JMP exit
character:
;CALCULATION for hex character
SUB AL, 11h
MOV C2,AL
MOV AH,9
LEA DX, msg2
INT 21H
JMP input
dig:
MOV AH,9
LEA DX, msg1
INT 21h
MOV AH,2
MOV DL, ch1
INT 21H
JMP input
exit:
MOV ah,4ch
INT 21h
MAIN ENDP
END MAIN
OUTPUT:
Question 12:
Write a program that reads a string of capital letters , ending
with carriage return and display the longest sequence of consecutive
alphabetically increasing capital letters read.
CODE:
#copied from internet
.STACK 100h
.MODEL small
.DATA
inputmsg DB 'Enter a string of capital etters: $'
outputmsg DB 0dh, 0Ah, 'The longest consecutive increasing string is: $ '
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS,AX
MOV CH,0 ;ch
MOV AH,9 ;dislaying input message
LEA DX,inputmsg
INT 21H
INPUT_1:
MOV AH,1
INT 21H
CMP AL, 0DH
JE end_
MOV CL,1
MOV BL,AL
MOV DH, AL
INPUT_2:
INT 21H
CMP AL,0dh
JE END_
INC bl
CMP BL,AL
JNE init
INC cl
JMP input_2
INIT:
CMP CH, CL
JL update
MOV CL,1
MOV BL,AL
MOV DH,AL
JMP input_2
update:
MOV ch,cl
MOV bh,dh
MOV cl,1
MOV bl,al
MOV dh,al
MOV input_2
end_:
CMP CH,CL
JL Reupdate
JMP end_2
reupdate:
MOV CH,CL
MOV BH,DH
JMP end_2
end_2:
MOV ah,9
Lea dx, outputmsg
INT 21h
MOV ah,2
MOV dl, bh
output:
CMP ch, 0
JE finish
DEC ch
INT 21h
INC dl
JMP output
finish:
MOV ah,4ch
INT 21h
main endp
end main
Output:

Mais conteúdo relacionado

Mais procurados

Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...Bilal Amjad
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...Bilal Amjad
 
Representation of numbers and characters
Representation of numbers and charactersRepresentation of numbers and characters
Representation of numbers and characterswarda aziz
 
Binary and hex input/output (in 8086 assembuly langyage)
Binary and hex input/output (in 8086 assembuly langyage)Binary and hex input/output (in 8086 assembuly langyage)
Binary and hex input/output (in 8086 assembuly langyage)Bilal Amjad
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...Bilal Amjad
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...Bilal Amjad
 
Assembly language (coal)
Assembly language (coal)Assembly language (coal)
Assembly language (coal)Hareem Aslam
 
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...Bilal Amjad
 
Jumps in Assembly Language.
Jumps in Assembly Language.Jumps in Assembly Language.
Jumps in Assembly Language.NA000000
 
Assembly Language Lecture 4
Assembly Language Lecture 4Assembly Language Lecture 4
Assembly Language Lecture 4Motaz Saad
 
Solution manual of assembly language programming and organization of the ibm ...
Solution manual of assembly language programming and organization of the ibm ...Solution manual of assembly language programming and organization of the ibm ...
Solution manual of assembly language programming and organization of the ibm ...Tayeen Ahmed
 
Logic, shift and rotate instruction
Logic, shift and rotate instructionLogic, shift and rotate instruction
Logic, shift and rotate instructionkashif Shafqat
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...Bilal Amjad
 
Assembly Language Lecture 5
Assembly Language Lecture 5Assembly Language Lecture 5
Assembly Language Lecture 5Motaz Saad
 
Flag Registers (Assembly Language)
Flag Registers (Assembly Language)Flag Registers (Assembly Language)
Flag Registers (Assembly Language)Anwar Hasan Shuvo
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Bilal Amjad
 
Addressing Modes Of 8086
Addressing Modes Of 8086Addressing Modes Of 8086
Addressing Modes Of 8086Ikhlas Rahman
 
Flow control instructions
Flow control instructionsFlow control instructions
Flow control instructionsProdip Ghosh
 
Multiplication & division instructions microprocessor 8086
Multiplication & division instructions microprocessor 8086Multiplication & division instructions microprocessor 8086
Multiplication & division instructions microprocessor 8086University of Gujrat, Pakistan
 

Mais procurados (20)

Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
 
Representation of numbers and characters
Representation of numbers and charactersRepresentation of numbers and characters
Representation of numbers and characters
 
Binary and hex input/output (in 8086 assembuly langyage)
Binary and hex input/output (in 8086 assembuly langyage)Binary and hex input/output (in 8086 assembuly langyage)
Binary and hex input/output (in 8086 assembuly langyage)
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
 
Assembly language (coal)
Assembly language (coal)Assembly language (coal)
Assembly language (coal)
 
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
 
Jumps in Assembly Language.
Jumps in Assembly Language.Jumps in Assembly Language.
Jumps in Assembly Language.
 
Assembly Language Lecture 4
Assembly Language Lecture 4Assembly Language Lecture 4
Assembly Language Lecture 4
 
Solution manual of assembly language programming and organization of the ibm ...
Solution manual of assembly language programming and organization of the ibm ...Solution manual of assembly language programming and organization of the ibm ...
Solution manual of assembly language programming and organization of the ibm ...
 
DAA AND DAS
DAA AND DASDAA AND DAS
DAA AND DAS
 
Logic, shift and rotate instruction
Logic, shift and rotate instructionLogic, shift and rotate instruction
Logic, shift and rotate instruction
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...
 
Assembly Language Lecture 5
Assembly Language Lecture 5Assembly Language Lecture 5
Assembly Language Lecture 5
 
Flag Registers (Assembly Language)
Flag Registers (Assembly Language)Flag Registers (Assembly Language)
Flag Registers (Assembly Language)
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
 
Addressing Modes Of 8086
Addressing Modes Of 8086Addressing Modes Of 8086
Addressing Modes Of 8086
 
Flow control instructions
Flow control instructionsFlow control instructions
Flow control instructions
 
Multiplication & division instructions microprocessor 8086
Multiplication & division instructions microprocessor 8086Multiplication & division instructions microprocessor 8086
Multiplication & division instructions microprocessor 8086
 

Semelhante a Chapter 6 Flow control Instructions

Taller practico emu8086_galarraga
Taller practico emu8086_galarragaTaller practico emu8086_galarraga
Taller practico emu8086_galarragaFabricio Galárraga
 
Loop instruction, controlling the flow of progam
Loop instruction, controlling the flow of progamLoop instruction, controlling the flow of progam
Loop instruction, controlling the flow of progamDr. Girish GS
 
1344 Alp Of 8086
1344 Alp Of 80861344 Alp Of 8086
1344 Alp Of 8086techbed
 
Emulador de ensamblador emu8086
Emulador de ensamblador emu8086Emulador de ensamblador emu8086
Emulador de ensamblador emu8086Marco Muñoz
 
Lenguaje ensamblador EMU8086
Lenguaje ensamblador EMU8086Lenguaje ensamblador EMU8086
Lenguaje ensamblador EMU8086Santy Bolo
 
Assembly lab up to 6 up (1)
Assembly lab up to 6 up (1)Assembly lab up to 6 up (1)
Assembly lab up to 6 up (1)ilias ahmed
 
Instalación de emu8086 y compilados
Instalación de emu8086 y compiladosInstalación de emu8086 y compilados
Instalación de emu8086 y compiladosDiego Erazo
 
Assembly language programs 2
Assembly language programs 2Assembly language programs 2
Assembly language programs 2HarshitParkar6677
 
Emulador de ensamblador EMU8086
Emulador de ensamblador EMU8086Emulador de ensamblador EMU8086
Emulador de ensamblador EMU8086Jhon Alexito
 
Instalación de emu8086
Instalación de emu8086Instalación de emu8086
Instalación de emu8086Alex Toapanta
 

Semelhante a Chapter 6 Flow control Instructions (20)

Taller practico emu8086_galarraga
Taller practico emu8086_galarragaTaller practico emu8086_galarraga
Taller practico emu8086_galarraga
 
Loop instruction, controlling the flow of progam
Loop instruction, controlling the flow of progamLoop instruction, controlling the flow of progam
Loop instruction, controlling the flow of progam
 
Lecture6
Lecture6Lecture6
Lecture6
 
Assembly language programs
Assembly language programsAssembly language programs
Assembly language programs
 
1344 Alp Of 8086
1344 Alp Of 80861344 Alp Of 8086
1344 Alp Of 8086
 
Taller Ensambladores
Taller EnsambladoresTaller Ensambladores
Taller Ensambladores
 
Emulador de ensamblador emu8086
Emulador de ensamblador emu8086Emulador de ensamblador emu8086
Emulador de ensamblador emu8086
 
Lenguaje ensamblador EMU8086
Lenguaje ensamblador EMU8086Lenguaje ensamblador EMU8086
Lenguaje ensamblador EMU8086
 
Assembly lab up to 6 up (1)
Assembly lab up to 6 up (1)Assembly lab up to 6 up (1)
Assembly lab up to 6 up (1)
 
Instalación de emu8086 y compilados
Instalación de emu8086 y compiladosInstalación de emu8086 y compilados
Instalación de emu8086 y compilados
 
Compiladores emu8086
Compiladores emu8086Compiladores emu8086
Compiladores emu8086
 
Assembly language programs 2
Assembly language programs 2Assembly language programs 2
Assembly language programs 2
 
Chapt 06
Chapt 06Chapt 06
Chapt 06
 
Chapt 06
Chapt 06Chapt 06
Chapt 06
 
Emulador de ensamblador EMU8086
Emulador de ensamblador EMU8086Emulador de ensamblador EMU8086
Emulador de ensamblador EMU8086
 
Exp 03
Exp 03Exp 03
Exp 03
 
جميع اوامر لغة الاسمبلي
جميع اوامر لغة الاسمبلي جميع اوامر لغة الاسمبلي
جميع اوامر لغة الاسمبلي
 
8086 instruction set
8086  instruction set8086  instruction set
8086 instruction set
 
Instalación de emu8086
Instalación de emu8086Instalación de emu8086
Instalación de emu8086
 
Lec06
Lec06Lec06
Lec06
 

Último

VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Christo Ananth
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 

Último (20)

VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 

Chapter 6 Flow control Instructions

  • 1. A solution manual to Assembly language Programming and the organization of the IBM PC Chapter 6 Flow control instructions BY:- Ytha Yu & Charles Marut prepared by : Warda Aziz Wardaaziz555@gmail.com
  • 2. Question 1: Write assembly code for each of the following decision structures. A) IF AX<0 THEN PUT -1 IN BX END_IF SOLUTION: ;this is just an instruction, editing is required while implementing CMP AX, 0 ;condition if(ax<0) JL loop_ ;goto loop JMP end_if Loop_: ;loop: MOV BX,-1 ;loop body end_if: ;else {} ;DOS EXIT ;return 0 B) IF AL<0 THEN Put FFh in AH ELSE Put 0 in AH END_IF SOLUTION: ;this is just an instruction, editing is required while implementing CMP AL,0 JL loop_ JMP loop1 Loop_: MOV AH, 0FFh JMP end_if Loop1: MOV AH, 0 JMP end_if end_if: ;DOS EXIT C) Suppose DL contains the ASCII code of a character. (IF DL>= “A”) AND (DL<= “Z”) THEN Display DL END_IF Solution: No editing required, just add the format of assembly MOV AH,1 INT 21h MOV dl, al
  • 3. CMP dl,"A" JGE jump JMP exit jump: CMP DL, 'Z' JLE jumpe JMP exit jumpe: MOV AH,2 INT 21H JMP exit exit: ;DOS exit D) if AX<BX THEN IF BX<CX THEN PUT 0 IN AX ELSE Put 0 in BX End_ifEnd_if Solution: MOV AX,5 MOV BX,6 MOV CX,7 CMP AX,BX ;if ax is less then bx , then check another condition JB label JMP end_if MOV AX, 0 Label: CMP BX, CX ;if BX<CX satisfies then mov 0 in ax and terminate the code JB label2 MOV BX,0 JMP end_if Label2: MOV AX,0 JMP end_if end_if: MOV ah,4ch INT 21h E) if(AX<BX) OR (BX<CX) Then Put 0 in DX Else Put 1in DX End_if
  • 4. Solution: No editing required MOV AX,7 MOV BX,6 MOV CX,5 CMP AX,BX ;if ax is less then bx , mov 0 in dx JB label CMP BX, CX ; OR if BX<CX satisfies then mov 0 in dx JB label MOV DX,1 ;else mov 1 in dx JMP end_if Label: MOV DX,0 JMP end_if end_if: MOV AH,4ch INT 21h F) if AX<BX THEN Put 0 in AX Else If(BX<CX) Then Put 0 in BX Else Put 0 in cx end_if End_if Solution: MOV AX,7 MOV BX,6 MOV CX,5 CMP AX,BX ;if ax is less then bx , mov 0 in ax JB label CMP BX, CX ;else if ax is greater then bx then perform this section JB label2 ;if bx<cx , mov 0 in bx MOV CX,0 ;else mov 0 in cx JMP end_if label: ;label MOV AX , 0
  • 5. JMP end_if Label2: ;label 2 MOV BX,0 JMP end_if end_if: MOV AH,4Ch INT 21h Question 2: Use a CASE structure to code the following:  Read a chracter.  If it’s ‘A’, then execute carriage return  If it’s ‘B’, then execute line feed  If it’s any other chracter , then return to DOS ANS: MOV AH, 1 INT 21h MOV BL,AL ;reading a character and storing in another register CMP Bl, 'A' ;IF character = A JE carriage ;jump carriage CMP Bl,'B' ;else if character=B JE line ;jump to line JMP exit ;else exit carriage: MOV AH,2 MOV DL, 0Dh INT 21h MOV DL, BL INT 21H JMP exit line: MOV AH,2 MOV DL, 0Ah INT 21H MOV DL, BL INT 21H exit: MOV AH,4ch INT 21h Question 3: Write a sequence of instruction to code each of the following A) Put the sum 1+4+7+…+148 in AX B) Put the sum 100+95+90+…+5 in AX Solution: A)
  • 6. ;Put the sum 1+4+7+...+148 in AX main endp MOV CX, 49;counter for FOR LOOP MOV AX,1 ;adds the sum of series and store the result MOV BX,1 ;used to move the series 3 steps forward forward Label: ADD AX,BX ADD BX,3 LOOP Label ;DOS exit INT 21H MOV AH,4CH INT 21H B) Put the sum 100+95+90+…+5 in AX MOV CX, 19;counter for FOR LOOP MOV AX,100 ;adds the sum of series and store the result MOV BX,100 ;used to move the series 3 steps forward forward Label: ADD AX,BX SUB BX,3 LOOP Label ;DOS exit INT 21H MOV AH,4CH INT 21H Question 4: Employee LOOP to do the following:  Put the sum of the first 50 terms of the arithmetic sequence 1,5,9,13,… in DX  Read a character and display it 80 times on the next line  Read a five character password and overprint it by executing a carriage return and display five X’s. you need not store the input characters anywhere. Put the sum of the first 50 terms of the arithmetic sequence 1,5,9,13,… in DX MOV CX,50 MOV BX,1 MOV DX,1 label: ADD DX,BX ADD BX, 4 LOOP label Read a character and display it 80 times on the next line MOV CX, 80 MOV AH,1
  • 7. INT 21h MOV AH,2 MOV DL,AL label: INT 21H LOOP label Read a five character password and overprint it by executing a carriage return and display five X’s. you need not store the input characters anywhere. MOV AH,7 INT 21H INT 21H INT 21H INT 21H INT 21H MOV AH,2 MOV DL,0DH INT 21H MOV CX,5 LABEL: MOV DL,'X' INT 21H LOOP LABEL Question 5: The following algorithm may be used to carry out division of two non-negative numbers by repeated subtraction ;let AX contains the quotient ;BX contains dividend ;DX contains divisor then MOV AX,0 LABEL: CMP BX,DX JGE label2 JMP end LABEL2: INC AX SUB DX,BX JMP label EXIT: ;DOS exit Question 6: The following algorithm may be used to carry out multiplication of two positive numbers M and N by repeated addition: Initialize product to 0 Repeat Add m to product Decrement N Untill n=0
  • 8. Write a sequence of instructions to multiplay AX by BX and put the product in CX. You may ignore the possibility of overflow Let ax contains the product MOV CX,0 LABEL: ADD CX,AX DEC BX CMP BX,0 JNE label Question 7: It is possible to setup a count controlled loop that will continue to execute as long as some condition is satisfied. Using LOOPE, LOOPZ, LOOPNE, LOOPNZ do the following : a) Write instructions to read characters until either a non blank character is typed , or 80 characters have been typed. Use LOOPE b) Write instructions to read characters until either a carriage return is typed , or 80 characters have been typed. Use LOOPNE Write instructions to read characters until either a non blank character is typed , or 80 characters have been typed. Use LOOPE MOV CX,80 MOV AH,1 Label: INT 21h CMP AL, 20h LOOPE EXIT LOOP LABEL EXIT: MOV AH,4CH INT 21H Write instructions to read characters until either a carriage return is typed , or 80 characters have been typed. Use LOOPNE MOV CX,80 MOV AH,1 Label: INT 21h CMP AL, 0Dh LOOPNE LABEL EXIT: MOV AH,4CH INT 21H Question 8: Write a program to display a “?”, read two capital letters, and display them on the next line in alphabetical order.
  • 9. CODE: .MODEL SMALL .STACK 100h .DATA ms db 'Enter two letters $' ch1 DB ? ch2 DB ? .CODE MAIN PROC MOV AX,@data MOV DS, AX ;prompt the user MOV AH, 9 LEA DX, ms INT 21h ; read two characters MOV AH, 1 INT 21h MOV ch1,AL INT 21h MOV ch2, AL ;comparing the values CMP ch1, AL JB ascending JA descending JMP exit ascending: MOV AH,2 MOV DL, ch1 INT 21h MOV DL, ch2 INT 21H JMP exit descending: MOV AH,2 MOV DL, ch2 INT 21h MOV DL, ch1 INT 21H JMP exit exit: MOV ah,4ch INT 21h MAIN ENDP END MAIN
  • 10. Output: Question 9: Write a program to display the extended ASCII characters (ASCII codes 80h to FFh). display 10 characters per line, separated by blanks. Stop after the extended characters have been displayed once. Solution: .MODEL SMALL .STACK 100h .DATA .CODE MAIN PROC ;prompt the user MOV AH, 2 MOV CL, 0 ;for space MOV DL, 80H ;initializing dl and bl to character at address 80h MOV BL,80h WHILE_: MOV DL,BL ;restoring in dl for displaying INT 21H CMP DL, 0FFh JE exit INC Dl MOV BL,DL ;temporarily storing dl MOV DL,20h ;for space INT 21h INC CL ;incrementing in char for space CMP cl, 10 JE line MOV DL,BL JMP WHILE_ line: MOV dl,0ah INT 21h MOV dl,0dh INT 21h MOV cl,0 JMP while_ exit: MOV ah,4ch
  • 11. INT 21h MAIN ENDP END MAIN Output Question 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 if he want 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. Solution: CODE: .MODEL SMALL .STACK 100h .DATA msg DB 0AH,0DH,'Enter a hex character from ‘0’,…, ‘9’ or ‘A’,…, ‘F’$' ch1 DB ? ch2 DB ? msg1 DB 0AH,0DH,"in decimal it is " ch3 DB ?, "$" msg2 DB 0AH,0DH,"In decimal it is: 1" C2 DB ?,'$ ' msg3 DB 0AH,0DH,"do you want to check more results?",0ah,0dh,"type y for yes , n for no " c3 DB ?, "$" msg4 DB 0AH,0DH,"invlaid input try again $" .CODE MAIN PROC MOV AX,@DATA MOV DS, AX again: ;prompt the user
  • 12. MOV AH, 9 LEA dx, msg INT 21h ; read a character MOV AH, 1 INT 21h MOV ch1,AL ;CHECKING the hex character CMP ch1, 39h ;39h=9 JBE dig CMP ch1, 46h ;46H=F JBE character MOV AH,9 LEA DX, msg4 INT 21h JMP again input: ;if user want to take next input MOV AH,9 LEA DX,msg3 INT 21h MOV AH,1 INT 21h MOV c3, AL CMP c3, 'y' JE again CMP c3, 'Y' JE again JMP exit character: ;CALCULATION for hex character SUB AL, 11h MOV C2,AL MOV AH,9 LEA DX, msg2 INT 21H JMP input dig: MOV AH,9 LEA DX, msg1 INT 21h
  • 13. MOV AH,2 MOV DL, ch1 INT 21H JMP input exit: MOV ah,4ch INT 21h MAIN ENDP END MAIN OUTPUT: Question 11: Do programming exercise 10, except that if the user fails to enter a hex-digit character in three tries, display a message and terminates the program. CODE: .MODEL SMALL .STACK 100h .DATA msg DB 0AH,0DH,'Enter a hex character $' ch1 DB ? ch2 DB ? msg1 DB 0AH,0DH,"in decimal it is " ch3 DB ?, "$" msg2 DB 0AH,0DH,"In decimal it is: 1" C2 DB ?,'$ ' msg3 DB 0AH,0DH,"do you want to check more results?",0ah,0dh,"type y for yes , n for no " c3 DB ?, "$"
  • 14. msg4 DB 0AH,0DH,"invalid input! $" msg5 DB 0AH,0DH ,"Entered invalid input for three times! $" .CODE MAIN PROC MOV AX,@DATA MOV DS, AX MOV BL,0 again: ;prompt the user MOV AH, 9 LEA DX, msg INT 21h ; read a character MOV AH, 1 INT 21h MOV ch1,AL ;CHECKING the hex character CMP ch1, 39h ;39h=9 JBE dig CMP ch1, 46h ;46H=F JBE character MOV AH,9 LEA DX, msg4 ;invalid input try again INT 21h INC bl CMP BL,3 JE DISP JMP again DISP: MOV AH,9 LEA DX, msg5 INT 21h JMP exit input: ;if user want to take next input MOV AH,9 LEA DX,msg3 INT 21h MOV AH,1 INT 21h MOV c3, AL CMP c3, 'y' JE again CMP c3, 'Y' JE again
  • 15. JMP exit character: ;CALCULATION for hex character SUB AL, 11h MOV C2,AL MOV AH,9 LEA DX, msg2 INT 21H JMP input dig: MOV AH,9 LEA DX, msg1 INT 21h MOV AH,2 MOV DL, ch1 INT 21H JMP input exit: MOV ah,4ch INT 21h MAIN ENDP END MAIN OUTPUT: Question 12: Write a program that reads a string of capital letters , ending with carriage return and display the longest sequence of consecutive alphabetically increasing capital letters read. CODE: #copied from internet .STACK 100h .MODEL small .DATA inputmsg DB 'Enter a string of capital etters: $' outputmsg DB 0dh, 0Ah, 'The longest consecutive increasing string is: $ ' .CODE
  • 16. MAIN PROC MOV AX, @DATA MOV DS,AX MOV CH,0 ;ch MOV AH,9 ;dislaying input message LEA DX,inputmsg INT 21H INPUT_1: MOV AH,1 INT 21H CMP AL, 0DH JE end_ MOV CL,1 MOV BL,AL MOV DH, AL INPUT_2: INT 21H CMP AL,0dh JE END_ INC bl CMP BL,AL JNE init INC cl JMP input_2 INIT: CMP CH, CL JL update MOV CL,1 MOV BL,AL MOV DH,AL JMP input_2 update: MOV ch,cl MOV bh,dh MOV cl,1 MOV bl,al MOV dh,al MOV input_2 end_: CMP CH,CL JL Reupdate JMP end_2 reupdate: MOV CH,CL MOV BH,DH JMP end_2 end_2: MOV ah,9
  • 17. Lea dx, outputmsg INT 21h MOV ah,2 MOV dl, bh output: CMP ch, 0 JE finish DEC ch INT 21h INC dl JMP output finish: MOV ah,4ch INT 21h main endp end main Output: