Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
packed_bcd_additions [2016/06/01 17:04] ex_writer removed |
— (current) | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Packed BCD Addition ====== | ||
- | The following addition function assumes that both BCD numbers are stored with their least significant digits at the lowest address, and both numbers must have the same length. | ||
- | |||
- | <code z80> | ||
- | ;Input: HL = base address of addend, DE = base address of adder, B = length of numbers | ||
- | ;Output: Addend replaced by addend plus adder | ||
- | |||
- | ld A, B | ||
- | or A | ||
- | ret z ;test whether length = 0 | ||
- | Loop: | ||
- | ld A, (DE) ;get byte of adder | ||
- | adc A, (HL) ;add it to addend, care for carry | ||
- | daa ;convert to BCD-decimal | ||
- | ld (HL), A ;save number back in addend | ||
- | inc HL ;next number | ||
- | inc DE | ||
- | djnz Loop ;continue until all bytes summed | ||
- | ret | ||
- | </code> | ||
- | |||
- | **Source**: Icarus Productions' [[http://icarus.ticalc.org/articles/z80_faq.html|Z80 FAQ]] |