Dry run

No matter what ingenious programming software is available, there are times when the only practicable way to debug a program is to do a dry run. All you need are a pencil and paper.

In a dry run you set out a table of all the registers and variables that are involved. You then go through the listing line-by-line and work out the values that are in each register. Enter these in the table and confirm that they are the right values. As an example, here is a segment of the listing for part of the random spin routine of Project 6.4 (p. 295). This is explained on p. 163.

This routine produces a new pseudo-random value in randval every time it is run. Repeat the routine on paper several times to confirm that the values are really appearing at random.

Listing Contents of registers

bitn bitm

randval

w

c

clrf bitn 00000000 xxxxxxxx

11011011

xxxxxxxx

x

clrf bitm 00000000

btfsc randval, 5

(bit 5 = 0)

bsf bitn, 0 (skip)

btfsc randval, 6

(bit 6 = 1)

bsf bitm, 1 00000001

movf bitn w

00000000

xorwf, bitm, w

00000001

addlw '00FF'

00000000

1

rlf randval, f

10110111

c is the carry bit of the STATUS register.

x = don't care

A dry run is sometimes the only way to get the programming just right.

A dry run is sometimes the only way to get the programming just right.

Was this article helpful?

0 0

Post a comment