Homework 1 | Computer Systems and Assembly Language | EECS 388, Assignments of Electrical and Electronics Engineering

Material Type: Assignment; Class: Computer Systems&Assembly Lang; Subject: Elect Engr & Computer Science; University: University of Kansas; Term: Spring 2007;

Typology: Assignments

Pre 2010

Uploaded on 03/19/2009

koofers-user-2rp
koofers-user-2rp 🇺🇸

9 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
EECS 388: Computer Systems and Assembly Language
Homework 1
Due Feb. 12, 2007
Justify your answers!
Figure 1 shows a part of the memory (both contents and locations).
Contents Locations
_____________________________________
$20 $4000
$50 $4001
$01 $4002
: :
: :
$B5 $5000
$CD $5001
Figure 1.
Problem 1 (10 Points):
Consider the memory shown in Figure 1. Write a program to add the two
numbers in $4000 and $4001 and store the results in $5002.
Here, we simply need to add two 8-bit numbers and store the 8-bit result, so we can use
accumulator A for this task:
ORG $4100
LDAA $4000
ADDA $4001
STAA $5002
SWI
Problem 2 (10 Points):
Consider the memory shown in Figure 1. What is the content in accumulator D
after the following lines are executed?
LDD $4001
ADDA $5000
First we load D with the 16-bit value starting at location $4001. At this point, we have
D: $5001
Next we add the 8-bit value at location $5000 to the value contained in A (which is the
most significant byte of D, $50):
A: $50 + $B5 = $05 (The real result is $105)
pf3
pf4
pf5

Partial preview of the text

Download Homework 1 | Computer Systems and Assembly Language | EECS 388 and more Assignments Electrical and Electronics Engineering in PDF only on Docsity!

EECS 388: Computer Systems and Assembly Language

Homework 1

Due Feb. 12, 2007 Justify your answers!

Figure 1 shows a part of the memory (both contents and locations). Contents Locations


$20 $ $50 $ $01 $

$B5 $

$CD $

Figure 1.

Problem 1 (10 Points): Consider the memory shown in Figure 1. Write a program to add the two numbers in $4000 and $4001 and store the results in $5002.

Here, we simply need to add two 8-bit numbers and store the 8-bit result, so we can use accumulator A for this task:

ORG $ LDAA $ ADDA $ STAA $ SWI

Problem 2 (10 Points): Consider the memory shown in Figure 1. What is the content in accumulator D after the following lines are executed?

LDD $ ADDA $

First we load D with the 16-bit value starting at location $4001. At this point, we have

D: $

Next we add the 8-bit value at location $5000 to the value contained in A (which is the most significant byte of D, $50):

A: $50 + $B5 = $05 (The real result is $105)

The above result is too large to fit in A, so A will contain $05 and the overflow bit in the CCR will be set. Consequently, the upper byte of D (which is A) is now $05 but the lower byte has not changed at all, giving us:

D: $

Problem 3 (30 points): Consider the memory shown in Figure 1. What are the contents in memory location $5002 and accumulator A after the following lines are executed?

LDAA $ LDD #$ LDAB $ STD $

First, we load accumulator A with the 8-bit value at location $4000, which gives us:

A: $

Next, we load D with the immediate 16-bit value $5000, which now gives us:

D: $

But since D is really A and B, this means:

A: $ B: $

Next we load accumulator B with the 8-bit value at location $4002, which gives us:

B: $

So now we have:

A: $ B: $ D: $

Finally we store the 16-bit value in D to memory location, starting at location $5002, so now memory will look like:

Contents Locations


$20 $ $50 $

c) LSLD

Original(hex): $ B B C D Original(bin): 1011 1011 1100 1101 Shifted(bin): 0111 0111 1001 1010 Shifted(hex): $ 7 7 9 A

Final answer:

A: $77 B: $9A

d) ROLB

Remember that B is the lower byte of D, and that the carry bit is 1 before the rotate:

Original(hex): $ B B C D Original(bin): 1011 1011 1100 1101 Shifted(bin): 1011 1011 1001 1011 Shifted(hex): $ B B 9 B

The upper byte of D (which is A) is not affected by the rotate. Final answer:

D: $BB9B

Problem 4 (10 Points): Write a program to add two values $20 and $40 and store the result in memory location $8000.

We are asked to add to immediate 8-bit values and store the 8-bit result in memory.

ORG $ LDAA #$ ADDA #$ STAA $ SWI

Problem 5 (15 Points): Write a program to implement the following 16 bit rotation, i.e., originally, A and B contain a 7 a 6 …a 0 and b 7 b 6 …b 0 , respectively. After the 16 bit rotation, the contents in A and B are a 6 a 5 …a 0 b 7 and b 6 b 5 …b 0 a 7 , respectively. (Note: You can only use the data transfer and manipulation instructions in Section 2.4.1).

There are a lot of ways to do this problem; here are a few solutions (we only show the instructions for brevity):

Solution 1:

ASRA ROLA ROLB ROLA

Solution 2:

ASRB ROLB ROLA ROLB

Solution 3:

STAB $ LSLD LDAB $ ROLB

Solution 4:

STAA $ ROLA ROLB LDAA $ ROLA

Solution 5: