The following warnings occurred:
Warning [2] Undefined array key 0 - Line: 1677 - File: showthread.php PHP 8.2.31 (Linux)
File Line Function
/inc/class_error.php 157 errorHandler->error
/showthread.php 1677 errorHandler->error_callback
/showthread.php 916 buildtree




Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tutorial: How to put inline assembly functions into ZX Basic
#11
LCD Wrote:
Code:
function mirror(dowedoit as ubyte, number as ubyte) as ubyte dim result as ubyte if dowedoit then result=(number&1)<<7|(number&2)<<5|(number&4)<<3|(number&8)<<1|(number&16)>>1|(number&32)>>3|(number&64)>>5|(number&128)>>7 Else result=number end if return result end Function
Though if I was going to, I'd say why bother with a new variable? :mrgreen:

Code:
function mirror(dowedoit as ubyte, number as ubyte) as ubyte if dowedoit then number=(number&1)<<7|(number&2)<<5|(number&4)<<3|(number&8)<<1|(number&16)>>1|(number&32)>>3|(number&64)>>5|(number&128)>>7 end if return number end Function

That said, if you read the behemoth assembly that makes. Ouch. Hopping on and off the stack like crazy! Not to mention a lot of very expensive reads and writes to (IX+7) - which cost 19 T states each. I wonder if my original beginners algorithm is faster!

Anyway, I think my suggested optimized version is pretty tight:

Code:
function fastcall mirror (dowedoit as uByte, number as uByte) as uByte asm pop hl pop bc AND A LD A,B RET Z ld b,8 ld c,a XOR A mirrorLoop: RR C RLA DJNZ mirrorLoop jp (hl) end asm END FUNCTION
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 3 Guest(s)