You are on page 1of 7

# CHAPTER 4 EXERCISES

12.
MARIE can handle 16-bit data, so the AC must be 16 bits wide. However, MARIE's
Memory is limited to 4096 address locations, so the MAR only needs to be 12 bits wide to
Hold the largest address.

13.

1108

3109

9106

3109

2108

7000

3108

9103

0023

14.
A 108
One 109
S1 106
S2 103

15.
a. i) Store 007
ii) Jump 00B
iii) Add 009

b.
If, 100 Load X /Load X
101 Sub One /Subtract 1, store result in AC
102 Skip Cond 800 /If AC>0 (X>1), skip the next instruction
103 Jump End if /Jump to End if if X is not greater than 1
Then, 104 Load X /Reload X so it can be doubled
105 Add X /Double X
106 Store Y /Y:= X + X
107 Clear /Move 0 into AC17.
108 Store X /Set X to 0
Endif,109 Load Y /Load Y into AC
10A Add One /Add 1 to Y
10B Store Y /Y: = Y + 1
10C Halt /Terminate program
X, 10D Dec? /X has starting value, not given in problem
Y, 10E Dec ? /Y has starting value, not given in problem
One, 110 Dec 1 /Use as a constant
16. ORG 100
Load A
Store X /Store A in first parameter
Load B
Store Y /Store B in second parameter
JnS Mul /Jump to multiplication subroutine
Load Sum /Get result
Store E /E:= A x B
Load C
Store X /Store C in first parameter
Load D
Store Y /Store D in second parameter
JnS Mul /Jump to multiplication subroutine
Load Sum /Get result
Store F /F := C x D
Load E /Get first result
Add F /AC now contains sum of A X B + C X D
Halt /Terminate program
A, Dec ? /Initial values of A,B,C,D not given in problem
B, Dec ? / (give values before assembling and running)
C, Dec ? /
D, Dec ? /
X, Dec 0 /First parameter
Y, Dec 0 /Second parameter
Ctr, Dec 0 /Counter for looping
One, Dec 1 /Constant with value 1
E, Dec 0 /Temp storage
F, Dec 0 /Temp storage
Sum, Dec 0
Mul, Hex 0 /Store return address here
Load Y /Load second parameter to be used as counter
Store Ctr /Store as counter
Clear /Clear sum
Store Sum /Zero out the sum to begin
Loop, Load Sum /Load the sum
Add X /Add first parameter
Store Sum /Store result in Sum
Load Ctr
Subt One /Decrement counter
Store Ctr /Store counter
SkipCond 400 /If counter = 0 finish subroutine
Jump Loop /Continue subroutine loop
JumpI Mul /Done with subroutine, return to main
END

17.
Load One
Store X /Initialize X
Loop, Load X /Load loop constant
Subt Ten /Compare X to 10
SkipCond 000 /If AC<0 (X is less than 10), continue loop
Jump Endloop /If X is not less than 10, terminate loop
Load X /Begin body of loop
Add One /Add 1 to X
Store X /Store new value in X
Jump Loop /Continue loop
Endloop, Halt /Terminate program
X, Dec 0 /Storage for X
One, Dec 1 /The constant value 1
Ten, Dec 10 /The loop constant

18.

ORG 100
Load One /Load constant
Store X /Initialize loop control variable X
Loop, Load X /Load X
Subt Ten /Compare X to 10
SkipCond 000 /If AC<0 (X is less than 10), continue loop
Jump Endloop /If X is not less than 10, terminate loop
Load Sum
Add X /Add X to Sum
Store Sum /Store result in Sum
Load X
Add One /Increment X
Store X
Jump Loop
Endloop, Load Sum
Output /Print Sum

## Halt /terminate program

Sum, Dec 0
X, Dec 0 /Storage for X
One, Dec 1 /The constant value 1
Ten, Dec 10 /The loop constant
END

19.

