Getting around asm - argument out of range - error


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838

    Default Getting around asm - argument out of range - error

    hi guys , i am getting the above error due to the following bit of code

    reason for the error is that SDC_PAGE IS BYTE, Event_Record_INX is a word

    although the code works for what is intend , i would like re do it so that it would not generate the warning error


    Code:
    ' get block  and page value from Event record Index - values 0-1023 
      IF Event_Record_IDX <  256 THEN  
         SDC_Block = (Current_Event*4) - 3                        ' 1ST 256K BLOCK - records 0 -255 
         SDC_Page  = Event_Record_IDX                             ' pages 0 - 255
      endif 
      IF Event_Record_IDX => 256 AND Event_Record_IDX < 512  THEN 
         SDC_Block = (Current_Event*4) -2                         ' 2ND 256K BLOCK - records 256-511
         SDC_Page  = Event_Record_IDX - 255                       ' pages 256-511
      ENDIF   
      IF Event_Record_IDX => 512 AND Event_Record_IDX < 768  THEN 
          SDC_Block = (Current_Event*4) -1                        ' 3RD 256K BLOCK - records 512-767
          SDC_Page  = Event_Record_IDX - 511                      ' pages 512-767
      ENDIF 
      IF Event_Record_IDX => 768 THEN
         SDC_Block = Current_Event * 4                            ' 4TH 256K BLOCK - records 768-1023
         SDC_Page  = Event_Record_IDX - 767                       ' pages 768-1023
      ENDIF

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,388


    Did you find this post helpful? Yes | No

    Default Re: Getting around asm - argument out of range - error

    the error is not caused by that

    Code:
     SDC_Page  var byte
     Event_Record_IDX   var word
                               
      Event_Record_IDX =1023
      while  Event_Record_IDX >64
      
      SDC_Page=   Event_Record_IDX- (Event_Record_IDX//256) *256
     
      Event_Record_IDX=Event_Record_IDX-64
     
      wend
    compiles with 0 errors

  3. #3
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: Getting around asm - argument out of range - error

    thanks for the reply , unfortunatly i cant change the value of Event_Record_IDX in any routine , and still wanted to avoid allocating a new word varable

    this solves the problem by making SDC_PAGE A WORD var

  4. #4
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: Getting around asm - argument out of range - error

    Looks like you are correct.

    The issue you see seems to be with the interim calculation for the assignment of SDC_PAGE.
    SDC_PAGE = (Event_Record_IDX- nnn) when nnn is 255, 511 or 767.
    The compiler seems to be generically testing the size of the variables during subtraction macro and letting you know that it is truncating the result of the interim step to a byte.
    You can get around this as you indicated by changing the SDC_PAGE variable type to a word size or defining a new variable of size word to store the " Event_Record_IDX - nnn" calculation in before the assignment to SDC_PAGE.
    E.G.
    B0 var word
    B0 = Event_Record_IDX - nnn
    SDC_PAGE = B0

    But this seems redundant.

    BTW, I don't know if you realize this or not but your IF/Then statements that assign the value to SDC_PAGE do not all set the values from 0 to 255.

    The first test for Event_Record_IDX < 256 obviously works because you are not manipulating anything, just a straight assignment.
    But the following three tests for 256 to 511, 512 to 767 and 768 to 1023 actually set SDC_PAGE to 1 to 256.
    If you want to set SDC_PAGE to 0 to 255 for each of these three blocks then you need to subtract 256, 512 and 768.

    For instance...
    If Event_Record_IDX = 256 then by doing SDC_PAGE = Event_Record_IDX - 255
    Then SDC_PAGE = 256 - 255 = 1, not 0
    If Event_Record_IDX = 513 then SDC_PAGE = Event_Record_IDX - 511 = 513 - 511 = 2, not 1, etc., etc.

    I don't know if this is what you are intending, but it's just an observation.
    Regards,
    TABSoft

  5. #5
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: Getting around asm - argument out of range - error

    You know you can simplify the IF/Then test blocks (actually eliminate them) and just use 2 statements.

    SDC_Block = (Current_Event * 4) - (3 - (Event_Record_IDX / 256))
    SDC_PAGE = Event_Record_IDX - ((Event_Record_IDX / 256) * 256)


    This will save you >100 code words or 194 bytes of code space.
    Regards,
    TABSoft

  6. #6
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: Getting around asm - argument out of range - error

    thanks tabsoft , did not see that 1-156 error , and the thanks for the compressed version ,
    i hate adding a variable or expanding any that i can avoid ,

    cheers guys

Similar Threads

  1. Replies: 7
    Last Post: - 27th December 2012, 21:42
  2. Missing Operator ASM error
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th June 2012, 07:26
  3. Argument out of range - how to find what is causing it?
    By BrianT in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd November 2011, 02:00
  4. MASM error 202 argument out of range
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 29th October 2011, 09:14
  5. Undefined Symbol error when using ASM interrupt
    By toalan in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th January 2005, 21:41

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

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