# Signetics 2650 & 2636 programming/BCD arithmetic

### Binary Coded Decimal

The natural way for a microprocessor to represent numbers and perform arithmetic is in binary format. Humans prefer decimal notation, so when a computer wants to communicate with us, it has to convert from one format to the other. Another option is to force the computer to operate on binary-coded decimals, where each decimal digit, 0-9, is represented by 4-bits. The other six numbers that can be represented by those four bits, A16 - F16 are meaningless, and this makes binary arithmetic more complicated than in a pure binary format. If for example we do the addition 8 + 4 in binary, the result is C16 which is meaningless in BCD. To get the correct answer we must add six, giving 1216. The '1' is carried to the next most significant digit.

The primary use of BCD in these video game consoles is for displaying the score, a number that is typically only incremented, so our discussion here will be confined to addition of BCD numbers. Should your game require subtraction, signed integer arithmetic or division, the Application Memo listed in the references below should help.

 ```0000 1F0004  : 0003 17  : 0004 7620  : 0006 7708  : 0008 7501  : 000A 0C1F51  : 000D 0D1F50  : 0010 0F1F52  : 0013 8466  : 0015 8566  : 0017 7501  : 0019 83  : 001A 94  : 001B 8500  : 001D 95  : 001E CC1F51  : 0021 CD1F50  : 0024 1B60  :  :  :  :  :  :  :  : ``` ```bcta,un start  ; reset vector retc,un  ; interrupt vector start: ppsu intinhibit ;inhibit interrupts loop: ppsl withcarry cpsl carry loda,r0 lsbA  ; get the score loda,r1 msbA loda,r3 inc  ; get the increment addi,r0 H'66' addi,r1 H'66' cpsl H'01'  ; clear carry addz r3  ; perform BCD addition, scoreX = scoreX + r3 dar,r0 addi,r1 H'00' dar,r1 stra,r0 lsbA  ; save result stra,r1 msbA bctr,un loop msbA equ \$1F50 lsbA equ \$1F51 inc equ \$1F52 carry equ \$01 withcarry equ \$08 intinhibit equ \$20 ```