Hello everyone,
I need to add a constant 8-bit value to a big list of 16-bit values stored in RAM, update them with the result and then check if that value is within a given range :
loop: (value) = (value)+constant if value < range_start then if value > range_stop then ... goto loop
But I need to make it fast, as fast as possible in fact.
This is the best solution I found so far.
If 'hl' contains the address of the list of 16-bit values, and 'e' contains the 8-bit constant value :
.loop ld a,e ; 5 | e = 8-bit constant exx ; 5 (std) add (hl) ; 8 ld c,a ; 5 ld (hl),c ; 8 inc hl ; 7 adc (hl) ; 8 sub c ; 5 ld b,a ; 5 ld (hl),b ; 8 ;------------------------------------------------------------------------------- ; test range ;------------------------------------------------------------------------------- ex de,hl ; 5 ld hl,(range_stop) ; 17 | range_stop is a negative value adc hl,bc ; 17 jp ns,.off_range ; 11 ld bc,range_stop-range_start ; 11 adc hl,bc ; 17 jp s,.off_range ; 11 (...)
The use of 'adc hl,bc' has the advantage of giving me the use of the 's' flag, which 'add hl,bc' does not. I loose the a little bit on the precision of the result, because I do not know the value of the carry, but that's OK.
I really need to make this subroutine go as fast as possible.
Would you have some ideas ?
Login أوregister لوضع تعليقاتك