From your description I assume that this could work.
(untested code !!)
; * Addition: ; Input: BC = base address of addend+5, DE = base address of adder+5 ; Output: Addend replaced by addend plus adder _BCDadd: ld h,b ld l,c and a rept 5 ; 10 BCD digits ld a, (de) ;get byte of adder adc a, (hl) ;add it to addend, care for carry daa ;convert to BCD-decimal ld (de), A ;save number back in addend dec hl ;next number dec de endm ;continue until all bytes summed ret ; * Subtraction: ; Works nearly the same, but instead of the ADC, a SBC is used. ; Input: BC = base address of minued+5, DE = base address of subtrahend+5 ; Output: Minuend replaced by minuend minus subtrahend _BCDsub: ld h,b ld l,c and a ex de,hl ;exchange subtrahend and minuend rept 5 ; 10 BCD digits ld a, (de) ;get byte of minuend sbc a, (hl) ;subtract byte of subtrahend daa ;convert to BCD-decimal ld (de), A ;save number back in minuend dec hl ;next number dec de endm ;continue until all bytes summed ret
code from this site seemd broken
http://icarus.ticalc.org/articles/z80_faq.html
as no carry is passed between digits in different bytes
Seems fine to me... in both snippets, loop is entered with carry reset (or A), and carry is passed between bytes (adc, sbc). The other loop instructions (LD, INC/DEC rr, DJNZ) should preserve the carry between passes.
Btw. found it...
In: bit 0-3 of A = 0-F hex digit to print
OR #F0
DAA
ADD A,#A0
ADC A,#40 Out: A = ASCII code "0"-"9" or "A"-"F" depending on input
Absolutely brilliant code! (not mine, just found it somewhere in a book or on the 'net). Exercise for the reader: see if it's possible to modify such that ASCII output is in lower case...
Yes, indeed brilliant code! (wasn't it MSDs one?)
code from this site seemd broken
http://icarus.ticalc.org/articles/z80_faq.html
as no carry is passed between digits in different bytes
Seems fine to me... in both snippets, loop is entered with carry reset (or A), and carry is passed between bytes (adc, sbc). The other loop instructions (LD, INC/DEC rr, DJNZ) should preserve the carry between passes.
My fault, I was expecting carry was changed by djnz.
Thanks!
