Jump to content

Photo

mixing assembly with basic


5 replies to this topic

#1 mos6507 OFFLINE  

mos6507

    River Patroller

  • 4,915 posts

Posted Fri Aug 26, 2005 1:12 AM

I was reading the docs in relation to user-defined functions and I was wondering how you would handle user-defined procedures that are coded in assembly.

Normally a procedure is handled with GOTO or GOSUB. If you had an assembly routine could you simply GOSUB to the label assigned to it within the asm?

I would also assume that labels, equates, constants have to be unique across all the cumulative asm and basic code otherwise the compilation will fail?

Also, might there be a way to pass-through calls to DASM macros?

#2 batari OFFLINE  

batari

    )66]U('=I;B$*

  • 6,680 posts
  • begin 644 contest

Posted Fri Aug 26, 2005 1:57 AM

I was reading the docs in relation to user-defined functions and I was wondering how you would handle user-defined procedures that are coded in assembly.

Normally a procedure is handled with GOTO or GOSUB.  If you had an assembly routine could you simply GOSUB to the label assigned to it within the asm?

close - to allow labels and linenumbers, bB sticks a dot (.) before everything because if it compiled goto 40 as JMP 40, it wouldn't jump to the label called 40 but instead would jump to zero-page address 40 and probably crash.

Come to think of it, maybe a dot wasn't the best choice because it's actually a "local label" in DASM - Maybe I'll change this to an underscore in the next version. But anyway, if you want to "goto" an asm procedure, you just add a dot before the label in asm, but maybe you'll need to change to an underscore later.

I would also assume that labels, equates, constants have to be unique across all the cumulative asm and basic code otherwise the compilation will fail?

Yes, but with the dot in front of all bB labels, it's unlikely to have asm conflict with bB labels, but asm labels in one module can certainly conflict with another. Therefore, using generic labels line "loop3" probably isn't a good idea for inline asm/asm modules.

Also, might there be a way to pass-through calls to DASM macros?

View Post

Like what?

Edited by batari, Fri Aug 26, 2005 1:58 AM.


#3 mos6507 OFFLINE  

mos6507

    River Patroller

  • Topic Starter
  • 4,915 posts

Posted Fri Aug 26, 2005 1:36 PM

Like what?

View Post


Like the macros inside macro.h such as SLEEP.

#4 batari OFFLINE  

batari

    )66]U('=I;B$*

  • 6,680 posts
  • begin 644 contest

Posted Fri Aug 26, 2005 2:39 PM

Like what?

View Post


Like the macros inside macro.h such as SLEEP.

View Post

You can do this in inline asm - does this answer your question?
  asm
  sleep 10
end

Edited by batari, Fri Aug 26, 2005 2:39 PM.


#5 vdub_bobby OFFLINE  

vdub_bobby

    Quadrunner

  • 5,832 posts
  • Boom bam.
  • Location:Seattle, WA

Posted Fri Aug 26, 2005 3:01 PM

Like what?

View Post


Like the macros inside macro.h such as SLEEP.

View Post

You can do this in inline asm - does this answer your question?

I am somewhat curious to know what use you would have for the SLEEP macro in bBASIC. ??

#6 mos6507 OFFLINE  

mos6507

    River Patroller

  • Topic Starter
  • 4,915 posts

Posted Sun Aug 28, 2005 8:29 AM

Like what?

View Post


Like the macros inside macro.h such as SLEEP.

View Post

You can do this in inline asm - does this answer your question?

I am somewhat curious to know what use you would have for the SLEEP macro in bBASIC. ??

View Post


You can do anything in inline asm. It's just that it defeats the purpose of using batari Basic to rely on it.

Macros are a little strange in assembly because normally you'd want to make something a subroutine and just call that instead of inserting code inline everytime you did something. Assembly subroutines can be integrated in batari Basic already. Nevertheless, there are some cases where macros make sense.

For instance, I was working on some macros for the Supercharger.

Instead of doing CMP $F000+$DD to set the value you are going to write to RAM, you could do SC_RAMVAL $DD or something similar, since it reads better.

so it would be the difference between doing this:


asm
     SC_RAMVAL $DD
end

and this:

     SC_RAMVAL $DD

Not having to bracket the macros with asm/end makes the code read a little better. Since DASM is going to process the files anyway, then I'm sure something like that would be easy to do. As long as the parser is told to pass through any lines it doesn't understand directly to DASM then as long as the macro is defined then it would work.




0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users