Assembler Addressing Error - PJ Monty
Hello PJ;
I believe I have discovered a bug in the SX assembler's label addressing assignments.
For convenience,·I use a macro that automatically adds a "PAGE" instruction to a jump (or call) address (only) when the addressed location is not on the current page. This saves some memory and execution cycles compared to always adding a PAGE instruction before a jump or a call.
I name this macro jmp@, and invoke it as:
Address1··· jmp@··· Address2
and define it as:
jmp@·· ·macro···································· ;
··· ······ TargetPage = \1 >> 9··············· ;calculate page of the target address
······ ··· CurrentPage = $ >> 9··············· ;calculate page of current address counter
········· ·if TargetPage = CurrentPage······ ;test for same
············ ·jmp··· \1····························· ;if same then only issue jump instruction
··· ······ else······································· ;
······ ······ page· \1·······························;if different then issue page and jump instruction
········· ··· jmp··· \1
········· ·endm
This works great until the targetted address actually spans a page boundary, and the PAGE instruction is issued.·When that occurs,·the assembler miscalculates the address of the target by one location.
I did some experimentation, adding some superfuous instructions to the macro, and it turns out that the magnitude of the address error is the difference in size (number of instructions) between the "if" and "else" halves of the macro...... one in my case.
I have exhaused my ideas in how to "fool" the assembler using org statemnets, messing with the program counter·and so on, but no success in that so far.
Could you have a peek and correct that bug?
And if you really wanted to make us all thrilled, why not have the assembler thake care of issuing the necessary PAGE statements (only) when required? This could be a selectable configuration option.
Thanks for your consideration.
Cheers,
Peter (pjv)
P.S.· I for got to mention that when the address calculation is in error, all address labels further down are also off by that amount.
Post Edited (pjv) : 12/15/2006 6:14:52 PM GMT
I believe I have discovered a bug in the SX assembler's label addressing assignments.
For convenience,·I use a macro that automatically adds a "PAGE" instruction to a jump (or call) address (only) when the addressed location is not on the current page. This saves some memory and execution cycles compared to always adding a PAGE instruction before a jump or a call.
I name this macro jmp@, and invoke it as:
Address1··· jmp@··· Address2
and define it as:
jmp@·· ·macro···································· ;
··· ······ TargetPage = \1 >> 9··············· ;calculate page of the target address
······ ··· CurrentPage = $ >> 9··············· ;calculate page of current address counter
········· ·if TargetPage = CurrentPage······ ;test for same
············ ·jmp··· \1····························· ;if same then only issue jump instruction
··· ······ else······································· ;
······ ······ page· \1·······························;if different then issue page and jump instruction
········· ··· jmp··· \1
········· ·endm
This works great until the targetted address actually spans a page boundary, and the PAGE instruction is issued.·When that occurs,·the assembler miscalculates the address of the target by one location.
I did some experimentation, adding some superfuous instructions to the macro, and it turns out that the magnitude of the address error is the difference in size (number of instructions) between the "if" and "else" halves of the macro...... one in my case.
I have exhaused my ideas in how to "fool" the assembler using org statemnets, messing with the program counter·and so on, but no success in that so far.
Could you have a peek and correct that bug?
And if you really wanted to make us all thrilled, why not have the assembler thake care of issuing the necessary PAGE statements (only) when required? This could be a selectable configuration option.
Thanks for your consideration.
Cheers,
Peter (pjv)
P.S.· I for got to mention that when the address calculation is in error, all address labels further down are also off by that amount.
Post Edited (pjv) : 12/15/2006 6:14:52 PM GMT

Comments
Let me look into what the problem is in SASM so I know what I am up against.
Thanks, PeterM
http://forums.parallax.com/showthread.php?p=527026
regards peter
Yes, I see you describe exactly what I have re-discovered.
When I ran into this, I thought it was a remnant of the similar @jmp / @call adress calculation error I discovered in early 2005. Apparently not so, and perhaps there is no practical answer...... hopefully PJ can find something, but it's not the end of the world.
Just as long as everyone is very aware!
Cheers,
Peter (pjv)
I thought this one sounded familiar. As far as I can tell, I fixed this one February 21, 2005 in SASM version 1.51.06. Here is a snippet of the list file I get using SASM 1.51.07, which part of the IDE version 3.1 and higher:
53 0206 0012 page NextPage ; Manually insert the page instruction 54 0207 0A00 jmp NextPage 55 56 Address1 jmp@ NextPage ;Automatically insert the page instruction 57 =00000002 m TargetPage = NextPage >> 9 ;calculate page of the target address 58 =00000001 m CurrentPage = $ >> 9 ;calculate page of current address counter 59 m if TargetPage = CurrentPage ;test for same 60 m jmp NextPage ;if same then only issue jump instruction 61 m else ; 62 0208 0012 m page NextPage ;if different then issue page and jump instruction 63 0209 0A00 m jmp NextPage 65 66 67 ;Address2 jmp@ SamePage 68 020A 0B98 jmp SamePage 69 70 =00000398 org $398 71 =00000398 SamePage 72 73 =00000400 org $400 74 75 =00000400 NextPageLines 62 and 63 show the macro in action where it inserts the page instruction and generates a JMP command of "0A00".
Lines 53 and 54 show me manually inserting the page and doing the JMP and getting the same result. I put the manual version before the macro to avoid the potential problem where said all subsequent addresses were off by one.
I have attached my source file. Am I misunderstanding something (or making a mistake on my end) about this problem?
BTW, there does seem to be a problem when no page is required from the macro. In that case, I am getting a crash in SASM which I am investigating.
Thanks, PeterM
That gives a SASM DLL error, hence a crash.
regards peter
I found the problem with the crash when no page was needed - the macro you show in your original post has an "if" without a corresponding "endif". Obviously SASM should handle this correctly with a warning, but there is something about the if/else being inside a macro that causes the crash before SASM can figure out it is missing the "endif". I'll see if I can fix that bug, but for now at least I don't have crashes with the macro whether it is adding a "page" or not.
Thanks, PeterM
Updated - I see I posted my message after you posted yours, hence the re-discovery of the missing "endif".