Você está na página 1de 8

Chapter 6 Exercises and Answers

Answers are in blue.


For Exercises 1- 15, mark the answers true and false as follows:
A. True
B. False
1. Arithmetic can be performed in the Instruction Register.
B
2. Arithmetic can be performed in the A Register.
A
3. Arithmetic can be performed in the accumulator.
A
4.
LDA 0X008B,i loads 008B into register A.
A
5. ADDA 0x008B,i adds the contents of 008B to the A register.
B
6. The Program Counter and the Instruction Register are two names for the same place.
B
7. The A register and the accumulator are two names for the same place.
A
8. The Instruction Register is three bytes long.
A
9. The Program Counter is three bytes long.
B
10.
The branch instruction, BR, branches to the location specified in the operand specifier.
A
11. The instruction specifier is one bytes long.
B
12. If the data to be loaded into the accumulator is stored in the operand, the instruction specifier is 00.
A
13. If the data in the accumulator is to be stored in the place named in the operand, the instruction
specifier is 00.
B
14. All Pep! instructions occupy three bytes.
B
15. At least one branching instructions is re"uired in a loop.
A
Gien the followin! state of memor" #in hexadecimal$, answer Exercises 1% throu!h &' (" matchin!
the )ro(lem to the solution shown.
000# A2
000$ 11
000% 00
000& FF
A. A2 11
B. A2 12
C. 00 02
'. 11 00
(. 00 FF
16. )hat are the contents of the A register after the e*ecution of this instruction+
C1 00 01
A
17. )hat are the contents of the A register after the e*ecution of this instruction+
C1 00 02
D
18. )hat are the contents of the A register after the e*ecution of the following two instructions+
C0 00 01
70 00 01
C
19. )hat are the contents of the A register after the e*ecution of the following two instructions+
C1 00 01
70 00 01
B
20.
)hat are the contents of location 000# after the e*ecution of the following two instructions+
C1 00 03
E0 00 01
E
Exercises &1 - %' are )ro!rams or short answer *uestions.
21. )hat does it mean when we say that a computer is a programmable de,ice+
Programmable means that data and instructions are logically the same and are stored in the same
place. The conse"uence of this fact is that the program the computer e*ecutes is not wired into the
hardware but entered from outside.
22. -ist fi,e operations that any machine language must include.
There must be machine.language instructions to store, retrie,e, and process data, to input data and
to output data. These instructions mirror the operations of the ,on /eumann machine.
23.
0ow many low.le,el tas1s can each machine language instruction perform+
A machine language instruction can perform only one low.le,el tas1.
24. )hat is a ,irtual machine+ 'iscuss this definition in terms of the Pep! computer.
A ,irtual machine is a hypothetical machine designed to illustrate important features of a real
computer. The Pep! computer is a ,irtual machine designed to illustrate the features of the ,on
/eumann architecture. It has instructions to store, retrie,e, and process data as well as instructions
to input and output data.
25.
0ow many bits does an instruction ta1e in Pep!+
The instructions in Pep! are ,ariable length.
26. 'escribe the features of the Pep! CP2 that we co,ered in this chapter.
There is one register for arithmetic and logical operations3 the A register 4the accumulator5. There
is a Program Counter that contains the address of the ne*t instruction to be e*ecuted and the
Instruction Register that contains the instruction being e*ecuted. An operand may be immediate
4stored in the instruction specifier5 or direct 4stored in the place named in the instruction specifier5.
27.
)here is the data 4operand5 if the address mode specifier is3
a. 000
b. 00#
a. in the instruction specifier
b. in the place named in the instruction specifier
28.
)e discussed two mode specifiers. 0ow many are there+
!
29. 'istinguish between the IR 4instruction register5 and the PC 4program counter5.
The IR contains an instruction 4the one being e*ecuted56 the PC contains an address 4the address of
the ne*t instruction to be e*ecuted5.
30. 0ow many bits are re"uired to address the Pep! memory+
The Pep! memory contains 78,8%7 bytes, so #7 bits are re"uired to address each one.
31. 0ow many more cells could be added to memory without ha,ing to change the instruction format+
9ustify your answer.
/one. The operand specifier could not address more than the current memory.
32. :ome Pep! instructions are unary, ta1ing only one byte. ;ther instructions re"uire three bytes.
<i,en the instructions that we ha,e co,ered in this chapter, would it be useful to define instructions
that re"uire only two bytes+
The instructions we ha,e co,ered, other than the :top instruction, use the operand specifier of the
instruction. The operand specifier is two bytes long, so three bytes are re"uired for the instruction3
the instruction specifier and the operand specifier. Therefore, two.byte instructions would not be
useful.
33. If the input character is A, what is the result of e*ecuting the following two instructions+
000# 49 00 06
000& 51 00 06
A is written on the screen.
34.
If the input number is 8, what are the contents of the A register after e*ecuting the following
instructions+
000# 31 00 0F
000& +1 '' 'F
000= 70 00 02
=
35. )rite the algorithm for writing out your name, gi,en that the implementation language is Pep!
machine code.
)rite >/ell>
)rite >/>
)rite >e>
)rite >l>
)rite >l>
)rite >/>
)rite &( 4he*5
)rite >e>
)rite 78 4he*5
)rite >l>
)rite 7C 4he*5
)rite >l>
)rite 7C 4he*5
36. )rite the machine.language program to implement the algorithm in (*ercise %8.
80 00 &( 80 00 78 80 00 7C 80 00 7C ??
37. )rite the algorithm for writing out your name, gi,en that the implementation language is Pep!
assembly language.
)rite >/ell>
)rite >/>
)rite >e>
)rite >l>
)rite >l>
38. )rite the assembly.language program to implement the algorithm in (*ercise %=.
CHARO 0x004e,i ;Output 'N'
CHARO 0x0065,i ;Output 'e'
CHARO 0x006C,i ;Output 'l'
CHARO 0x006C,i ;Output 'l'
STOP.END
39. Rewrite the machine language program in 7.&, using direct addressing.
'irect addressing re"uires the ability to store ,alues into the addresses from which you are to
e*tract ,alues. )e did not co,er this in the te*t. If you went to Pep! documentation and found a
way to do this, more power to you.
40.
'istinguish between the Pep! menu options Assemble, Load, and Execute (run).
Assemble translates the assembly language program into machine code. Load puts the program into
memory ready to be e*ecuted. (*ecute e*ecutes the loaded program.
41. The following program seems to run, but does strange things with certain input ,alues. Can you
find the bug+
BR Main
sum: .WORD 0x0000
num1: .BLOCK 1
num2: .BLOCK 1
num3: .BLOCK 1
Main: LDA sum!
DEC" num1!
DEC" num2!
DEC" num3!
ADDA num3!
ADDA num2!
ADDA num1!
#$A sum!
DECO sum!
#$O%
.E&D
;ne byte of storage is set up for each input ,alue. If the ,alue that is read is grater than one byte,
the e*cess spills o,er to the byte abo,e gi,ing the wrong answer.
42. Correct the code in (*ercise &# and run the test plan outlined in the Chapter.

BR Main
sum: .WORD 0x0000
num1: .BLOCK 2
num2: .BLOCK 2
num3: .BLOCK 2
Main: LDA sum!
DEC" num1!
DEC" num2!
DEC" num3!
ADDA num3!
ADDA num2!
ADDA num1!
#$A sum!
DECO sum!
#$O%
.E&D
The test plan gi,es the correct answers with this code.
43. @inish e*ecuting the test plan for the algorithm in the te*t that reads and sums three ,alues.
The answers are correct.
44.
)rite a pseudocode algorithm that reads in three ,alues and writes out the result of subtracting the
second ,alue from the sum of the first and the third ,alues.
Read num1
Read num2
Read num3
Load num1
Add num3
Sub num2
Store in answer
Write answer
45. Implement the algorithm in (*ercise && as an assembly.language program.
BR Main
sum: .WORD 0x0000
num1: .BLOCK 2num2:
.BLOCK 2
num3: .BLOCK 2
ans'():.BLOCK 2Main:
DEC" num1!
DEC" num2!
DEC" num3!
LDA num1!
ADDA num3!
#*BA num2!
#$A ans'()!
DECO ans'()!
#$O%
.E&D
46. )rite and implement a test plan for the program in (*ercise &8.
Reason for Test Case Input Values Expected Output Observed Output
Assumption3 Input ,alues are no greater than $
#8
.# or less than A $
#8
.
Input three positi,e numbers &, 7, # .# .#
Input three negati,e numbers .&, .7, .# # #
Input mi*ed numbers &, 7, .#
&, .7, #
&, .7, .#
.&, 7, #
.&, 7, .#
.&, .7, #
.%
##
.B
.B
.##
%
.%
##
.B
.B
.##
.%
-arge numbers %$=7=, .#, C# o,erflows o,erflows
%$=7=, #, .# %$=7=
47. 'esign and implement in assembly language an algorithm that reads four ,alues and prints the sum.
Set count to 0
Set sum to 0
WHILE count < 4
Read num
Add num to sum
Set count to count + 1
Write sum
BR Read ;branch to location Read
sum: .WORD 0x0000 ;set word to zero
count: .WORD 0x0000 ;set up a two byte block for count limit:
.WORD 0x0004 ;set up a block for value 4
number:.BLOCK 2 ;set up word for value read
Read: LDA sum,d
DECI number,d
ADDA number,d
STA sum,d ;store accumulator in sum
LDA count,d ;load a copy of limit in accumulator
ADDA 1,i
STA count,d ;store contents in count
CPA limit,d ;compare accumulator to 0
BREQ Quit ;branch to Quit if count is 4
BR Read ;go back to read in another number
Quit: DECO sum,d
STOP
.END
48.
Is the test plan for a machine language program ,alid for the same solution written in assembly
language+ (*plain your answer.
A data.co,erage plan is written without loo1ing at the code, so the same test plan would be ,alid.
A code.co,erage plan loo1s at the code, but because there is a one to one relationship between a
machine code instruction and an assembly language instruction, the same test plan would be ,alid.
49. 'istinguish between the pseudo.code instructions .B-;CD and .);R'.
The pseudo.code instruction .B-;CD ta1es a decimal argument and sets aside that many bytes of
storage and set them to ?ero. A .);R' pseudo.code instruction ta1es a decimal argument and
generates one word of storage with the decimal ,alue stored in it.
50. 'istinguish between assembly language pseudo.code instructions and mnemonic instructions.
Pseudo.code instructions are instructions to the assembler6 mnemonic instructions are to be
translated by the assembler.
51. 'istinguish between test plans based on code co,erage and data co,erage.
A code.co,erage test plan is based on e*amining and co,ering the statements in the code. A data.
co,erage test plan is based on the input data to the program.
52.
)hat button on the Pep! console must be pushed for 1eyboard input+
Terminal I;
53. )rite the Pep! assembly language statement for the following instructions.
a. Branch to location Branch1 if the accumulator is ?ero.
BREQ Branch1
b. Branch to location Branch1 if the accumulator is negati,e.
BRLT Branch1
c. Branch to location Branch1 if the accumulator is negati,e and to Branch2 if accumulator is
not negati,e.
BRLT Branch1
Branch2:
That is, go to location Branch1 if the accumulator is negati,e. If the accumulator is not negati,e,
the ne*t instruction is e*ecuted, so it must be labeled Branch2.
54. )rite a pseudocode algorithm to read in a name and write a E<ood morningF message.
Write "Enter a ame"
Read name
Write "!ood mornin""# name
55.
)rite a pseudocode algorithm to get three integers from the user and print them in numeric order.
Write "Enter t$ree inte"er %a&ues"
Read 'irst# second# t$ird
I( )'irst < second*
I( )second < t$ird*
Write 'irst# second# t$ird
ELSE
I( )'irst < t$ird*
Write 'irst# t$ird# second
ELSE
Write t$ird# 'irst# second
ELSE
I( )'irst < t$ird*
Write second# 'irst# t$ird
ELSE
I( )second < t$ird*
Write second# t$ird# 'irst
ELSE
Write t$ird# second# 'irst
56.
(nclose the design in (*ercise 88 within a loop that reads in the three ,alues until the user enters
the first ,alue of the trio as negati,e.
Write "Enter t$ree %a&ues+ a ne"ati%e %a&ue sto,s t$e ,rocessin""
Read 'irst# second# t$ird
WHILE )'irst - 0*
.. /rocess t$e t$ree %a&ues
Write "Enter t$ree %a&ues+ a ne"ati%e %a&ue sto,s t$e ,rocessin""
Read 'irst# second# t$ird
Rewrite the algorithm in (*ercise 87 so that the user has to enter only one negati,e ,alue to stop
4that is, the second and third ,alues are not entered5.
Write "Enter t$ree %a&ues+ a ne"ati%e %a&ue sto,s t$e ,rocessin""
Read 'irst
WHILE )'irst - 0*
Read second# t$ird
.. /rocess t$e t$ree %a&ues
Write "Enter t$ree %a&ues+ a ne"ati%e %a&ue sto,s t$e ,rocessin""
Read 'irst
58.
'istinguish between pseudocode and pseudo.operations.
Pseudocode is a language for e*pressing algorithms. Pseudo.operations are instructions to a
translating system.
59. )hat are the constructs that pseudocode must be able to e*press+
Gariables, assignment, inputoutput, repetition, selection 4if.then, if.then.else5
60. 'istinguish between the looping construct and the selection construct.
A looping construct repeats an action 4s5 while a condition is true. A selection construct
determines if a condition is true and does one thing if it is and another thing if it is not.

Você também pode gostar