Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: Xeda112358 on January 08, 2012, 08:46:14 pm

Title: 68K ASM Help
Post by: Xeda112358 on January 08, 2012, 08:46:14 pm
I am just learning Assembly for the 68K series and I was wondering if anybody could provide a breakdown of how certain things work. I have a TI-89 Titanium, I consider myself a decently experienced z80 programmer, and I understand math. I have difficulty learning mnemonics, so I will probably ask questions multiple times about how certain instructions work until I solidly understand it.

The assembler I am using is an on-calc assembler that seems to work beautifully. It is the only thing I could understand how to install because my computer skills are massively lacking. Anyways, I looked at the source for a "hello world" program and I was just absolutely confused. I think that move instructions move data between registers and RAM and I believe the stack and PC, but there are operators and whatnot that I am not following. The instructions used are all unfamiliar to me:

movem.l       d4/a5,-(a7)
I am assuming this writes using d4 and a5 to the address pointed to by a7? Does the negative mean it decrements A7 ? I saw somewhere that A7 was a stack register
move.l         HeapAllocPtr*4(a5),a0
I have no clue what this syntax means. I checked out the hex and that helped me realise that it is like a 2 byte instruction followed by 0288h (which is HeapAlloc*4). But what does it mean to be right before (a5) ?
jsr              (a0)
Is this some kind of relative jump?
pea.l           3840
Does the .l mean it is a "long" operation? The hex has a 32-bit value equal to 3840. But what does pea mean and what does it do?
tst.l            d4
I cannot even begin... "tst" looks like test, so is this some way to check if an event has happened with d4?
beq.s          nomem
I haven't a clue, but since nomem is a label, does this jump
move.l        #3840,(a7)
Does this push an immediate value to the stack?
pea.l          LCD_MEM
I've not a clue... LCD_MEM seems to have a value of 4C00h, but this seems to be different from the last pea.l instruction (the hex is 4079h as opposed to 4879h, so this tells me that it is just a flag difference or a slight difference in operation from my experience with z80 hex)

lea.l          12(a7),a7
I don't get the syntax :/
pea.l          Hello_World(pc)
again, I is slightly different from the first pea.l (the hex is 487A versus 4879). This tells me that it is the same style if it were like z80
clr.l            -(a7)
I am not sure what clr.l is...


