Results 1 to 4 of 4

Thread: Select Case Question

  1. #1

    Select Case Question

    Since the "Select Case" Command selects the value of a byte, it would seem logical that the number of "CASE IS" options would be 256 (0 >> 255). However, in a few instances I found myself getting compile errors. If I reduce the number of options, the error goes away. What is the magic number, and can it be extended to 256?

    Mike

  2. #2
    Hi Mike,
    I'm curious what you're doing. Are you saying that you actually have more than 255 CASE statements?
    I don't know if there's an actual limit on how many "Cases" you can have but the variable used in the SELECT CASE statement doesn't have to be a BYTE, you can use a WORD
    Code:
    Test VAR WORD
    
    Select Case Test
    
    Case 0
      Toggle PortB.0
    
    Case 400
      Toggle PortB.1
    
    Case 1000
      Toggle PortB.2
    
    End Select
    If there is a limit I'm sure you can figure out how to split it up into two blocks.

    /Henrik.

  3. #3
    Senior Member
    Join Date
    Sep 2011
    Location
    australia
    Posts
    253
    Looking at a simple example

    Code:
    select case inx
                   case 0
                     portc=portc&$fe
                   case 1
                     portc=portc|1
                   case 2
                     portc=portc&$fd
                   case else
                     portc=portc|2
                   end select
    assembles to this
    Code:
    ; C:\PBP3\EXAMPLES\SCEMO.PBP	00148	             select case inx
    
    ; C:\PBP3\EXAMPLES\SCEMO.PBP	00149	               case 0
    	CMPNE?BCL	_INX, 000h, L00009
    
    ; C:\PBP3\EXAMPLES\SCEMO.PBP	00150	                 portc=portc&$fe
    	AND?BCB	PORTC, 0FEh, PORTC
    
    ; C:\PBP3\EXAMPLES\SCEMO.PBP	00151	               case 1
    	GOTO?L	L00008
    	LABEL?L	L00009	
    	CMPNE?BCL	_INX, 001h, L00010
    
    ; C:\PBP3\EXAMPLES\SCEMO.PBP	00152	                 portc=portc|1
    	OR?BCB	PORTC, 001h, PORTC
    
    ; C:\PBP3\EXAMPLES\SCEMO.PBP	00153	               case 2
    	GOTO?L	L00008
    	LABEL?L	L00010	
    	CMPNE?BCL	_INX, 002h, L00011
    
    ; C:\PBP3\EXAMPLES\SCEMO.PBP	00154	                 portc=portc&$fd
    	AND?BCB	PORTC, 0FDh, PORTC
    
    ; C:\PBP3\EXAMPLES\SCEMO.PBP	00155	               case else
    	GOTO?L	L00008
    	LABEL?L	L00011	
    
    ; C:\PBP3\EXAMPLES\SCEMO.PBP	00156	                 portc=portc|2
    	OR?BCB	PORTC, 002h, PORTC
    
    ; C:\PBP3\EXAMPLES\SCEMO.PBP	00157	               end select
    	LABEL?L	L00008
    its just a simple test ,jump to test fail label if test fails and then do the next test till the end. or continue on to execute the selected code and jump to to the end .

    unless the compiler's label generator is limited to byte size I can't see a problem , i'm not sure about wether a code page rollover issue is possible .

    a > 255 selectcase chain does seem a bit messy , worse than a Microsoft eula to read I suspect

    mike if you can provide a compliable example of a failure it would be interesting

  4. #4
    SELECT CASE ID ;ID = BYTE
    CASE 0 : TP = Val
    CASE 1 : TA = Val
    CASE 2 : TC = Va
    ..............................
    CASE 240 : OCT = Val
    CASE 241 : JAC = Val
    END SELECT

    The Page Roll idea may be it. I may have to do this in assembly and specify a block of memory to do it. I wanted to create an INCLUDE library that would work with practically any processor. May have to rethink the whole thing, like break it down into smaller chunks with an ELSE opt out to the next filter. Thanks for the input folks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •