| Click here to select a new forum. |
| Learning 68k assembly - issues with _NewWindow |
Posted by: Crutch on 2022-10-01 05:42:23 From memory (I haven’t used CodeWarrior in a few years), CodeWarrior lets you write whole functions in assembly, if desired, but not use assembly instructions inside C functions.
In (at least) the System 6-7 era, the best choice for 68K assembly embedded in a C program was THINK C, which lets you sprinkle assembly anywhere you like in a very well-integrated way. For example, say you have patched an OS trap that takes a param in d0, and you have stored its address in oldAddr. You can cleanly head-patch it from C code (such that the trap doesn’t see your patch as a return address on the stack) like this:
long foo;
Ptr oldAddr;
…
if (foo < 6)
asm {
move.l oldAddr, a0
move.l foo, d0 // contents of foo are now in d0
unlk // clean up your stack frame; RTS from the code at a0 will return directly to our caller
jmp (a0)
// never get here
}
You can also use goto to jump into asm blocks, use an asm block as a secondary entry point to a function different from the one currently executing (a very powerful/dangerous feature!), and do many other nifty things. (You can only do this from C code, not from inside a C++ code file.)
It doesn’t let you assemble “bare” assembly programs, that’s true, though I’m not sure if this is ever strictly necessary. You could if desired put all of your code inside one giant asm{…} block! |
Posted by: Crutch on 2022-10-01 08:41:12 Or my personal favorite -
asm {
move.l myVar, d0
_Debugger
}
now I can see what’s in myVar at a glance inside Macsbug by just looking at d0 without doing a NumToString |
Posted by: Phipli on 2022-10-01 10:08:38
From memory (I haven’t used CodeWarrior in a few years), CodeWarrior lets you write whole functions in assembly, if desired, but not use assembly instructions inside C functions. I think it lets you do both, according to the link I shared. I could be wring. I've not done it. |
Posted by: cheesestraws on 2022-10-01 10:13:28
I think it lets you do both, according to the link I shared. I could be wring. I've not done it.
Think that's a newer version thing. The version I use can't. |
Posted by: Phipli on 2022-10-01 10:15:08
Think that's a newer version thing. The version I use can't. Makes sense.
Can you link pre-compiled blobs of code? You must be able to? Forgive my ignorance. |
Posted by: cheesestraws on 2022-10-01 10:51:09
Can you link pre-compiled blobs of code? You must be able to? Forgive my ignorance.
Oh, yeah. And you can put whole ASM routines in. It's just that you can't put asm in the middle of C routines |
Posted by: Crutch on 2022-10-01 11:05:15
I think it lets you do both, according to the link I shared. I could be wring. I've not done it. Pretty sure the link you shared is for some very modern CodeWarrior offshoot for “power architecture” processors.
I am not aware that CW ever allowed for inline (sub-function-level) assembly for 68K. But I may be wrong. Anyway, THINK C could do it in 1989 and maybe earlier 😊 (pretty sure 4.0 supported this) |
| < 2 |