Sorry for all of the questions :/ tutorials don't generally help me much and I am still not understanding them yet, so this is why I turn to y'all. I am sure that, left to my own devices long enough, I could figure it all out on my own (I did that with z80), but I think it would be a lot neater if I could start programming soon. I am hoping that I can port some of my better known z80 attempts to 68K and  I also think this experience will be very helpful for understanding assembly on other processors. Thank you much in advance!
Title: Re: 68K ASM Help
Post by: chickendude on January 09, 2012, 12:41:27 am
Wow! Just today i was asking about resources for 68k assembly programming. I think you might be interested in this:
http://www.cs.tcu.edu/people/professors/nute/systems/68K_Instr.pdf
movem means MOVEMultiple (registers). I think the .l and .w mean longword and word respectively.
So maybe "movem.l d4/a5,-(a7)" would load the d4 register at (a7), decrement, then load a5 register at (a7-4
The next part:
move.l         $C8,a5
move.l         HeapAllocPtr*4(a5),a0
jsr              (a0)
...is essentially a 68k B_CALL (ROM_CALL). I suppose $C8 is the address of the rom call table, and the what the second command does is store the longword (i guess each romcall pointer takes up 4 bytes, hence the *4), using the value in a5 as an offset, then stores it into a0. Jsr (Jump to SubRoutine) jumps to the address held in a0.

pea = push effective address. So pea.l pushes the address that follows onto the stack.

tst: Yep, this is TeST. I think it basically is like an "or a" in z80, or cp 0, it tests if the register = 0.

beq.s nomem: bra is branch (jr), bXX are the conditions. BEQ is Branch on EQual, aka jr z. The .s means short, i think the default is 16 bits, not 8.

"move.l        #3840,(a7) Does this push an immediate value to the stack?"
Yep.

lea.l 12(a7),a7: Load Effective Address. a7+12 to a7. The (a7) is an offset, though i'm not sure if it uses the value of the register or the value of the address pointed to by the register. It looks like this might clear up the stack?

clr = clear, set register to 0.

A lot of the information i've found (TI specific, that is) is in French, but none of it too comprehensive and don't really explain things in much detail. A lot of old tutorials appear to have disappeared due to offline sites. I'd be interested in trying to learn 68k asm together, if you're interested in changing thoughts/ideas/etc. Anyway, good luck!

EDIT: So yea, the $ROM_CALL(a5) takes the address pointed to by a5 as the offset (so the address that $C8 points to). AaronTheGreat recommended technoplaza (http://www.technoplaza.net/assembly/lesson1.php) to me, which is the first tutorial i've found which really explains things well for someone who is just starting and has no idea about the entirely different syntax from the z80. It's not very long, but maybe worthwhile checking out.
Title: Re: 68K ASM Help
Post by: Xeda112358 on January 09, 2012, 01:14:07 am
Wow, thank you much! And I am okay with sharing what I learn, but I may be the weaker individual, so you may be doing most of the sharing :/ Also, I know a little french, so some of the french documentation might help me. I have never had to read any technical stuff in french, though.
Title: Re: 68K ASM Help
Post by: chickendude on January 09, 2012, 01:44:36 am
Here's (a very short) one i found, in French:
http://www.squalenet.net/fr/ti/tutorial_asm/

Kevin Koffler also wrote a guide, in French, but it looks like they translated it to English:
http://members.chello.at/gerhard.kofler/kevin/ti89prog/asmnstb.htm

And "ZGuide" appears to have been popular, too. I haven't looked through it yet though.
http://www.ticalc.org/archives/files/fileinfo/59/5957.html

Also, i stumbled across this, for the Atari ST:
http://atariste.free.fr/asm/assembleur.html

Ticalc has a couple more:
http://www.ticalc.org/pub/text/68k/

Finding a comprehensive ASSEMBLY tutorial seems to be a bit complicated, probably because of TIGCC. I'm sure there are some books out there, though. There's also an 89 version of Phoenix ;)
Title: Re: 68K ASM Help
Post by: Xeda112358 on January 09, 2012, 02:00:58 am
This has so far been very helpful, thanks! I wonder what my first program should be... maybe a bouncing thing or pong? Thank you much for your help so far!
Title: Re: 68K ASM Help
Post by: Jim Bauwens on January 09, 2012, 03:41:27 am
What about grammer for the 68k :D
Title: Re: 68K ASM Help
Post by: chickendude on January 09, 2012, 05:32:32 am
This has so far been very helpful, thanks! I wonder what my first program should be... maybe a bouncing thing or pong? Thank you much for your help so far!
What? No Hello World?! And what about the little dot that moves around the screen? Also, the 89's LCD is like the 86's, right? In that you don't have to send data to a port to update, just an address in memory? You could make a grayscale pong ;)

Btw, what do people use to emulate the 89? TiEmu?

EDIT: Oh, and i've also learned quite a bit, so thanks for bringing this discussion up. There's a few boards at yAronet which have (well, had :/) a lot of discussion on 68k asm programming, it might be fun to look through their old programming help archives. A lot of really knowledgeable people post(ed) there, you'll probably recognize a few of their names from games you've played. :)

