Programs

8
SAMPLE PROGRAMS

description

The_Quintessential_PIC_Microcontroller_2000

Transcript of Programs

Page 1: Programs

SAMPLE PROGRAMS

Page 2: Programs

EXAMPLE 1

Code a program to decrement a 2-byte number at File 26:27h ordered as high:low byte, remembering that decf does not alter the Carry/Borrow flag.

Page 3: Programs

SOLUTION TO EXAMPLE 1

The task list to implement this job is:

1. IF the least significant byte in File 27h is zero THEN decrement the most significant byte.

2. Always decrement the least significant byte.

Page 4: Programs

EXAMPLE 2

Some early computers used a bi-quinary code to represent BCD digits. This is a 7-bit code with only two bits set to one for any combination:

Page 5: Programs

EXAMPLE 2

Bi-quinary coded decimal is a numeral encoding scheme used in many abacuses and in some early computers, including the Colossus. The term bi-quinary indicates that the code comprises both a two-state (bi) and a five-state (quinary) component. The encoding resembles that used by many abaci, with four beads indicating either 0 through 4 or 5 through 9 and another bead indicating which of those ranges.

Page 6: Programs

EXAMPLE 2

Page 7: Programs

SOLUTION TO EXAMPLE 2

All we need to do here is to determine when there are more or less than two bits set to one. Based on this approach we have the tasklist:

1. Count the number of ones in the bi-quinary byte.

2. Zero W.

3. IF count is not two THEN make FFh to signal an error.

Page 8: Programs

SOLUTION 3