EASy68K
http://www.easy68k.com/EASy68Kforum/

Illegal instruction found?
http://www.easy68k.com/EASy68Kforum/viewtopic.php?f=6&t=1149
Page 1 of 1

Author:  jakemoly [ Mon Dec 10, 2012 10:33 am ]
Post subject:  Illegal instruction found?

I'm trying to display [3 * 6 + 9 = 27],

Code:
   ORG   $1000
START:   move   #3,d0
   move   #3,d1
   trap   #15
   move   #14,d0
   lea   textD1,a1
   trap   #15
textD1   dc   ' * '
   move   #6,d1
   move   #3,d0
   trap   #15
   move   #14,d0
   lea   textD2,a1
   trap   #15
textD2   dc   ' + '
   move   #9,d1
   move   #3,d0
   trap   #15
   move   #14,d0
   lea   textD3,a1
   trap   #15
textD3   dc   ' = '
   move   #27,d1
   move   #3,d0
   trap   #15
   END   START


but I found it can't display 27 after displaying =,
and it told me that illegal instruction found.

So, I use task number 17 instead of 14 in the last text,
Code:
   ORG   $1000
START:   move   #3,d0
   move   #3,d1
   trap   #15
   move   #14,d0
   lea   textD1,a1
   trap   #15
textD1   dc   ' * '
   move   #6,d1
   move   #3,d0
   trap   #15
   move   #14,d0
   lea   textD2,a1
   trap   #15
textD2   dc   ' + '
   move   #9,d1
   move   #3,d0
   trap   #15
   move   #17,d0
   lea   textD3,a1
   move   #27,d1
   trap   #15
textD3   dc   ' = '   
   END   START


I can successfully display [3 * 6 + 9 = 27] but it still shows illegal instruction found. What happened??

Author:  lee [ Mon Dec 10, 2012 1:24 pm ]
Post subject:  Re: Illegal instruction found?

Quote:
I can successfully display [3 * 6 + 9 = 27] but it still shows illegal instruction found. What happened??
After the TRAP #15 call there is nothing to tell the simulator to jump over the
Code:
textD1   dc   ' * '
so, just like a real CPU would do, the simulator tries to execute it.

Sometimes you will get away with this as the data will be equivalent to harmless, from your porgram's point of view, instructions. Other times it will cause catastrophic errors.

What you want to do is arrange your source so that the code and data aren't mixed, something like this ..

Code:
* equates for values go here

CR    EQU   $0D                           * [CR] character
LF    EQU   $0A                           * [LF] character

* now set the start address of your code

      ORG         $1000

* now all the code

start
      LEA         string(pc),a1           * point to the string
      MOVEQ       #13,d0                  * display a string with [CR][LF]
      TRAP        #15

      MOVEQ       #9,d0                   * halt the simulator
      TRAP        #15

* now the data

string
      dc.b  '$'
      dc.b  CR,LF
      dc.b  $09,'Test line 1'
      dc.b  CR,LF
      dc.b  0

      END         start

Lee.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/