Laurian Angelescu

Illegal instruction exception generated when executing rts

Discussion created by Laurian Angelescu on Jun 18, 2006
Latest reply on Jun 18, 2006 by Laurian Angelescu
Hi all, I've been trying to fix an illegal exception for a couple of hours now with no success.

What happens is that I have a piece of code that checks for imputs and branches to appropriate subroutine. But after the subroutine finishes when executing the RTS to return to the called throws an Illegal exception. The address in PC seems to be 00000000 which is complete garbage. At the same time I did check my stack manipulation and it looks fine to me. The code snip:

Caller:


Code:

process_input
move.l A0, -(A7)
move.l D0, -(A7)
clr D0
lea BUFFER, A0
move.b (A0), D0
cmpi.l #$31, D0
beq return_to_monitor
cmpi.l #$32, D0
beq calculator_mode
cmpi.l #$33, D0
beq clock_mode
cmpi.l #$34, D0
beq clock_display
move.l (A7)+, D0
move.l (A7)+, A0
rts

Called sub:

clock_mode
move.l A1, -(A7)
lea ERROR_OPTION_UNAVAILABLE, A1
bsr.w out_string
move.l (A7)+, A1
rts
This final RTS instruction generates (snip of trace):

PC: 1020010A SR: A704 [T.Sm.111...xnZvc]
An: 10220000 00000000 00000000 00000000 00000000 00000000 00000000 1023FFEC
Dn: 00000033 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1020010A: 4E75 RTS

trace>

PC: 00000000 SR: A704 [T.Sm.111...xnZvc]
An: 10220000 00000000 00000000 00000000 00000000 00000000 00000000 1023FFF0
Dn: 00000033 00000000 00000000 00000000 00000000 00000000 00000000 00000000

trace>


PC: 00000000 SR: A704 [T.Sm.111...xnZvc]
An: 10220000 00000000 00000000 00000000 00000000 00000000 00000000 1023FFF0
Dn: 00000033 00000000 00000000 00000000 00000000 00000000 00000000 00000000

Exception:
Illegal Instruction
format: 0x04 fault status: 0x0
vector: 0x04 status reg: 0xA704

I do not know how to approach this, I'm thinking maybe the stack is broken, but I checked my pushes and pops and they match. What causes this exception to arise when executing an rts?

Message Edited by NOPz on 2006-06-17 08:48 PM

Message Edited by NOPz on 2006-06-17 08:49 PM

Outcomes