Docsity

Solutions to EECS 388 Homework 2: Memory Operations and Instruction Execution, Assignments of Electrical and Electronics Engineering

Toggle sidebar
bg1
EECS 388: Computer Systems and Assembly Language
Homework 2 - Solution
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. What is in accumulator A and the N, Z, C, V
bits in CCR after an LDD #$4001 instruction is executed?
Accumulator A _____$40____ N __0__ Z ___0__ C __??(unchanged)_ V __0__
LDD #$4001
This instruction will load register D (A:B) with the immediate value of $4001
D = (A:B) = $4001, therefore…
A = $40
B = $01
According to pg. 450 of the textbook the LDD instruction has an effect on the N and Z
bits, it will zero out the V bit, and it has no effect on the C bit.
The N-bit is set when a number is negative in 2’s complement representation. This
means that this bit will be set if the most significant bit of D is set. The most significant
nybble (4-bits) of D is 4, or 0100 in binary, so the most significant bit is 0, and thus the
N-bit is also zero.
The Z-bit is set when the result of an operation is zero. In this case, Z will be zero due
to the fact that the number being loaded into register D is not a zero.
pf3
pf4
pf5

Partial preview of the text

Download Solutions to EECS 388 Homework 2: Memory Operations and Instruction Execution and more Assignments Electrical and Electronics Engineering in PDF only on Docsity!

EECS 388: Computer Systems and Assembly Language

Homework 2 - Solution

Justify your answers!

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

Contents Locations

_____________________________________

$B5 $

$CD $

Figure 1.

Problem 1 (10 Points):

Consider the memory shown in Figure 1. What is in accumulator A and the N, Z, C, V

bits in CCR after an LDD #$4001 instruction is executed?

Accumulator A _____$40____ N __ 0 __ Z ___ 0 __ C _??(unchanged) V __ 0 __

LDD #$4001 

This instruction will load register D (A:B) with the immediate value of $

D = (A:B) = $4001, therefore…

A = $

B = $

According to pg. 450 of the textbook the LDD instruction has an effect on the N and Z

bits, it will zero out the V bit, and it has no effect on the C bit.

The N-bit is set when a number is negative in 2’s complement representation. This

means that this bit will be set if the most significant bit of D is set. The most significant

nybble (4-bits) of D is 4, or 0100 in binary, so the most significant bit is 0, and thus the

N-bit is also zero.

The Z-bit is set when the result of an operation is zero. In this case, Z will be zero due

to the fact that the number being loaded into register D is not a zero.

Write a program segment to reverse the bit order of a 6-bit number. Assume this number is stored in $6000. Store the reversed number to $6001 (i.e., if the original number is 0 0 b 5 b 4 b 3 b 2 b 1 b 0 , after this program, the number in $6001 will be 0 0 b 0 b 1 b 2 b 3 b 4 b 5 ). Reversing a number can be easily accomplished by rotating the number 1-bit at a time, until the desired rotation is accomplished. First, start the process by rotating the LSB out of the original number and into the carry register. Then rotate this number into the LSB of another register, and repeat this process. Each subsequent rotation will “push” the last rotation forward until all bits are in their correct places. This can be accomplished with a series of shifts, or with a loop. ORG $4000 ; Set program start address LDAA $6000 ; Load original number in register A LDAB #$00 ; Initialize register B LSRA ; Shift LSB out of original number and into carry register ROLB ; Rotate bit in carry register into LSB of register B ; Now register B = 0000000b 0 LSRA ; Shift LSB out of original number and into carry register ROLB ; Rotate bit in carry register into LSB of register B ; Now register B = 000000b 0 b 1 LSRA ; Shift LSB out of original number and into carry register ROLB ; Rotate bit in carry register into LSB of register B ; Now register B = 00000b 0 b 1 b 2 LSRA ; Shift LSB out of original number and into carry register ROLB ; Rotate bit in carry register into LSB of register B ; Now register B = 0000b 0 b 1 b 2 b 3 LSRA ; Shift LSB out of original number and into carry register ROLB ; Rotate bit in carry register into LSB of register B ; Now register B = 000b 0 b 1 b 2 b 3 b 4 LSRA ; Shift LSB out of original number and into carry register ROLB ; Rotate bit in carry register into LSB of register B ; Now register B = 00b 0 b 1 b 2 b 3 b 4 b 5 STAB $6001 ; Store the results and stop the program SWI

that a bit can be negated by using an exclusiveOR with the binary value ‘1’. Therefore a full 8-bit negation can be accomplished by exclusiveOR with $FF. Not (X) = ExclusiveOR(X,$FF) NEGATE_MASK EQU $FF ; Create an equate for the negation mask BASE1 EQU $5000 ; Base of 1st number BASE2 EQU $5010 ; Base of 2nd number NEGATED_BASE EQU $5020 ; Base of negated version of 2nd number RESULT_BASE EQU $6000 ; Base of result ORG $4000 ; Set program start address ; Convert the second number to negative in 2’s complement ; First Negate the 2nd number 1 byte at a time LDAA BASE2+0 ; Read in byte EORA #NEGATE_MASK+0 ; Negate it STAA NEGATED_BASE+0 ; Store the result LDAA BASE2+1 ; Do this for the remaining 2 bytes EORA #NEGATE_MASK STAA NEGATED_BASE+ LDAA BASE2+ EORA #NEGATE_MASK STAA NEGATED_BASE+ ; Now perform 2's complement addition ; NUM1 - NUM2 = NUM1 + (Negated NUM2) + 1 ; Pre-load the carry bit with 1 LDAA #$01 ; Load a 1 into A, and shift the 1 into the carry reg LSRA ; Now begin the addition starting with the least-signficant byte LDAA BASE1+2 ; Load in byte of NUM ADCA NEGATED_BASE+2 ; Add negated byte with carry STAA RESULT_BASE+2 ; Use carry (with carry pre-set to 1) LDAA BASE1+1 ; Continue for remaining bytes ADCA NEGATED_BASE+ STAA RESULT_BASE+1 ; Use carry again LDAA BASE1+ ADCA NEGATED_BASE+ STAA RESULT_BASE+0 ; Use carry again SWI ; Stop the program

If A contains $56, what is the result of each of the following instructions? Assume that A is restored to its original value before each instruction. a) ANDA #$ A = $56 = 0101_ Mask = $33 = 0011_ Result(AND) = 0001_0010 = $ A = $ b) ORAA #$ A = $56 = 0101_ Mask = $33 = 0011_ Result(OR) = 0111_0111 = $ A = $ c) EORA #$ A = $56 = 0101_ Mask = $33 = 0011_ Result(EOR) = 0110_0101 = $ A = $ d) BITA #$ The BITA operation performs arithmetic, but does not alter the contents of register A. However, it does alter the contents of the CC register. Typically this instruction will be used for the sake of comparison before a branch instruction, so that CCR bits can be purposefully set w/o having to alter any of the values in registers.