А для какой цели? Если для счёта в игре, то я использую такую штуку от автора AGD. Счёт храниться как строка и печатаешь его как строку, а для добавления используется addScore.
Т.е. когда нужно добавит счёта, например 5 очков, делаем так:Код:
score defb "000000"
addScore ld a,(hl) ; current value of digit.
add a,b ; add points to this digit.
ld (hl),a ; place new digit back in string.
cp 58 ; more than ASCII value '9'?
ret c ; no - relax.
sub 10 ; subtract 10.
ld (hl),a ; put new character back in string.
uscor0 dec hl ; previous character in string.
inc (hl) ; up this by one.
ld a,(hl) ; what's the new value?
cp 58 ; gone past ASCII nine?
ret c ; no, scoring done.
sub 10 ; down by ten.
ld (hl),a ; put it back
jp uscor0 ; go round again.
Когда нужно реализовать hiScore, просто сравниваем два набора строк, например так:Код:ld hl,score+5
ld b,5
call addScore
Код:checkHiScore
xor a
ld (HI_SCORE_FLAG),a
;cp two sets of ASCII
ld ix,score
ld hl,hScore
ld b,6 ;5 digits only, the 6th one is always 0
chilp ld a,(ix+0) ;new score byte
cp (hl) ;cp old score byte
ret c ;if carry set old score is higher
jr nz,newsc ;nc & nz means new score is higher
inc ix
inc hl
djnz chilp
ret ;reaching here means hi & low score equal
newsc ld hl,score ;ok new score is higher than old hi score
ld de,hScore ;new high score, so ldir it in place
ld bc,6
ldir
;set hi score flag
ld a,1
ld (HI_SCORE_FLAG),a
ret

