Page 1 of 1

YACOC

Posted: Fri Oct 06, 2017 11:18 pm
by marste
(yet another code optimization challenge! :))

As the previous one (viewtopic.php?f=6&t=2597), here another one to get the teeth on:

It should be checked if d is zero or not, but depending on the value of one bit of b the jump should be taken if it is zero (if bit is also zero) or alternatively if it is not zero (as the bit of b).

As usual a starting piece of code:

Code: Select all

      ld a,d
      bit FLAGBIT,b
      jr z,checkforzerovalue
  checkforvaluenonzero:
      or a
      jr z,conditionistrue
      jr continuesinceconditionisfalse
  checkforzerovalue:
      or a
      jr nz,conditionistrue
  continuesinceconditionisfalse:
Let's start the dances!
:)

Re: YACOC

Posted: Sat Oct 21, 2017 1:29 am
by marste
Two byte less with:
(clearly the "mask" is the byte with the corresponding FLAGBIT bit high and the rest low)

Code: Select all

    ld a,d
    or a
    jr z,diszero
    ld a,FLAGBITMASK
diszero:
    xor b 
    and FLAGBITMASK
    jr z,conditionistrue
continuesinceconditionisfalse:
cannot be improved :?: