EASy68K  
It is currently Sat Mar 25, 2017 5:52 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Mon Dec 28, 2015 4:49 am 
Offline

Joined: Tue Oct 20, 2015 7:09 pm
Posts: 7
I'm using EASy68K to write software for the Sega Genesis/Mega Drive. Even a modest program written for the Genesis platform entails a hefty amount of complexity, so I'm trying to think of ways to make my code more readable, manageable, and easier to debug. In the case of debugging, one idea I had was to implement bounds checking on arguments passed to macros. I was hoping I could use conditional assembly directives to do the checking, but I'm having a hard time figuring out how, if it's even possible at all. Here's a pseudocode example of what I'm trying to do:

Code:
TestMac MACRO

    ; move some immediate data \1 to a register \2, but only if \1 is in the range of #0-#23, and \2 is one of d0-d7

 IF \1 > #23, OR \1 < #0
    FAIL arg 1 is out of range - enter a value from #0-#23
    MEXIT
 ELSE
    IFNC \2 'd'?, OR \2 'D'?    ;  ? represents single character wild card
        FAIL arg 2 is invalid - enter a data register symbol from d0-d7
        MEXIT
    ENDC
 ENDIF

move.b \1, \2   ; args are in range if we've made it here

ENDM


     ORG $1000

StartLabel:

 TestMac #0, d4  ; this works, d4 = $xxxxxx00
 TestMac #24, d0   ; won't work, arg 1 is > #23
 TestMac #-1, d7   ; won't work, arg 1 is < #0
 TestMac #23, a0  ; won't work, arg 2 isn't a data register

 END StartLabel


After fiddling with this on my development PC, I get the sense that conditional assembly isn't suited to this task, but I'm still not sure. Does this approach to bounds checking for macro arguments make sense? If so, how would I make it work?


Top
 Profile  
Reply with quote  
PostPosted: Mon Dec 28, 2015 1:18 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1035
Location: Monroe County Community College, Monroe Michigan, U.S.A.
Try this:

Code:
TestMac MACRO
    ; move some immediate data \1 to a register \2, but only
    ; if \1 is in the range of #0-#23 and \2 is one of d0-d7

    ; if \1 is in the range of #0-#23
    IFLT \1     ; if argument \1 is < 0
        FAIL arg 1 is out of range. Enter a value from #0-#23
        MEXIT
    ENDC
    IFGT \1-23  ; if argument \1 is > 23
        FAIL arg 1 is out of range - enter a value from #0-#23
        MEXIT
    ENDC
   
    ; if \2 is not one of D0-D7
    IFLT ('\2'-'D0')
        FAIL arg 2 is invalid. Enter a data register from D0-D7
        MEXIT
    ENDC

    IFGT ('\2'-'D7')
        FAIL arg 2 is invalid. Enter a data register from D0-D7
        MEXIT
    ENDC

    move.b #\1, \2   ; args are in range if we've made it here
    ENDM

    ORG $1000

StartLabel:

    TestMac  0,d4  ; this works, d4 = $xxxxxx00
    TestMac 24,d0  ; won't work, arg 1 is > #23
    TestMac -1,d7  ; won't work, arg 1 is < #0
    TestMac 23,a0  ; won't work, arg 2 isn't a data register

    SIMHALT             ; halt simulator

* Put variables and constants here

    END StartLabel


_________________
Prof. Kelly


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 01, 2016 2:42 pm 
Offline

Joined: Tue Oct 20, 2015 7:09 pm
Posts: 7
Thanks for your help, Professor. Your code did the trick! After experimenting with it, I think I understand how EASy68K's conditional assembly and macro processing work together. Thank you again for your gracious assistance, I never would have figured this out on my own!


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 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:  
cron
Powered by phpBB® Forum Software © phpBB Group