Author Topic: 68K ASM Help  (Read 14580 times)

0 Members and 1 Guest are viewing this topic.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
68K ASM Help
« 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!

Offline chickendude

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 817
  • Rating: +90/-1
  • Pro-Riot Squad
    • View Profile
Re: 68K ASM Help
« Reply #1 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 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.
« Last Edit: January 09, 2012, 01:03:04 am by chickendude »

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: 68K ASM Help
« Reply #2 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.

Offline chickendude

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 817
  • Rating: +90/-1
  • Pro-Riot Squad
    • View Profile
Re: 68K ASM Help
« Reply #3 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 ;)

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: 68K ASM Help
« Reply #4 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!

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: 68K ASM Help
« Reply #5 on: January 09, 2012, 03:41:27 am »
What about grammer for the 68k :D

Offline chickendude

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 817
  • Rating: +90/-1
  • Pro-Riot Squad
    • View Profile
Re: 68K ASM Help
« Reply #6 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.
« Last Edit: January 09, 2012, 05:38:19 am by chickendude »

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: 68K ASM Help
« Reply #7 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 :/

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: 68K ASM Help
« Reply #8 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. :/

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: 68K ASM Help
« Reply #9 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 :)

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: 68K ASM Help
« Reply #10 on: January 09, 2012, 11:20:26 am »
You guys would like totally be my heroes. :D

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: 68K ASM Help
« Reply #11 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);
    }
}

Offline chickendude

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 817
  • Rating: +90/-1
  • Pro-Riot Squad
    • View Profile
Re: 68K ASM Help
« Reply #12 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

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: 68K ASM Help
« Reply #13 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.

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: 68K ASM Help
« Reply #14 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.
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.