0% found this document useful (0 votes)
169 views7 pages

HW 3

This document contains instructions for HW 3 in COSC 3332 Computer Organization and Architecture. It includes 5 questions about memory addressing, instruction encoding, and writing simple programs in MARIE assembly language. The questions cover topics like calculating the number of bits needed to address memory, determining opcode and register field sizes, writing IF/THEN statements and for loops in assembly language.

Uploaded by

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

HW 3

This document contains instructions for HW 3 in COSC 3332 Computer Organization and Architecture. It includes 5 questions about memory addressing, instruction encoding, and writing simple programs in MARIE assembly language. The questions cover topics like calculating the number of bits needed to address memory, determining opcode and register field sizes, writing IF/THEN statements and for loops in assembly language.

Uploaded by

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

COSC 3332 Computer Organization and Architecture Dr.

Zhu

HW 3
Due Date: 3/6/2022 11:59pm

1. How many bits are required to address a 4Mx16 main memory if


a. Main memory is byte addressable?
Byte addressable: 4M x 16 = 2^2(4) x 2^20(1m) x 2^1 (2 bytes, or 16 bits) =
2^23, or 23 bits
b. Main memory is word addressable?
Word addressable: 4M x 16 = 2^2(4) x 2^20(1m) x 2^0 (1 word, or 16 bits) =
2^22, or 22 bits

2. A digital computer has a memory unit with 32 bits per word. The instruction set
consists of 110 different operations. All instructions have an operation code part
(opcode) and two address fields: one for a memory address and one for a register
address. This particular system includes eight general-purpose, user-addressable
registers. Registers may be loaded directly from memory, and memory may be
updated directly from the registers. Direct memory-to-memory data movement
operations are not supported. Each instruction stored in one word of memory.

a. How many bits are needed for the opcode?


2^7 = 128 > 110
Hence the no of bits needed will be 7.

b. How many bits are needed to specify the register?


No of registers =8
2^3 = 8
Hence the no of bits needed will be 3.

c. How many bits are left for the memory address part of the instruction?
32 - 7 - 3 = 22
22 bits will be available for the memory address part of the instruction.

d. What is the maximum allowable size for memory?


2^22 x 4 bytes per word = 2^24 bytes
2^24 bytes = 16 MB

e. What is the largest unsigned binary number that can be accommodated in one
word of memory?
Word Length = 32 bits
Largest Unsigned Binary Number = 2^32 - 1

3. Consider the MARIE program below.

a. List the hexadecimal code for each instruction.


COSC 3332 Computer Organization and Architecture Dr. Zhu

b. Draw the symbol table.

c. What is the value stored in the AC when the program terminates?

Hex Address Label Instruction


100 Start, LOAD A
101 ADD B
102 STORE D
103 CLEAR
104 OUTPUT
105 ADDI D
106 STORE B
107 HALT
108 A, HEX 00FC
109 B, DEC 14
10A C, HEX 0108
10B D, HEX 0000

Answer:

a. The hexadecimal code for


each instruction are as
follows:
Hex Address Label
Instruction Hexadecimal
Code
100 Start
LOAD A 1108
COSC 3332 Computer Organization and Architecture Dr. Zhu

101 ADD
B 3109
102
STORE D 210B
103
CLEAR A000
104
OUTPUT 6000
105
ADDI D B10B
106
STORE B 2109
107
HALT 7000
COSC 3332 Computer Organization and Architecture Dr. Zhu

108 A, HEX
00FC 00FC
109 B, DEC
14 000E
10A C,
HEX 0108 0108
10B D,
HEX 0000 0000
b. The symbol table is as
follows:
Symbol Location
A 108
B 109
C 10A
D 10B
COSC 3332 Computer Organization and Architecture Dr. Zhu

c. The value stored in the AC


when the program terminates
is HEX 0108
a. The hexadecimal code for each instruction are as follows:

Hex Address Label Instruction Hexadecimal Code

100 Start LOAD A 1108


101 ADD B 3109
102 STORE D 210B
103 CLEAR A000
104 OUTPUT 6000
105 ADDI D B10B
106 STORE B 2109
107 HALT 7000
108 A HEX 00FC 00FC
109 B DEC 14 000E
10A C HEX 0108 0108
10B D HEX 0000 0000
b. The symbol table is as follows:
Symbol Location
A 108
B 109
C 10A
D 10B
START 100

c. The value stored in the AC when the program terminates is HEX 0108

4. Write the following code segment in MARIE’s assembly language:

If X>1 then
Y = X+X;
X=0;
Endif;

Y=Y+1;
COSC 3332 Computer Organization and Architecture Dr. Zhu

Answer:
ORG 100

If,
Load X /Load X
Subt One /Subtract 1, & store result in AC
Skipcond 800 /it AC>0 (X>1), skip the next instruction
Jump ENDIF /Jump to Endif if X is not greater than 1

Then,
Load X /Reload X so it can be doubled
Add X /Double X
Store Y /Y=X+X
Clear /Move 0 into AC
Store X /Set X to 0

Endif,
Load Y /Load Y into AC
Add One /Add 1 to Y
Store Y /Y=Y+1
Halt /Terminate program

X, Dec ? /X has starting value, not given in problem


Y, Dec ? /Y has starting value, not given in problem
One, Dec 1 /Use as a constant

5. Write the following code segment in MARIE’s assembly language (Hint: Turn the
for loop into a while loop):

Sum = 0;
for X=1 to 10 do
Sum = Sum +X;

Answer:
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
COSC 3332 Computer Organization and Architecture Dr. Zhu

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 X

You might also like