EASy68K  
It is currently Sun Apr 05, 2020 10:46 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Question
PostPosted: Sun Dec 09, 2012 5:20 pm 
Offline

Joined: Thu Nov 08, 2012 6:07 pm
Posts: 12
Hi all ,
I have tried alot to solve this but I can not solve it without errors,
how can I determine the content of data register to decide later to which subroutine I had to go?


Top
 Profile  
 
 Post subject: Re: Question
PostPosted: Sun Dec 09, 2012 6:12 pm 
Offline

Joined: Mon Dec 27, 2004 11:40 pm
Posts: 318
Usually you would use a compare instruction followed by a conditional branch.

Can you share an example what you want to do and the code you've tried so far?

Lee.


Top
 Profile  
 
 Post subject: Re: Question
PostPosted: Tue Dec 11, 2012 5:44 pm 
Offline

Joined: Thu Nov 08, 2012 6:07 pm
Posts: 12
I have done this:
LEA MESG,A1
MOVE.B #14,D0
TRAP #15
MOVE.B #4,D0
TRAP #15
MOVE D1,D5
Here I want to move to subroutine depends on value of D5
there is four subroutines each for a specific value of D5


Top
 Profile  
 
 Post subject: Re: Question
PostPosted: Wed Dec 12, 2012 3:29 am 
Offline

Joined: Mon Dec 27, 2004 11:40 pm
Posts: 318
Aaaaagh! Always, always comment your code. Even it it seems trivial and obvious what it's doing. It may not be obvious what you were trying to do to anyone else.
Quote:
Here I want to move to subroutine depends on value of D5
there is four subroutines each for a specific value of D5
There are lots of ways, here are just two.

Use the Assembler Commands - Structured Control - IF Statement, like this.
Code:
 if.l d5 <EQ> #value1 then          * if d5 matches the first value
   bsr  subroutine1                 * do the first subroutine
 endi

 if.l d5 <EQ> #value2 then          * if d5 matches the second value
   bsr  subroutine2                 * do the second subroutine
 endi

* other values/subroutines go here
Or just 68000 code, no assembler specific commands.
Code:
      PEA         not_found(pc)     * push the return address

      CMPI.l      #value1,d5        * compare d5 with value 1
      BEQ         subroutine1       * if it matches go do subroutine 1

      CMPI.l      #value2,d5        * compare d5 with value 2
      BEQ         subroutine2       * if it matches go do subroutine 2

* other values/subroutines go here

      RTS                           * swallow the return address if no match

* all the subroutines will return here

not_found
I realise this last example uses a branch to call a subroutine but that has been taken care of by pushing the return address with PEA before any tests were done.

Other ways inlude aetting an address register depending on d5's value and doing a JSR (an) after the tests, using a lookup table and doing JSR (an,dn.w) or not calling a subroutine if there isn't a match ...

There are about as many ways to do it as there are programmers.

Lee.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group