• Updated 2023-07-12: Hello, Guest! Welcome back, and be sure to check out this follow-up post about our outage a week or so ago.

Learning 68k assembly - issues with _NewWindow

Crutch

Well-known member
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:

C:
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!
 
Last edited:

Crutch

Well-known member
Or my personal favorite -

C:
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
 

Phipli

Well-known member
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.
 

Crutch

Well-known member
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)
 
Top