Re: A89: Address Error
[Prev][Next][Index][Thread]
Re: A89: Address Error
Schony wrote:
> Yes i get it at the rts at the very end how do i get rid of that? also what
> do you mean by "in some way are trying to access a word or a long at an odd
> address"? and Messed up some pointers? Just want to kn ow cuz I get the
> error often and I hate it!
If you get it at the rts, you have in some way leave trash on the stack, or
taken to much off the stack as Scott said..
You see, when a subroutine is called by jsr or bsr, the address of the
instruction right after it, is stored on the stack. then, what the rts does, is
simply take the longword off the top of the stack and jump to that address. If
you have used the stack, it is therefore vital that the stackpointer is the same
at the rts, as it was in the beginning of the subroutine. otherwise it will jump
out in nothingness, and generate an illiegal instruction, or an address error or
a line xxxx error, depending on what just happen to be at that address. most
likely is address error, followed by illiegal instruction.
you see, any instruction ending in a .w or a .l and therefore is operating on
words or longwords (2 bytes, or 4 bytes at the same time) can only operate on
even memoryaddresses. if it is odd, it will generate an address error.
when the processor fetches new instructions from memory to be executed, it does
this a word at a time. therefore, if you try to jump to an odd address, the
processor will try to read the next instruction from an odd adress, and
therefore generate an address error.
I hope this cleared things up a bit.
//Olle
References: