Page 1 of 1

jumptable PB 6.0 asm and c backend

Posted: Fri Jul 01, 2022 8:17 am
by idle
jumptable code pattern for PB 6.0 x86/x64/arm Asm and C backends

edit: changed to pointer array, mk-soft

Code: Select all

Structure ArrayOfPointer
  *Index[0]
EndStructure

Procedure JumpTable_test(index)
  Protected *addr.ArrayOfPointer = ?jt 
  Protected result 
  
  DataSection : jt:
     Data.i ?l0 , ?l1 , ?l2 , ?l3 , ?l4
  EndDataSection 
  
  If index < 5 
    
    CompilerIf #PB_Compiler_Backend = #PB_Backend_C    
      !goto *p_addr->f_index[v_index];
    CompilerElse 
      EnableASM  
      jmp *addr\Index[index]
      DisableASM 
    CompilerEndIf 
    
  Else 
    Goto lE 
  EndIf  
    
  l0: 
  result =  0
  Goto lE 
  l1: 
  result = 1  
  Goto lE
  l2:
  result =  2  
  Goto lE 
  l3:
  result = 3 
  Goto lE 
  l4:
  result =  4  
  lE:
  
  ProcedureReturn result 
EndProcedure    

Debug JumpTable_test(3)



Re: jumptable PB 6.0 asm and c backend

Posted: Sun Jul 03, 2022 3:35 pm
by Jeromyal
Hey ! This is some ground work for some really clever stuff.

Thanks for sharing.

Re: jumptable PB 6.0 asm and c backend

Posted: Tue Jul 12, 2022 6:57 pm
by Blue
Smart and useful.
Thank you, idle