# Getting the homework done -- III

Tonight you get a chance to work on Homework 3.

## Homework 3

Begin by downloading a ZIP'ed MPLAB lab project that contains a driver program to test your code into the c:\files directory. This driver program will call your nextnum routine ten times and count the number of times nextnum returns the correct value.

The driver program is very long. Most of it was generated by an emacs macro and is not intended for human reading. All you really need to do is go to the end of the program and find the routine nextnum.

```nextnum  movlw   D'16'
movwf   H'22'
clrf    H'21'
clrf    H'20'
return
```

Replace these five lines with a correct solution for Homework 3. By the way, you may need to download, unzip, and install a copy of the MPLAB-IDE program.

Two breakpoints have been placed in this program. One is located at nextnum, the start of your code. Use this breakpoint to step through your code and debug it. The other breakpoint is located at chkpnt. When this breakpoint is reached: (1), registers A0 to A2 contain the 24-bit number last passed to the nextnum; (2), registers A4 to A6 contain the 24-bit number that should have been returned on the last call to nextnum; (3), registers A8 to AA contains the 24-bit number that really was returned by nextnum; (4), register AE is the number of times nextnum has been called; and (5), register AF is the number of times nextnum has returned the correct value. You want registers AE and AF to be the same.

Here's some examples of what you might see. Here are the registers before the first run of nextnum. Hexadecimal value 0x000055 is being passed in, and 0x000100 should be returned.

When the call completes, we see that nextnum correctly returned 0x000100. Notice that the counts of all calls (register AE) and successful calls (register AF) are equal.

Here is a list of the the values passed and returned by the ten calls:

 in decimal in hexadecimal input output input output 85 256 000055 000100 3355443 10066330 333333 99999A 11184810 5592405 AAAAAA 555555 5 16 000005 000010 32 16 000020 000010 100000 50000 0186A0 00C350 50001 150004 00C351 0249F4 255 766 0000FF 0002FE 65536 32768 010000 008000 1193046 596523 123456 091A2B