EDIT2: If you don't have it already, you might want to check out TIGCC. I've read that all the ROM CALLS are documented there.
Title: Re: 68K ASM Help
Post by: Xeda112358 on January 09, 2012, 10:51:03 am
What about grammer for the 68k :D
That is one thing I was thinking of, but I am trying to figure out if I should. TI-89 BASIC is pretty powerful as it is.
Also, the 89's LCD is like the 86's, right? In that you don't have to send data to a port to update, just an address in memory? You could make a grayscale pong ;)
That is what I want to do :D And yes, the LCD is mapped to RAM, so it should make grayscale fairly easy :)
Btw, what do people use to emulate the 89? TiEmu?
I've no clue o.o TiEmu is the one recommended on Technoplaza.
EDIT: Oh, and i've also learned quite a bit, so thanks for bringing this discussion up. There's a few boards at yAronet which have (well, had :/) a lot of discussion on 68k asm programming, it might be fun to look through their old programming help archives. A lot of really knowledgeable people post(ed) there, you'll probably recognize a few of their names from games you've played. :)
Cool! I will poke around there :)
EDIT2: If you don't have it already, you might want to check out TIGCC. I've read that all the ROM CALLS are documented there.
Yeah, I think I should do that. I have not done it yet :/
Title: Re: 68K ASM Help
Post by: TIfanx1999 on January 09, 2012, 11:07:11 am
As far as emulation is concerned I'd ask Ranman or AaroneousTheGreat, or either of the Bauwen brothers. I'm not sure what the popular emulator is for the 68k series. 68k ASM would be interesting. Whenever I tried learning in the past though it seemed hard to find decent information, even back then. :/
Title: Re: 68K ASM Help
Post by: Xeda112358 on January 09, 2012, 11:19:01 am
Yeah, I am searching sites like UTI that have a section for z80 and 68k assembly, but I have found almost nothing :( Oh well, maybe chickendude and I can bring life back to 68k Asm development :)
Title: Re: 68K ASM Help
Post by: TIfanx1999 on January 09, 2012, 11:20:26 am
You guys would like totally be my heroes. :D
Title: Re: 68K ASM Help
Post by: Xeda112358 on January 09, 2012, 11:22:34 am
I am already learning a decent amount, I think and since I learned z80 hex in terms of TI-BASIC, then z80 mnemonics using z80 hex and now M68k in z80 terms, I think I can break it all down to BASIC :D Maybe I can help folks, too, but this technoplaza link is really good for me :)

EDIT: Okay, so for now I have been learning C for the TI-89 instead. It was really easy to download and install TIGCC and TiEmu and that really helped a lot. I got excited with it, so I made a program to draw inverted lines whos endpoints bounce around the screen at different speeds. It is 299 bytes on calc, so I think that is a decent size.

Spoiler For Spoiler:
#include <tigcclib.h>

void _main(void) {
    void *kbq = kbd_queue();
    int x, y, c, d, a, b, e, f, key;
    x=y=key=a=b=0;
    c=1;
    d=2;
    e=3;
    f=2;
    clrscr();
    while (key != 263) {
        DrawLine(x,y,a,b,A_XOR);
        x=x+c;
        y=y+d;
        a=a+e;
        b=b+f;
        if (x==0) {
          c=-c;
        }
        if (x>149) {
          c=-c;
        }
        if (y==0) {
          d=-d;
        }
        if (y>89) {
          d=-d;
        }
        if (a==0) {
          e=-e;
        }
        if (a > 149) {
          e=-e;
        }
        if (b==0) {
          f=-f;
        }
        if (b > 89) {
          f=-f;
        }
        OSdequeue(&key, kbq);
    }
}
Title: Re: 68K ASM Help
Post by: chickendude on January 11, 2012, 05:35:35 am
When i get some free time i'm gonna spend a couple evenings trying to wet my feet in 68k asm. I'm not entirely sure what the difference between the normal registers and the address registers are (i know a7 is reserved for the stack). Have you started your pong game yet? :D I was thinking of doing a 68k version of my old prgmBAD game i made like.. 10 years ago:
http://www.ticalc.org/archives/files/fileinfo/267/26730.html
Xeda, it was also ported in C to the 89, maybe you would be interested in the source ;)
http://www.ticalc.org/archives/files/fileinfo/240/24065.html
Title: Re: 68K ASM Help
Post by: Xeda112358 on January 11, 2012, 09:56:35 am
There are data registers and address registers, from what I see. pretty much, traditionally the D registers contain data for intermediary operations whereas the A registers contain addresses to calls, jump tables, et cetera. A7 is indeed the stack and A6 is the stack frame (I do not understand what a "stack frame" is).

