EER-018
Introduction to Digital Computers
Assignment #9
1.
|
|
org |
$3FF ;initialize one data value in memory |
|
data_v: |
fcb |
$67 |
|
|
org |
$300 ;put program in memory at $300 |
|
start: |
LDX |
#$C0 |
|
|
LDA |
$3FF |
|
|
STA |
,X |
|
|
LSRA |
|
|
|
INCX |
|
|
|
STA |
,X |
|
|
INCX |
|
|
|
INCA |
|
|
|
STA |
,X |
|
|
STOP |
|
|
|
ORG |
$7FE |
|
|
FDB |
START ; to set the reset address |
Modify the program above so that it accomplishes the same thing, but uses only 8 instructions. (Two instructions can be eliminated. ) Hint: considering using the indexed, 8-bit offset address mode.
2. Write a program that counts the number of zeros in memory location $C0 and stores the result in location $C1.
Example input and output in memory:
$C0 $0C
0000 1100 <-- 6 zeros, 2 ones
$C1 $06
|
instruction: |
COMA |
ROLA |
LSLA |
NEGA |
|
accumulator: |
|
|
|
|
|
CCR flags: |
|
|
|
|
3. The following instructions
occur in a sequence, one after the other. What are the final values of the
A and X register?
|
LDA #$57 |
|
ORA #$82 |
|
DECA |
|
CLRA |
|
TAX |
4. Assume that there are 2 data
values in memory starting at location $C2. Write a program to move the 2
values to the memory locations starting at location $DF.
6. Analyze the program shown
below by filling in the worksheet that follows for each instruction that is
fetched and executed.
|
Address |
Label |
Instruction |
Operand |
Comment |
|
$0200 |
START: |
LDA |
#$FF |
; Load A immediate |
|
$0202 |
|
INCA |
|
; Increment A |
|
$0203 |
|
LDX |
#$D0 |
; Load X immediate |
|
$0205 |
|
ADC |
#2 |
; Add 2 to A with carry |
|
$0207 |
|
STA |
,X |
; Store A in memory using indexed mode |
|
$0208 |
|
STX |
1,X |
; Store X in memory using indexed mode |
|
Accumulator (A) |
Cond. Codes |
Index Register (X) |
Program Counter (PC) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Memory |
Memory |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7. Hand assemble the following short program and
give the resulting addresses and machine code.
|
|
org |
$300 ; put program in memory starting at location $300 |
|
start: |
LDA |
#$50 |
|
loop: |
DECA |
|
|
|
BNE |
loop |
|
|
STOP |
|
8. Give the final values of the A and X
registers and the memory locations shown when the program below terminates.
|
|
org |
$3FF ;initialize one data value in memory |
|
|
data_v: |
fcb |
4 |
|
|
|
org |
$300 ;put program in memory at $300 |
Memory |
|
start: |
LDX |
#$C0 |
address: contents |
|
LDA |
data_v |
$C0 |
|
|
again: |
STA |
,X |
$C1 |
|
|
DECA |
|
$C2 |
|
|
BEQ |
done |
$C3 |
|
|
INCX |
$C4 |
|
|
|
BRA |
again |
|
|
done |
STOP |
|
|
|
|
ORG |
$7FE |
|
|
|
FDB |
START ; to set the reset address |
|
9. Write a program that checks memory locations $C0, $C1, $C2 and $C3 and clears the memory location if the data is an even number. If the number is odd, it is left untouched.
For example:
Before:
$C0 $0C
even
$C1 $07 odd
$C2 $F3 odd
$C3 $80 even
After:
$C0 $00
$C1 $07
$C2 $F3
$C3 $00