beckadam

variable->register opt

Aug 6th, 2020
3,169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. ; scopes with up to 3 effective registers could easily be optimized.
  3. ; ex.
  4. ;  int countByteMatches(uint8_t *ptr, uint8_t c){
  5. ;    int matches=0;
  6. ;    while (*ptr){
  7. ;      if (*ptr++==c) matches++;
  8. ;    }
  9. ;    return matches;
  10. ;  }
  11.  
  12. ;optimized code
  13. ;returns int
  14. ;inputs u8_ptr,u8
  15. countByteMatches:
  16.     call ti._frameset0
  17.     or a,a
  18.     sbc hl,hl
  19.     ld de,(ix+3)
  20.     ld c,(ix+6)
  21. .loop:
  22.     ld a,(de)
  23.     inc de
  24.     cp a,c
  25.     jr nz,.notequal
  26.     inc hl
  27. .notequal:
  28.     or a,a
  29.     jr nz,.loop
  30.     ret
  31.  
  32.  
Advertisement
Add Comment
Please, Sign In to add comment