Unit # 3
Exercises
1. Consider the following program. What numbers are in
$C100 and $C101 at the end? Verify your answer using the
THRSim11 Simulator.
LDD #$F00D
LDX #$C100
STD 0,X
BSET 0,X $44
BCLR 1,X #$11 ; the # is optional here
2. Consider the following instruction sequences. Determine the
label values and all allocated memory locations and their
contents. Note: EQU does not reserve any memory bytes.
a. ORG $00
VAR FCB $12,$00,A1
b. ORG $C000
MAR EQU $1234
RUN FCC “Ab2?”
c. ORG $F1
RMB 3
LOOP FDB $18,$125B
3. Consider the following assembly program. What are the
values of the labels “count”, “list” and “moon” after
assembling the program? Find the contents of ACCA, ACCB
the X register, and locations $C003 through $C007 after
executing the program. Verify your answer using the
THRSim11 Simulator.
moon EQU $FF
ORG $C003
count RMB 2
list FCB $12,$C0,$04
LDAA #moon
LDX #(list+1)
LDAB 1,X
SWI
END
4. Find the values of all labels in Programming Example 3 (Unit
3). Also, determine the hex code for the operands of all three
branch instructions.
5. Write a flowchart for a program that multiplies the number
NUM times 4 by adding it to itself three times. Write the
corresponding assembly program. Use the label NUM, and
assign it to memory location $00B0. Start the program at
$0010. The result is to be saved at $00B1.
6. What does the following program accomplish? Verify it on
the THRSim11 simulator or the M6800 simulator. Note: the
M6800 simulator does not allow for labels. So, they need to
be dropped; the operand of the branch instruction should be
replaced by the appropriate hex (or signed decimal) value.
START LDX #$60
ZAP CLR $9F,X
DEX
BNE ZAP
WAI
END
7. Verify the look-up table of squares program (listed below)
using the THRSim11 Simulator. Note that the simulator
allows the user to change the content of registers and
memory while a program is running on the simulator.
* Program to compute the square of a number 0-15
* Input is assumed to be placed at $0001
* Output goes to ACCA
ORG $C000
LDAB #$00
STAB $0000
loop LDX $0000
LDAA $96,X
BRA loop
ORG $96
FCB $00,$01,$04,$09,$10,$19,$24,$31,$40
FCB $51,$64,$79,$90,$A9,$C4,$E1
END
8. Calculate the number of E cycles and the time it takes to
execute the following program segment on a 68HC11
running at 0.5 μs E cycle. Assume [$D012] = $0A.
LDAA $D012
count DECA
CMPA #$00
BNE count
9. Compare the precision of the following 10s delay program to
the one in Huang’s text, p. 82 (correction: first instruction
should read LDAB in Huang’s program).
LDAB #60
outer_loop LDX #55554
inner_loop DEX
BNE inner_loop
DECB
BNE outer_loop
END
10. Write a program that converts an 8-bit binary number in
the range $00 through $63 (i.e., 0 – 99 decimal) stored at
$0000 to BCD. Store the result at $0001. Hint: save all 2-
digit BCD codes representing the numbers 0 through 99 in a
list in memory and employ indexed addressing to point and
pick the proper BCD code for the input hexadecimal number
stored at $0000.
11. Write a program to set bit seven (MSB) of a byte at
location $0000 so that it contains odd parity. That is, the
number of bits that are 1 in [$0000] must become odd at the
end of the program (e.g., $0F becomes $8F, $01 does not
change, etc.) Assume that the original number at $0000 is a
positive number less than $80.
12. Modify Programming Example 2 (Unit 3) so that it works
for signed numbers. Verify it on the THRSim11 Simulator.
13. The following program computes the square root (or a
good approximation of the square root) of a number stored at
$0000. The result is saved at $0001. Analyze this program
and generate a flowchart and the algorithm used to find the
square root. Demonstrate this algorithm (by hand) on the
number 25 (decimal). Test the program on one of the
simulators.
ORG $C000
LDAA $00
LDAB #$01
again SBA
BCS finished
INCB
INCB
BRA again
finished LSRB
STAB $01
WAI
END