Double Dabble: Binary to BCD Conversion (ACES 3-Step Task)
Reference: https://en.wikipedia.org/wiki/Double_dabble
Worksheet: DoubleDabble.docx
Purpose: Binary data must be converted to ASCII if it is to be presented on your fan's LCD screen in assembly. The most efficient algorithm to achieve this is the Shift-Add-3 or Double Dabble algorithm that we'll (eventually) implement in AVR Assembly. This can be daunting, so let's break this down into 3 steps to make it accessible in the time we've got.
Step 1 (High-level Register code - Same 3 digit outputs).
From the layout to the right it is clear we've committed PORTD to monitoring the 8-bit binary input. For this reason we'll use the AVR Pocket programmer through the ISP header to avoid the Rx/Tx pins required by Serial programming.
- For the output we need three 4-bit nibbles; one each for the units, tens and hundreds digits (12 output pins). We'll commit PORTB (PB0-3) for the units, PORTB and PORTC (PB4-5 and PC0-1) for the tens and PORTC (PC2-PC5) for the hundreds. Note: Bits 6 and 7 are not avaliable for either PORT B or PORT C.
- To gain familiarity with the prototype your first task is develop purely register level code that will (efficiently) read the input and present the low nibble (PD0-3) on each of the three displays. If the nibble is not a valid BCD value (10-15) you know the CD4511 will simply blank the output.
Step 2 (High-level Register code - Double Dabble).
- Inefficient as it is in a high-level language, implement the Double Dabble algorithm using similar register level code as in Step 1 to correctly display the binary conversion of the 8-bit input to the BCD equivalent (research mutability and why Assembly language holds such an advantage).
- TIP: For an 8-bit conversion, a 16-bit scratch register is needed. However, a 32-bit scratch register, with the original 8-bit data loaded in the low byte would mae the bit shifting easier.
Step 3 (Assembly - Double Dabble).
Filename: DoubleDabbleDisplay2026.S
Reference:
Double Dabble Algorithm (binary to BCD)
- The experience gained from the previous steps should enable you to implement the Double Dabble algorithm in AVR Assembly.