So if I was going to make a routine to multiply two, 96-bit numbers, I would use D0D1D3 for the first number and D4D5D6 for the second. Or, if it was stored in memory (the two numbers), I would store the location of the numbers in A0 and A1 and the output location in A2.
Title: Re: 68K ASM Help
Post by: Lionel Debroux on January 31, 2012, 02:01:40 am
Maybe a bit of necroposting here, but I don't attend this section very often... now that there seem to be several TI-68k programmers, I should attend the C and ASM help sections more often :)

There are two emulators for TI-68k calculators: VTI and TIEmu. TIEmu supports the V200 and 89T, it's more accurate and more complete than VTI is, and has a native Linux version - but conversely, it's more heavyweight :)
As mentioned in another topic, TIGCC is unmaintained for practical purposes. Its la(te)st release was made more than five years ago, and even bugfixes for 10-year-old crasher bugs are not backported from GCC4TI - let alone optimizations, new functions (ROM_CALLs and others), portability improvements, etc.
GCC4TI is still maintained, though the latest release was made more than two years and a half ago.

The Technoplaza tutorials are said to be good, indeed.

Quote
So if I was going to make a routine to multiply two, 96-bit numbers, I would use D0D1D3 for the first number and D4D5D6 for the second. Or, if it was stored in memory (the two numbers), I would store the location of the numbers in A0 and A1 and the output location in A2.
Why not d0-d2 for the first number, and d3-d5 for the second ? :)
In pure ASM, you can use the former calling convention; however, if you want to use such routines from C code, you'd have to use the second one: memory operands.
Title: Re: 68K ASM Help
Post by: chickendude on January 31, 2012, 07:55:07 am
While we've got you here, do you know of any good books for learning m68k asm, in French or English?
Title: Re: 68K ASM Help
Post by: Lionel Debroux on January 31, 2012, 08:17:30 am
I don't know of any books besides the reference manual (M68000PRM) and user manual (68000UM or equivalent).
I take it that you're looking for information which is neither in TI-68k tutorials, nor in GCC4TI's documentation, nor in the reference manuals... but what type of information is it ? :)

In the sibling topic at Cemetech ( http://cemetech.net/forum/viewtopic.php?t=7249 ), I linked to GoldenCrystal's (from yAronet) a quick reference card for the 68000 opcodes: http://bit.ly/M68kOpcodes .
Title: Re: 68K ASM Help
Post by: Xeda112358 on January 31, 2012, 08:25:46 am
I have TI-Emu and TIGCC, but they seemed to cause some conflicts with a few other programs (Wabbit seemed to get buggy, but that may have been fixed). TIGCC has an issue where if I get any warnings or errors, it uses up all of my system resources available (so it makes my computer lag), and I have to press F10 about 5 times and click okay for each pop up error :/ And if I click outside the IDE, it does this too.
Title: Re: 68K ASM Help
Post by: Lionel Debroux on January 31, 2012, 08:29:20 am
Which OS (flavor and version) is your computer running ?
Title: Re: 68K ASM Help
Post by: Xeda112358 on January 31, 2012, 08:31:55 am
Windows 7 (64-bit)
Title: Re: 68K ASM Help
Post by: Lionel Debroux on January 31, 2012, 08:37:52 am
There haven't been many changes in the IDE, but well, as the maintainer of GCC4TI, I can only suggest switching to GCC4TI, instead of sticking to the unmaintained 5-year-old TIGCC ;)
Title: Re: 68K ASM Help
Post by: Xeda112358 on January 31, 2012, 08:38:43 am
Yes, I have now downloaded GCC4TI :) Thanks!
Title: Re: 68K ASM Help
Post by: chickendude on January 31, 2012, 08:51:02 am
I mean books that introduce you to good programming practices for 68k asm, for the z80 there are tons (http://www.z80.info/z80books.htm), it seems that the 68k isn't quite as accessible as the z80.
Title: Re: 68K ASM Help
Post by: Lionel Debroux on January 31, 2012, 09:03:48 am
Does "good programming practices", in your mind, encompass optimization tips and tricks ?
I'm asking because optimization isn't necessarily considered good practice, as it has / can have negative impact on portability, maintainability, reusability, etc. :)
Title: Re: 68K ASM Help
Post by: chickendude on January 31, 2012, 09:16:12 am
Basically how to program/organize your code, an introduction to programming under the 68k, like the tutorials but more in-depth/more complete. Anyway, it's not a big deal, i'll play with what i've got, check out the documentation/source i can find, and see where to go from there :)
Title: Re: 68K ASM Help
Post by: Lionel Debroux on January 31, 2012, 09:34:25 am
Quote
Basically how to program/organize your code (snip) like the tutorials but more in-depth/more complete
For this part, software engineering books focusing on C programming (therefore, probably old books, as newer books tend to focus on C++ or Java) may do the job. I believe that the 68000 ASM was designed with C programming in mind. For instance, instructions such as lea and pea, or the fact that mem |= operand, mem &= operand , mem ^= operand can often be translated to a single instruction.

