The CAN specialist
+31-40-2301.922

Bcd Commands <TOP>

mov al, 0x45 ; BCD 45 add al, 0x27 ; BCD 27 → binary result 0x6C daa ; adjusts to 0x72 (BCD 72)

The 8051 has a DA (Decimal Adjust) instruction that operates on the accumulator after addition. bcd commands

mov ax, 0x0405 ; unpacked 45 (AH=04, AL=05) add al, 0x03 ; add unpacked 3 → AL=08 aaa ; adjusts if AL>9, increments AH The 6502 has no dedicated BCD arithmetic instructions, but it includes a Decimal Mode flag (D flag in status register). When set, all ADC and SBC instructions automatically perform BCD arithmetic. mov al, 0x45 ; BCD 45 add al,

ld a, $45 add a, $27 daa ; A becomes $72 The Z80 DAA uses carry and half-carry flags to correct the accumulator. ARM (especially Thumb and Cortex-M) does not have dedicated BCD arithmetic instructions. BCD operations must be implemented via software routines, using bit manipulation and conditional addition/subtraction. ld a, $45 add a, $27 daa ;

mov ax, dx shr ax, 8 ; high byte of BCD1 mov dx, bx shr dx, 8 ; high byte of BCD2 add al, dl daa mov dl, al mov al, ah adc al, dh daa mov dh, al

| Command | Effect in Decimal Mode | |---------|------------------------| | | Set Decimal Mode (D=1) | | CLD | Clear Decimal Mode (D=0, back to binary) | | ADC | Adds with carry in BCD | | SBC | Subtracts with borrow in BCD |

seconds = rtc_read(0x00); // BCD 0x45 = 45 sec // Convert to binary for computation: bin_sec = ((seconds >> 4) * 10) + (seconds & 0x0F); Multiplexed displays often receive BCD directly from a 74LS47 decoder. Processor outputs BCD values to port. 5.3 Financial/Cash Registers Currency amounts must be exact to the cent. BCD arithmetic prevents floating-point errors:

Getting interested?

Are you interested in the CM CANopen for SIMATIC S7-1200? Please request, without any obligation, for a quote. Would you like more information? Please send an email to or visit our contact page.
You can call us if you like, we can be reached at +31-40-2301.922. We are pleased to help you and do offer you practical advice and support.

Related products

PC CAN-interfaces
CAN Repeaters
CAN Bridges & Gateways
Communicator CAN
CANopen X-gateway
canAnalyser 3 Suite
CAN Diagnostic Tools
CAN Accessories