Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: bored_student on November 04, 2012, 01:51:33 pm

Title: Some basic questions
Post by: bored_student on November 04, 2012, 01:51:33 pm
Yeah I decided to learn ASM so I have read a lot but some questions still remained:  ???
1. What compiler/assembler should I use
  TI recommens the ZDS but I think it's a bit environment and I only need a compiler with documentation
2. Since the code depends on the compiler I need some documentation (not the TI hardware and routines guides
  but the basic commands like "call" or "ld"
3. Some questions that will appear when I start making my first errors :(
Title: Re: Some basic questions
Post by: Deep Toaster on November 04, 2012, 02:03:54 pm
Try this: http://www.ticalc.org/archives/files/fileinfo/268/26877.html

It's a really great tutorial and walks you through step-by-step. You can also access it online at http://eeems.omnimaga.org/files/Resources/Tutorials/ASMin28Days/lesson/toc.html (http://eeems.omnimaga.org/files/Resources/Tutorials/ASMin28Days/lesson/toc.html).

It recommends TASM but I personally prefer Spasm (http://wabbit.codeplex.com/releases/view/45088), which was designed for the TI-83 Plus series. Some syntax may be different from that of TASM, however. (Or if you prefer online tools you can try my own ORG IDE (http://clrhome.org/asm/) ;D)
Title: Re: Some basic questions
Post by: DJ Omnimaga on November 04, 2012, 02:15:46 pm
There is also MImas if you absolutely want to program on the calculator directly, but you must be careful with data loss and limited memory.

By the way Does Spasm have that feature TIGCC had with TiEmu which automatically launched the calculator emulator (if installed) and then the calc program just by pressing Compile/test/whatever is available in Spasm? That was kinda cool in TIGCC (although it only worked with certain calculator OSes so if you had the wrong one it just sent the files to the emulator but did not launch them)
Title: Re: Some basic questions
Post by: chickendude on November 04, 2012, 03:32:35 pm
WabbitCode (for Windows) does, or if you're on Linux you can make a simple script to compile with spasm then launch TilEm2. And yes, i also would recommend spasm. There's also Brass which some people (mainly Kerm i think) still use, though Spencer always boasted that spasm was faster. Spasm can also compile into a bunch of different formats, including applications. Though if you want to do nostub (ie uncompressed/hex) 83 games, you'll need another program (bin2hex or something along those lines).
Title: Re: Some basic questions
Post by: thepenguin77 on November 04, 2012, 07:18:20 pm
Try this: http://www.ticalc.org/archives/files/fileinfo/268/26877.html

It's a really great tutorial and walks you through step-by-step. You can also access it online at http://eeems.omnimaga.org/files/Resources/Tutorials/ASMin28Days/lesson/toc.html (http://eeems.omnimaga.org/files/Resources/Tutorials/ASMin28Days/lesson/toc.html).

It recommends TASM but I personally prefer Spasm (http://wabbit.codeplex.com/releases/view/45088), which was designed for the TI-83 Plus series. Some syntax may be different from that of TASM, however. (Or if you prefer online tools you can try my own ORG IDE (http://clrhome.org/asm/) ;D)

I completely agree. I learned with 28 days (and still reference it from time to time) and currently use spasm as my assembler.

If you also decide to go with this setup, this is what needs to go in your asm.bat file that you make on the first day. This is because spasm has a different command line syntax than tasm:
Code: [Select]
@echo off
copy c:\asm\source\%1.z80 %1.z80 > nul
spasm %1.z80 c:\asm\exec\%1.8xp
del %1.z80 > nul
time /T
Don't worry about that "time /T", that will help you keep your sanity later on. (Actually, don't worry about what any of it means, this is one of the hardest steps in learning to program for the 83/84.)
Title: Re: Some basic questions
Post by: bored_student on November 06, 2012, 07:50:32 am
I think SPASM is what I will use.
But is there any readme or something to learn how to use it?

If you also decide to go with this setup, this is what needs to go in your asm.bat file that you make on the first day. This is because spasm has a different command line syntax than tasm:

to be honest I don't really know what this code does and where to put it.
(I have only small experience with batch code)
Title: Re: Some basic questions
Post by: chickendude on November 06, 2012, 08:57:46 am
Check out the documentation:
http://wabbit.codeplex.com/documentation
Title: Re: Some basic questions
Post by: thepenguin77 on November 06, 2012, 11:04:53 am
I think SPASM is what I will use.
But is there any readme or something to learn how to use it?

If you also decide to go with this setup, this is what needs to go in your asm.bat file that you make on the first day. This is because spasm has a different command line syntax than tasm:

to be honest I don't really know what this code does and where to put it.
(I have only small experience with batch code)

Ok, to be honest, if you aren't very good with batch files, now is not the time to learn. All you need to do is to have a setup that works. The same goes for spasm. All you need is the ability to use it, you don't need to worry about how it works (yet).


So, to help you out, take this .zip file, extract it, and copy it to C:\. That way you have C:\asm\ already set up.

Then, as you go through the first day, you can just laugh at the instructions because you've already done them.
Title: Re: Some basic questions
Post by: bored_student on November 06, 2012, 11:45:01 am
Shouldn't be the SPASM.EXE in the 'tasm' directory
Title: Re: Some basic questions
Post by: thepenguin77 on November 06, 2012, 05:39:35 pm
Oops, forgot to include that. Yes
Title: Re: Some basic questions
Post by: bored_student on November 07, 2012, 06:12:44 am
a explanation in the tutorial Deep Thought gave me says:
http://eeems.omnimaga.org/files/Resources/Tutorials/ASMin28Days/lesson/day02.html (http://eeems.omnimaga.org/files/Resources/Tutorials/ASMin28Days/lesson/day02.html)

Quote
.org number    Specifies where in memory the program is loaded into (not exactly true), which is always $9D95.

Why is it always $9D95?
I mean if there is stored something other this "other" will be overwritten by the program code.

Deep Thought also mentioned this location in his SMC tutorial:
http://www.omnimaga.org/index.php?action=articles;sa=view;article=91 (http://www.omnimaga.org/index.php?action=articles;sa=view;article=91)
Quote
You also know the absolute location of the start of the program (it's E9D93).

Title: Re: Some basic questions
Post by: aeTIos on November 07, 2012, 06:15:01 am
It is always $9D95 because there's where the free RAM for programs starts (I think...)
Title: Re: Some basic questions
Post by: bored_student on November 07, 2012, 06:21:56 am
I always thought the memory management on the TI 83 Plus is dynamic so that the data is stored somewhere where you have free RAM  <_<
Title: Re: Some basic questions
Post by: aeTIos on November 07, 2012, 06:23:02 am
Could also be. I'm not really knowledgeable on this part.
Title: Re: Some basic questions
Post by: Deep Toaster on November 07, 2012, 09:36:17 am
Yes, the memory management system is dynamic, but assembly programs are always moved to $9D95 before they're run. Variables are shifted around so that the the program ends up there.

It's actually moved to $9D93, but since there's a two-byte header of $BB,$6D, the program code starts at $9D95. Some people might put the .org statement before the two bytes, in which case it's be .org $9D93.

It makes absolute addressing easier because you know the beginning of the program is always there.
Title: Re: Some basic questions
Post by: DrDnar on November 07, 2012, 07:59:06 pm
The calculator does indeed use dynamic memory allocation for user data. And BASIC programs don't get moved before execution; the parser is able to parse BASIC programs from where ever they're located in memory. However, the Z80 CPU doesn't well-support doing that for assembly programs. In particular, the JP and CALL instructions have to know the exact location they're branching to before program execution begins. So the OS always copies assembly programs to the exact same location in RAM so that the assembler can always compute before hand the address to jump to.

In theory, you could have your program store a list of the locations of+ instructions in the program that need to be fiddled with before executing, but that's more complicated solution than anybody so far has been willing to deal with.
Title: Re: Some basic questions
Post by: chickendude on November 08, 2012, 12:16:04 am
Not to mention things like jump tables and SMC would be hard to implement.
Title: Re: Some basic questions
Post by: bored_student on November 08, 2012, 09:37:27 am
By the way:
  Is there a way to store the current value of the PC register somewhere else
Title: Re: Some basic questions
Post by: Eeems on November 08, 2012, 11:16:25 am
If I remember correctly you could do a push pc \ pop hl to store it in hl. You wouldn't want to leave it on the stack because on the next ret it would jump back to it.
If that doesn't work a little hack you could probably do would be
Code: [Select]
  call self
self:
  pop hl
Title: Re: Some basic questions
Post by: DrDnar on November 08, 2012, 02:12:15 pm
There is no "push pc". The "call $+3 \ pop hl" will work, though. (But just to reiterate, it's not relocatable, which probably isn't a problem for you.)
Title: Re: Some basic questions
Post by: bored_student on November 08, 2012, 02:28:11 pm
It is a problem for me because if I want to add some ASM Code in an Axe Programm with the Asm() command, I don't really know where the ASM code is stored.
Title: Re: Some basic questions
Post by: aeTIos on November 08, 2012, 02:30:28 pm
hmm well it depends on what you want to do with the code?
Title: Re: Some basic questions
Post by: thepenguin77 on November 08, 2012, 02:32:37 pm
Code: [Select]
ld hl, $E9E1 ;pop hl \ jp (hl)
ld (appBackUpScreen), hl
call appBackUpScreen
here:

This returns with HL = here.


Edit:
   optimized a little


Edit2:
    Here are two other options (with runer's help)

Fastest version:
Code: [Select]
di
call $000F
here:
dec sp
dec sp
pop hl

Smallest version: (destroys BC and DE)
Code: [Select]
di
rst 20h
here:
dec sp
dec sp
pop hl
Title: Re: Some basic questions
Post by: DrDnar on November 08, 2012, 07:30:32 pm
It is a problem for me because if I want to add some ASM Code in an Axe Programm with the Asm() command, I don't really know where the ASM code is stored.
In that case, you may want to use an Axiom, since the Axe Axiom parser supports resolving jump references. (More information is in the SDK. The Axe Parser will parse the Axiom's bytestream so it can identify jumps and calls that need references resolved.) If you want to make Axioms on-calc, you can actually just use Mimas (http://www.ticalc.org/archives/files/fileinfo/431/43140.html). It doesn't support the standard helper macro used for Axiom jump resolution, but there's an easy enough workaround you can use instead.
Title: Re: Some basic questions
Post by: Eeems on November 08, 2012, 08:34:33 pm
There is no "push pc". The "call $+3 \ pop hl" will work, though. (But just to reiterate, it's not relocatable, which probably isn't a problem for you.)
I had thought so, I just couldn't quite remember.
Title: Re: Some basic questions
Post by: aeTIos on November 09, 2012, 05:14:28 am
I agree with DrDnar. Axioms are the best!