Increment a numerical string: Difference between revisions
Content deleted Content added
Puppydrum64 (talk | contribs) |
Puppydrum64 (talk | contribs) |
||
Line 3,370: | Line 3,370: | ||
=={{header|Z80 Assembly}}== |
=={{header|Z80 Assembly}}== |
||
As a test case, we'll start with 1999 and increment it to 2000. |
|||
It's much easier to do this using binary-coded decimal thanks to the <code>DAA</code> instruction. |
|||
<lang z80>;;;;;;;;;;;;;;;;;;; HEADER ;;;;;;;;;;;;;;;;;;; |
<lang z80>;;;;;;;;;;;;;;;;;;; HEADER ;;;;;;;;;;;;;;;;;;; |
||
read "\SrcCPC\winape_macros.asm" |
read "\SrcCPC\winape_macros.asm" |
||
Line 3,378: | Line 3,378: | ||
org &1000 |
org &1000 |
||
ld hl,NumericString |
ld hl,NumericString |
||
Line 3,387: | Line 3,385: | ||
jr z,displaystring |
jr z,displaystring |
||
add &01 |
add &01 |
||
cp &3A |
|||
daa |
|||
⚫ | |||
⚫ | |||
⚫ | |||
;carry forward |
;carry forward |
||
ld a,&30 |
|||
⚫ | |||
inc hl |
inc hl |
||
jr incstring |
jr incstring |
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
displaystring: |
displaystring: |
||
ld (hl),a ;store the last addition. |
|||
ld hl,NumericString_End |
ld hl,NumericString_End |
||
dec hl |
dec hl |
||
Line 3,401: | Line 3,401: | ||
cp 255 |
cp 255 |
||
ret z |
ret z |
||
call |
call &bb5a |
||
dec hl |
dec hl |
||
jr disploop |
jr disploop |
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
db 255 ;terminator when reading in reverse |
db 255 ;terminator when reading in reverse |
||
NumericString: |
NumericString: |
||
;stored little-endian for convenience |
;stored little-endian for convenience |
||
db & |
db &39,&39,&39,&31 |
||
NumericString_End: |
NumericString_End: |
||
db 255 ;terminator |
db 255 ;terminator |
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
read "\SrcCPC\winape_showhex.asm" |
read "\SrcCPC\winape_showhex.asm" |
||
read "\SrcCPC\winape_stringop.asm"</lang> |
read "\SrcCPC\winape_stringop.asm"</lang> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre>2000</pre> |
||
=={{header|zkl}}== |
=={{header|zkl}}== |