Chapter 2


1. Run the sample code below and measure the pulse width and period of the signal on PTB3 output pin (pin-9). Confirm that the execution times are correct for a clock frequency of 16 MHz (4MHz BUSCLK).

#include <MC9S08QG8.h>
void main()
lda #$52
sta SOPT1 ; disable COP watchdog
mov #$08,PTBDD ; set portB bit-3 to output
mov #$08,PTBD ; pulse portB bit-3
mov #$00,PTBD
bra loop


Answer the following questions:

(a) What is the difference between machine code, assembler and C? Give examples.

(b) What is the purpose of the first #include statement in the program shown above? Give examples.

(c) What is the Computer Operating Properly (COP) watchdog? What is it used for and how does one use it?

(d) Why is the instruction to set SOPT1 different from that to set PTBDD?

(e) How many machine cycles does it take to execute the program loop? What is the period? What is the internal clock frequency?


2. Modulo Timer

Write and test an assembly language program to test the operation of the modulo timer. The timer is started by writing $00 to register MTIMSC and the 8-bit timer value can be read from register MTIMCNT. Using the internal BUSCLK, alter the prescaler factor by writing to MTIMCLK. Verify all periods and frequencies observed.

Write a subroutine in assembler code which will delay program execution by any amount around 1 to 1000 ms


3. 16 x 16 Multiply

The MUL instruction forms the product of accumulators A and X with the 16-bit unsigned result in X:A. Take advantage of the MUL instruction to form the product of two 16-bit unsigned integers, giving a 32-bit result. Write your program in assembler code and use the debugger to verify your results.