Silly 68k question

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

Post Reply
powerofrecall
Very interested
Posts: 237
Joined: Fri Apr 17, 2009 7:35 pm
Location: USA

Silly 68k question

Post by powerofrecall »

I have been experimenting with the Easy68k environment to do some MD stuff.

The syntax is pretty much straight up Motorola so I have the old SGCC header/crt0 asm assembling and working okay... Easy68k's assembler is supposed to respect the original motorola style.

What I can't figure out though is why it won't accept

move.l (variable), a2

or

movea.l (variable), a2

am I missing something? Obviously I'm trying to load a RAM address into A2, but it dies here with "invalid syntax."
Chilly Willy
Very interested
Posts: 2993
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy »

That would be

movea.l variable,a2
movea.l variable.w,a2
movea.l variable.l,a2

Without .w or .l, the assembler picks one or the other based on the address of the variable. Using .w or .l explicitly tells the assembly to use short or long absolute addressing. The RAM and ROM in the Genesis are placed so that the lower 32 KB of ROM and upper 32 KB of RAM can be addressed with short absolute addressing to make programs smaller and faster (4 fewer cycles on short absolute addressing).

If you wanted the address of the variable in the register, you'd do

lea variable,a2
lea variable.w,a2
lea variable.l,a2
movea.w #variable,a2
movea.l #variable,a2
powerofrecall
Very interested
Posts: 237
Joined: Fri Apr 17, 2009 7:35 pm
Location: USA

Post by powerofrecall »

So basically with movea I have to reference it as an immediate, with lea I can reference directly?

The differing addressing modes on 68k confuse the hell out of me; I'm new to it. Sometimes I wonder if I should stick to C :D

As background I'm no asm guru on any CPU, the only ones I "get" are the most basic like 6502 mnemonics.
Chilly Willy
Very interested
Posts: 2993
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy »

Sounds like you need to read the programmer's reference again. :D

http://www.freescale.com/files/archives ... 000PRM.pdf

You'll find an explanation of the addressing modes in section 2 (page 42). I highly recommend learning the 68000 assembly if you wish to program on the Genesis. If you just can't wrap your head around assembly, try Stef's mini DevKit. It lets you do the programming in C.

viewtopic.php?t=14

Or if you're more into BASIC, try BEX.

http://devster.proboards.com/index.cgi? ... asiegaxorz
powerofrecall
Very interested
Posts: 237
Joined: Fri Apr 17, 2009 7:35 pm
Location: USA

Post by powerofrecall »

Haha, thanks man for not making too much fun of me. I get how asm works and how memory-mapped hardware works in general (I used to hack around on GBA stuff), so I think I can learn. I went with easy68k because it has built in if/then/for macros for people like me. :wink:

I actually have Stef's kit and it is fantastic for just banging out stuff. Still, I'm wanting to do a "demo" style demo with raster effects and such and asm is actually cleaner than a bunch of goofy C pointer math :D My inner nerd wants to understand it, too...
Chilly Willy
Very interested
Posts: 2993
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy »

Well, one thing you could do is write the code in C, then look at the assembly generated. That's how some people learn asm. Not me, but others. :)
TmEE co.(TM)
Very interested
Posts: 2452
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) »

such ASM does not look too good..... too much stack use too I believe :P
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen
Chilly Willy
Very interested
Posts: 2993
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy »

Among other issues, which is why I generally don't do that. I've only looked at c generated assembly when I wanted specific info about the ABI.
Post Reply