PDA

View Full Version : Getting around asm - argument out of range - error



longpole001
- 13th May 2015, 06:26
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




' 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

richard
- 13th May 2015, 07:01
the error is not caused by that



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

longpole001
- 13th May 2015, 07:46
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

Tabsoft
- 13th May 2015, 14:33
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.

Tabsoft
- 13th May 2015, 22:22
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. :biggrin:

longpole001
- 14th May 2015, 10:33
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