Software engineering books can contain advice such as, but not limited to:
* limiting the size of functions to one/several screens: in ASM, one line contains much less information than in C, so functions can become large monsters even more easily;
* splitting the code across multiple source files (grouped by family of functions, etc.): 4000-line source files are bad, I can tell you :D
* inlining trivial computations unless it blows size up too much.


There are few higher-level constructs usable in pure ASM, but one which really should be used, if applicable, are macros. Failing to do so, even in the presence of multiple files which share some common code, increases bugginess and reduces maintainability (due to copy, paste and forget to modify all occurrences) - that's a real problem with ExtGraph :)
Title: Re: 68K ASM Help
Post by: chickendude on February 01, 2012, 06:24:53 pm
I've been playing a little with 68k assembly and to be honest i like the A68k format better than the GNU one (it reminds me more of z80, i don't need to precede registers with %, hex numbers start with $, etc.). What are the reasons for using the GNU one? I remember reading in the GCC4TI documentation that the A68k assembler was included just for compatibility...

EDIT: Also, for the A68k i see the "dc.b" directive to insert bytes into the program (like dc.b "Hello World",0). The GNU assembler has the .string directive, which i think automatically adds a 0 to the end. Is there another way to insert a string of characters? What if i don't want the string to end in a 0? The .byte directive doesn't seem to like the string format. Thanks again!

EDIT2: Found this: http://tigcc.ticalc.org/doc/gnuasm.html#SEC67 :)

EDIT3: Another question:
Is there a difference between "movea.l 4*ClrScr(%a5),%a0" and "move.l 4*ClrScr(%a5),%a0"? Or does the assembler simply convert the move.l into a movea.l?
Title: Re: 68K ASM Help
Post by: Lionel Debroux on February 02, 2012, 01:30:47 am
A68k has quite a few bugs, such as trying to do something (wrong) with the invalid "moveq.w"; and its output format is AmigaOS object files, which are not supported by the BFD (foundation of GNU binutils). This is one of the reasons why TIGCC/GCC4TI have a specific linker.
For GNU as to accept a syntax closer to that of A68k, try the --register-prefix-optional and --mri-compat switches :)

For strings in GNU as, there's .ascii and .asciiz, indeed.

IIRC / AFAICT, move and movea are the same instruction, see the 68000 Programmers Reference Manual and the quick cheat sheet at http://bit.ly/M68kOpcodes :)
Title: Re: 68K ASM Help
Post by: chickendude on February 02, 2012, 06:38:05 am
The --register-prefix-optional switch works great, but the --mri-compat switch isn't recognized. Ah! It looks like it's just --mri. Thanks :)