Docsity

ECS 50 Homework 3 Solutions (Spring 2008), Assignments of Computer Science

Toggle sidebar
bg1
ECS 50, Computer Organization and Machine-Dependent Programming Spring Quarter 2008
Homework 3 Solutions
Due Date: May 6, 2008 Total Points: 100
Problems
1. Text, 3-1
Solution: See text.
2. Text, 3-2
Solution: See text.
3. Text, 3-3
Solution:
(a) LDA $002
ACC = code for ADA# $002 = $100 002
STA $004
Mem[$004] = $100 002
ADA# $002
ACC = ACC + $000 002 = $100 002 + $000 002 = $100 004
Since ACC is a positive number (left most bit is 0), it is not less than zero, and therefore LT = 0. PC =
address of last executed instruction plus 1 = $004.
(b) LDA# $003
ACC = $000 003
ADA $004
ACC = ACC + Mem[$004] = $000 003 + $7FF FFF = $800 002
OV = 1 since addition of two identically signed numbers has produced an oppositely signed result. EQ = 0.
STA $004
Mem[$004] = $800 002
HLT Stopped.
(c) LDA# $005
ACC = $000 005
CMA $007
Mem[$007] = $F0345E (a negative number)
Version of May 5, 2008 Page 1 of 3
pf3

Partial preview of the text

Download ECS 50 Homework 3 Solutions (Spring 2008) and more Assignments Computer Science in PDF only on Docsity!

Homework 3 Solutions

Due Date: May 6, 2008 Total Points: 100

Problems

  1. Text, 3-

Solution: See text.

  1. Text, 3-

Solution: See text.

  1. Text, 3-

Solution:

(a) LDA $ ACC = code for ADA# $002 = $100 002

STA $ Mem[$004] = $100 002

ADA# $ ACC = ACC + $000 002 = $100 002 + $000 002 = $100 004

Since ACC is a positive number (left most bit is 0), it is not less than zero, and therefore LT = 0. PC = address of last executed instruction plus 1 = $004.

(b) LDA# $ ACC = $000 003

ADA $ ACC = ACC + Mem[$004] = $000 003 + $7FF FFF = $800 002

OV = 1 since addition of two identically signed numbers has produced an oppositely signed result. EQ = 0.

STA $ Mem[$004] = $800 002

HLT Stopped.

(c) LDA# $ ACC = $000 005

CMA $ Mem[$007] = $F0345E (a negative number)

So ACC > Mem[$007], → EQ = 0 and LT = 0.

JLT $ This instruction not executed because LT is not 1.

SBA# $0A ACC = ACC - $000 0A3 = $FFF F LT = 1 because ACC is negative.

JMP $ Unconditional jump to the HLT instruction at $006.

PC = address of last executed instruction plus 1 = $007.

(d) LDA $ This sets the ACC to the code for ”LDA $000”. This code is $002 000. So ACC = $002 000

ADA $ ACC = ACC + Mem[$000 005] = $002 002

STA $ Mem[$003] = $002 002

ADA# $05C Actually this instruction has been overwritten by the previous instruction which wrote $002 002 in place of this instruction. So the instruction here is ”LDA $002”. This causes ACC to be set to Mem[$002], which is the code for ”STA $003”. That is, ACC = $042 003

  1. Text, 3-

Solution:

(a) LDA# $ ACC = $000 003

STA $ Mem[$006] = $000 003

ADA $ ACC = ACC + code for HLT = $000 003 + $FFF FFF = $000 002

OV = 0 because there can be no overflow when a positive number and a negative number are added.

(b) LDA# $ ACC = $000 123

STA $ Mem[$007] = $000 123