??? 11/12/06 15:07 Read: times |
#127815 - Hints for a smaller program Responding to: ???'s previous message |
Dan said:
... and keep in mind that I have only been working with 8051 for ~4 days so go easy. Maybe after a few more days check out the MOVC instructions. One variant makes it easy to look up values from a fixed table in code memory. Using this technique, you could collapse your gigantic 'display_bcd' routine into just a few lines. An example follows. You'd replace the TIMES_3_TABLE with a table containing the ten magic values you need to load into P1 for each of the ten decimal digits. You might also want to check out the JMP @A+DPTR instruction. In a similar fashion (using indirection through a table), it lets you jump to various points in your program based on the current contents of the accumulator. -- Russ ;------------------------------------------------------------------------------ ; MULTIPLY_BY_THREE ;------------------------------------------------------------------------------ ; DESCRIPTION: This routine multiplies the accumulator by three, using a table ; lookup technique. (This is intended only to demonstrate the ; table lookup technique; there are lots better ways to multiply ; by three!) ;------------------------------------------------------------------------------ TIMES_3_TABLE: DB 0, 3, 6, 9, 12, 15 MULTIPLY_BY_THREE: MOV DPTR,#TIMES_3_TABLE ; Point DPTR at lookup table MOVC A,@A+DPTR ; Grab the value indexed by A RET ; Done |