0% found this document useful (0 votes)
25 views4 pages

MP CH 6

Chapter 6 covers flow control instructions in assembly programming, including logical conditions, jump instructions, and loops. It provides a glossary of key terms and introduces new instructions such as CMP, JCXZ, and LOOP. The chapter also includes exercises for practicing decision structures, arithmetic operations, and character input handling.

Uploaded by

ddeleteitlater
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views4 pages

MP CH 6

Chapter 6 covers flow control instructions in assembly programming, including logical conditions, jump instructions, and loops. It provides a glossary of key terms and introduces new instructions such as CMP, JCXZ, and LOOP. The chapter also includes exercises for practicing decision structures, arithmetic operations, and character input handling.

Uploaded by

ddeleteitlater
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Chapter 6 Row Conrrol Instructions 113

Glo~sary
AND coiuUtloa
.. A logical AND of two conditions
coaclltlonal jump A jump Instruction whose execution
iD.structlOD depends on status flag settings
loop A sequence of instructions that is repeated
OR coaclltlon A logical OR of two conditions
signed jump A conditional jump instruction used with
signed numbers
single-Dag jump A conditional jump that operates on the
setting of an individual status flag
top-clown program design Program development by breaking a large
problem Into a series of smaller problems
unconclltlonal j~mp An unconditional transfer of control
unsigned jump A conditional jump instruction used with
unsigned numbers

New Instructions
CMP JCXZ JLE/JNG
JA/JNBE JE/JZ JMP
JAE/JNB JG/JNLE JNC
JB/JNAE JGE/JNL JNE/JNZ
JBE/JNA JL/JNLE LOOP
JC

Exercises
1. Write asse~bJy.c~.e for ~ach of the following decision structures.
a. ·IF AX < 0
THEN
PUT -1 IN BX
END IF

b. IF "AL < 0
THEN
put FFh in AH'
ELSE
put 0 in AH
END_IF

.c. - Suppose DL contains the ASCII code of a character.


(IF Dl. >• "A'"I ANO . (DL <,. •z•)
THEN
display DL
END IF

d. IF AX < BX
THEN
IF BX i<
ex
THEN
114 Exer<;ises.

t'ut 0 in AX.
ELSE ''l~
put 0 iii BX
END_IF ·:.. -·
END_IF

e. IF (AX < BX) OR (BX < CX)


THEN
put 0 ·in ox
ELSE
put 1 in DX
END- IF

f. IF AY. < BX
THEN
put 0 ·in AX
ELSE
IF BY. < C'X
THEN
put 0 in BX
ELSE
put ·o in ex
END IF
END IF

2. Use a CASE structure to code the following:


Read a character.
If it's "A", then execute carriage return.
If it's "Bn, then execute line feed.
If it's any other character, then return to DOS.
Write a sequence of inst~ctions to do each of the following:
a. Ptit the sum 1 + 4 + 7"+ .. ;.+. 148 in AX.
b. Put the sum 100 + 95 + 90 + ... + 5 in AX.
Employ LOOP instructions to do the following:
a. put the sum of the first 50 terms of the arithmetic sequence
I, 5, 9, 13, ... in DX.
b. Read a character and display it 80 times on the next line.
c. Read a five~character password and overprint it by executing
a carriage return and displaying five X's. You need not store
the input characters anywhere.
The following algorithm may be used to carry out division of two
nonnegative numbers by repeated subtraction:
initial~ze quotient to 0
WHILE dividend >- divisor DO
increment quotient
subtract diOi~or from dividend
END_WHILE
Write a sequence of instructions to divide.AX by BX, and put the
quotient in ex.
Chapter 6 Flow Control Instructions 115

6. The following algorithm may be used to carry out multiplication


of. two positive numbers M and N by repcatecf addition:

initialize product to O
REPEAT
add M to product
decrement N
UNTIL N z 0

Write a sequence of instructions to multiply AX by BX, and put


the product in ex. You may Ignore the possibility of overflow.
7. It is possible to set up a count-controlled loop that will continue
to execute as' long as ~me condition Is satisfied. The instructions

LOOPE label ; loop while equa:).


and
LOOPZ l,abel ; loop while zero
cause ex to be decremented, then if CX <>. 0 and ZF = 1, control
transfers to the instruction at the destination label; if either ex =
0 or ZF = 0, the instruction following the loop is done. Similarly,
the instructions
LOOPNE label ;loop while not equal
and
LOOPNZ label ; loop while not zero
cause ex to be decremented, then if CX <> 0 and ZF .. 0, control
transfers to the instruction at the destination label; if either ex ..
0 or ZF "' 1, the Instruction following the loop is done.
a. Write Instructions to read characters until either a nonblank
character is typed, or 80 characters have been typed. Use
LOO PE.
b. Write instructions to read characters until eHher a carriage re-
turn Is typed or 80 characters have been typed. Use LOOPNE.

Programming Exercises
8. Write a program to display a "?", read two capital letters, and dis-
play them on the next line In alphabetical order.
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.
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.

Sample exen1tiot1: :-
116 Programf'(ling Exercises

ENTER A HEX DIGIT: 9


IN DECIMAL IS IT 9
DO YOU WANT TO DO IT AGAIN? y
ENTER A HEX DIGIT: c
ILLEGAL CHARACTER - ENTER 0 .. 9 OR A .. F: C
IN DECIMAL IT IS 12
DO YOU WANT TO DO IT AGAIN? N
11. Do programming exercise 10, except that if the user fails to enter
a hex-digit character In three tries, display a message and termi-
nate the program. ·
12. (hard) Write a program that reads a string of capital letters, end-
ing with a carriage return, and displays the longest sequence of
consecutive alphabetically increasing capital letters read.
Sample exec11tio11:
ENTER A STKING OF CAPITAL LETTERS:
FGHADEFGHC
THE LONGEST CONSECUTIVELY INCREASING STRING IS:
DEFGH

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy