[fpc-pascal] CASE

Eduardo nec556 at retena.com
Tue Nov 8 20:35:45 CET 2005

At 18:22 08/11/2005, you wrote:
>>>Any hints?
>>Use 2.1.1
>version 2.1.1 [2005/11/08] for powerpc
>Same result, Peter :|
>P Davidson

Perhaps this code can do the trick, but don't know if is easily 
integrable in fpc ppc codegenerator, you can adapt it a bit if you want

** IN r3 Value to check r29 branch lookup table r5 top/end r6 
low/begin r4 where to branch

SecuentialCase: lwz        r3,VALUE         // VALUE from TOC or BSS or other.
                          subi       r29,r29,4          // Adjust 
value for access
           caseloop: lwzu      r4,4(r29)          // in address 
pointed by r29 begins the jump look-up table (L1051,L1052)
                          mtctr     r4                    // Move 
address in r4 to CTR special register. CTR has now the destiny address
                          lwz        r5,TOP             // last value
                          lwz        r6,LOW            // low value
                          cmplwi   cr2,r3,r6           // compare if 
value with r6
                          bcctr     12,10                // BO = 12 
Branch if condition True. BI = 10 Condition flag Equal of cr2.
                          addi       r6,r6,1              // r6 := r6 +1
                          cmplwi   cr3,r5,r6           // is r6 > r5 ?
                          ble        cr3,caseloop     // Branch to 
caseloop if FALSE
                          otherwise statement or branch to it

** OUT r29, r6 originals values are destroyed.  

More information about the fpc-pascal mailing list