ORG 100
Load Y /Load second value to be used as counter
Store Ctr /Store as counter
Loop, Load Sum /Load the sum
Add X /Add X to Sum
Store Sum /Store result in Sum
Load Ctr
Subt One /Decrement counter
Store Ctr /Store counter
SkipCond 400 /If AC=0 (Ctr = 0), discontinue looping
Jump Loop /If AC not 0, continue looping
Endloop, Load Sum
Output /Print product
Halt /Sum contains the product of X and Y
Ctr, Dec 0
X, Dec ? /Initial value of X (could also be input)
Y, Dec ? /Initial value of Y (could also be input)
Sum, Dec 0 /Initial value of Sum
One, Dec 1 /The constant value 1
END
CHAPTER 5 Exercises

1. S
2.
3.
4.
5. S
6. s

EXCERCISES PART 2

1.

a and b.

Address 00 01 10 11

Big Endian 00 00 12 34
Little Endian 34 12 00 00

c. Little endian is more efficient because the additional information simply needs to be
appended. With big endian, the "12" and "34" would need to shift to maintain the
correct byte ordering.
3.

## b. 01FE16 = 0000 0001 1111 11102 = 51010

7.

There are 250 2-address instructions. There are only a total of 256 2-address instructions
allowed if we have 32-bit instructions (two addresses take up 24 bits, leaving only 8 bits for
the opcode). Looking at the 8 bit opcode, assume bit patterns 00000000 (0) through
11111001 (249) are used for the 250 two-address instructions. Then there are 6 bit
patterns left for one address instructions. However, each one of these can use the
remaining 12 bits gained from having only one operand, so we have 6 * 212.

8.
a. X Y * W Z * V U * + +

b. W X * W U V * Z + * +

c. W X Y U V * * + * U X Y + * /

9.

a. W * (X + Y - Z)
b. U + (V * (W + (X * (Y + Z))))
c. X + ((Y + Z) * (V - W) + Z)

10.

a. A B - C D E * F - * + G H K * + /

Push A
Push B
Subtract
Push C
Push D
Push E
Mult
Push F
Subtract
Mult
Add
Push G
Push H
Push K
Mult
Add
Div
Pop X

11.

## a. Yes. The 2-address instructions could be represented 000xxxxxxxx through

100xxxxxxxx (using 000 through 100 for opcodes). The 1-address instructions could
use 1010000 through 1011111 (16), 1100000 through 1101111 (16), and 1110000
through 1111100 (13 more, for a total of 45). The 0-address instructions could use
11111100000 through 11111101111 (16), and 11111110000 through 11111111111
(16). So we have:
b. Assume the two-address instructions use bit patterns 000 xxxx xxxx through 101 xxxx
xxxx. Assume also that the zero-address instructions are of the format 11111101000
through 11111101111 (8), 11111110000 through 11111110111 (8), and 11111111000
through 11111111111 (8) (These constitute the last 16 binary numbers possible with
11 bits). Then all instructions beginning with 110 (1100000 xxxx through 1101111
xxxx) could be one address instructions (16). In addition, 1110000 xxxx through
1111101 xxxx could be one address instructions, giving us 14 more, for a total of 30 1-
address instructions.

12.

Direct addressing provides the actual memory address of the operand in the instruction,
whereas indirect addressing provides, as part of the instruction, a pointer to a memory
location. For example, the instruction Load X interpreted using direct addressing would go
to memory location X and load the value found there. Using indirect addressing, memory
location X would be used as the effective address of what should actually be loaded. So if a
value of 200 were found at location X, the value located at address 200 would be loaded.

13.

Mode Value
Immediate 1000
Direct 1400
Indirect 1300
Indexed 1000

14.

Mode Value
Immediate 500
Direct 100
Indirect 600
Indexed 800

15.

Max SpeedUp = 5

19.

## a. We need to identify 1 of 7 items, so there must be 3 bits (23 = 8)

b. 60 registers imply 6 bits (26 = 64)
c. 256K = 28210 = 218, or 18 bits
d. 32 - (3 + 6 + 18) = 5 bits