Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: matthias1992 on July 11, 2010, 07:22:45 am

Title: Coding ASM by hand
Post by: matthias1992 on July 11, 2010, 07:22:45 am
EDIT2: Seemingly my explanation is not really comprehensible because this topic has been viewed alot but 0 downloads so far...
or: is there simply no intrest in this? tell me!

One of the most difficult aspects of asm is its final output. it is just a sheer list of hexadecimal characters. There are some on calc converters that allow you to write ASM but they compile slow and are slow to write in unless you can type blindfolded on your calc. I never tried to code directly in hex but yesterday was my first try and it went suprisingly good! One problem was in looking up all the hexadecimal codes for the commands (i try to avoid bcalls altough they are pretty easy in hex).

So I wrote a program that could look up commands for me. Currently I have a 382 byte string that contains the first 20 commands of TASM80.TAB
It works as follows. It looks up the command in str0 and outputs the correct hex format. BCALL's are yet unsupported since the hex digits are swapped and well..I just ahve not included that yet. If one were to include all the commands into str0 (no bcalls, only the commands) it would take up about 6KB. However not every command is really needed/ a lot used so currently I am writing a Limited instruction set into str0 that has all the basic asm commands. If you however wanted to add a command you'd only need to typ '^' into MASM (that is what my program is called).

Well enough talk lets get down to the action:
Before you boot up make sure you have string 0 declared, if you don't use the supplied string in the attachments just store something like ":" to it.'

As you boot up MASM you get a Command Line Interface (that is a pretty glamourous description of the Input command but enver mind). You can do 4 things from here.

Q              | quits
C              | clears string0
^              | Add a command to the library
[command] | outputs the hexadecimal code for [command]

Q and C are pretty obvious but '^' isnt. Whenever you add a command you are prompted 'C:' and 'H:'.  Make sure you open up TASM80.TAB or something else, just don't make mistakes in the input...some errors are catched but a wrong hexadecimal code might eventually crash your calculator.

C: [type number here][type command here]
H: [type hex equivalent here. lenght of this must be equal to "[type number here]"]

the command is now added to the library (aka string0)
lets for example add the command EX DE,HL

Tasm80.tab says this: EX   DE,HL   EB   1 NOP 1

There are two ways to deduce the number you need to type BEFORE the command. 1 way is to multiply the number BEFORE "NOP" (or ZIX sometimes) by 2. In this case 1*2 = 2 so the number would be 2. The second method is to look at the hex-code. in this case EB = 2 characters long. I highly recommend the first method because sometimes with commands with * in it (which means something like: fill in the blanks with a hexadecimal code of a number).Now we type the command:

C:2EX DE,HL

hit [ENTER]

then the hex equivalent:

H:EB

hit [ENTER]

So now the command EX DE,HL is added to the library. We can now recall the hex code for it by typing:

EX DE,HL

which will print

EB

BCALLS use the following syntax:

EF[last two digits][first two digits]

ClrLCDFull for example = 4540h

in hex that would be:

EF4045

This program is to be a digital replacement for TI83PLUS.INC (not yet) and TASM80.tab
I consider making an app out of it eventually to avoid the use of str0. For the moment however this program must be seen as a quick and easy lookup for Z80 commands.

Feedback and critique are welcome but just remember this is a unoptimized, pre-alpha and around midnight created program which lacks optimization.

EDIT: I think AXE is just perfect for this. it allows to insert large amounts of data without using user ram and it allows me to output to an app. I think I'll have to learn axe then....
Title: Re: Coding ASM by hand
Post by: DJ Omnimaga on July 11, 2010, 12:46:16 pm
I am confused at what is the purpose of this program. Do you just type an hex code then it converts to z80 ASM code? The explanation was a bit TL;DR so I skimmed through it :S

It would be nice to be able to easily convert z80 to hex or vice-versa, command by command, if possible, for easier insertion in Axe or Omnicalc stuff
Title: Re: Coding ASM by hand
Post by: calcdude84se on July 11, 2010, 05:07:59 pm
So, what I get of this: (correct me if I'm wrong)
You're trying to write a pure BASIC program that functions as a quick way to look up the hex for a command so you can code ASM on-calc. (Or are you trying to write a compiler?) You're considering making it in Axe.
And what I have to say:
That sounds interesting. I took the approach of just printing off the hex corresponding to each command, but it sounds like you want it entirely on-calc.
As for bcalls, little-endianness (this is what the phenomenon you're referring to is called) is an inherent property of the z80, and this is true for all commands like "ld hl,nn" or "ld (nn),a", basically any command where a two-byte number is directly in the code.

Whatever you're trying to do, good luck! ;D
Title: Re: Coding ASM by hand
Post by: matthias1992 on July 11, 2010, 05:53:38 pm
you input z80 asm and you get hex codes. Next step is to make a fully functional and automatic compiler. I need that tutorial on Axe really...
Title: Re: Coding ASM by hand
Post by: calcdude84se on July 11, 2010, 06:19:08 pm
ah, okay. So you're going to write something like the OTBP assembler in the end?
(At this point you'll want to use Axe, and then we'll eventually have on-calc ASM compilers in three languages: OTBP in basic, MASM in Axe, and Mosaic in ASM. That'll be awesome! :D)
Title: Re: Coding ASM by hand
Post by: TC01 on July 11, 2010, 06:26:19 pm
ah, okay. So you're going to write something like the OTBP assembler in the end?
(At this point you'll want to use Axe, and then we'll eventually have on-calc ASM compilers in three languages: OTBP in basic, MASM in Axe, and Mosaic in ASM. That'll be awesome! :D)

And Tasm_on_calc (http://www.ticalc.org/archives/files/fileinfo/384/38467.html) and Chasm (http://www.ticalc.org/archives/files/fileinfo/261/26101.html), among others... They look like they're written in assembly (that is, from their file category on ticalc.org), but I took a look at the Tasm_on_calc source once and it appears to be Basic with random assembly mixed in. Whereas ChAsm is definitely assembly.
Title: Re: Coding ASM by hand
Post by: calcdude84se on July 11, 2010, 06:32:37 pm
Sorry, I never heard of those... Unfortunately, though, Chasm was never completed (and jr and djnz are, at least IMO, very important and necessary). I will look at Tasm_on_calc though, since it seems to be about equal to OTBP.
Title: Re: Coding ASM by hand
Post by: TC01 on July 11, 2010, 06:56:01 pm
Sorry, I never heard of those... Unfortunately, though, Chasm was never completed (and jr and djnz are, at least IMO, very important and necessary). I will look at Tasm_on_calc though, since it seems to be about equal to OTBP.
Hmm, it looks like Tasm_on_calc doesn't support relative addressing either.

So OTBP Assembler appears to be the best on-calc assembler currently available.
Title: Re: Coding ASM by hand
Post by: DJ Omnimaga on July 11, 2010, 07:37:07 pm
So this is written in Axe?

That said, I would like such program since it's annoying when you know ASM to have to compile in 8xp, upload to Galandros unsquisher site then figure out what hex to keep and what not.
Title: Re: Coding ASM by hand
Post by: calcdude84se on July 11, 2010, 07:40:52 pm
No, it's currently written in BASIC, but he wants to have it in Axe instead.
My statements of the possible awesomeness of this assume he will do it in Axe. ;D
Title: Re: Coding ASM by hand
Post by: DJ Omnimaga on July 11, 2010, 07:48:50 pm
Oooh ok ^^
Title: Re: Coding ASM by hand
Post by: TIfanx1999 on July 12, 2010, 08:03:43 am
I always check new stuff, and this does certainly seem to be an interesting endeavor. However, I do not code in ASM, thus there is no reason for me to download it. It'll be cool to see it in action once you get it to a more useable state. ^^
Title: Re: Coding ASM by hand
Post by: matthias1992 on July 12, 2010, 09:27:14 am
I used tasm_on_calc which inspired me to do this but it is slow and has some bugs. Also coding in the basic editor goes slow and you easily make mistakes. If i could only figure out how to insert tokens...
Title: Re: Coding ASM by hand
Post by: Deep Toaster on July 18, 2010, 11:06:26 pm
Yeah, IMO OTBP is better than Tasm_on_Calc. I don't think the second ever got finished, and it's slower to program in (you have to add brackets to commands), and it compiles slower, too.

Can't wait for Mosaic (or this, too) :P
Title: Re: Coding ASM by hand
Post by: DJ Omnimaga on July 18, 2010, 11:14:16 pm
I also remember something called Mon, but it was very slow as well. I think it took 2 minutes to compile Hello World x.x
Title: Re: Coding ASM by hand
Post by: Galandros on July 23, 2010, 09:40:16 am
Interesting. There is even an active programmer in assembly by hand with several releases in ticalc.
It is curious to see people write assembly in hex instead of memnomics.

Personally I stick in doing assembly with an computer assembler and emulator. It is much safer and fewer constraints in comments, labels, macros and other tools. Mosaic will replace the oncalc assemblers.
Title: Re: Coding ASM by hand
Post by: matthias1992 on November 17, 2010, 06:58:39 am
The battle is really on between Mosaic and Mimas but since Mimas is already 'out there' and Mosiac (as far as I know) isn't Mimas is right now the best way to go...

Looking back on this the program I wrote wasn't really that usefull it was intended to be a digital lookup file so you could type the command and it would spit out the hex command for it...
pretty useless and even more useless seeing what Mimas can do. I recommend anybody who was initially interested in this to download Mimas or wait for Mosaic to come out
Title: Re: Coding ASM by hand
Post by: DJ Omnimaga on November 17, 2010, 02:11:32 pm
It still seemed quite cool, though, for those who wanted to code ASM in the BASIC editor. By the way, Xeda codes in hex directly. ;D
Title: Re: Coding ASM by hand
Post by: Builderboy on November 17, 2010, 02:13:37 pm
By the way, Xeda codes in hex directly. ;D

Like a boss

I still think programs like this are useful, and also very cool :)
Title: Re: Coding ASM by hand
Post by: DJ Omnimaga on November 17, 2010, 02:15:16 pm
Another thing is that it can make it easy to grab hex code fast for use in Axe games (with Asm() or Omnicalc/Celtic/DCS7 ExecASM)
Title: Re: Coding ASM by hand
Post by: Xeda112358 on November 17, 2010, 02:16:09 pm
Yes! And it is quite amazing once you get the hang of it. It will be very easy to do once you have done it long enough. It took me a few months before I could program anything major without the aid of a chart or the SDK or other references, though. I still need to check up on B_Calls and RAM addresses occasionally, though. Plus, counting bytes becomes pretty easy when you realize there are 8 bytes to a line...

And you get a pretty intimate knowledge of assembly when you learn all the hex...
Title: Re: Coding ASM by hand
Post by: DJ Omnimaga on November 17, 2010, 02:21:31 pm
One good thing with ASM is that there aren't as many instructions to remember as in Axe or BASIC, so that helps remembering hex codes for each instructions.

I guess it's good to not put the entire code into one single line, though, else it can be hard to read and if you accidentally press CLEAR on 12 KB of hex code...
Title: Re: Coding ASM by hand
Post by: Xeda112358 on November 17, 2010, 02:23:15 pm
Yeah, that has been a problem for me in the past. I usually put one call to a line or one section to a line... So pressing clear sucks if I never copied down the code elsewhere...
Title: Re: Coding ASM by hand
Post by: DJ Omnimaga on November 17, 2010, 02:26:38 pm
The only annoying thing with splitting code in multiple lines is the much longer scrolling time through the code. But I think it's best to take the extra 20 seconds to scroll down the code instead of risking losing 8 hours of work due to an accidental CLEAR press.
Title: Re: Coding ASM by hand
Post by: Builderboy on November 17, 2010, 02:29:47 pm
Do hex programs allow for newlines?  Or do you have to erase them before you compile?
Title: Re: Coding ASM by hand
Post by: Xeda112358 on November 17, 2010, 02:31:14 pm
You can use newlines, it makes it much easier to organise code.
Title: Re: Coding ASM by hand
Post by: DJ Omnimaga on November 17, 2010, 02:31:42 pm
I swear I typed an hex program with linebreaks once

EDIT: Ninja'd
Title: Re: Coding ASM by hand
Post by: Xeda112358 on November 17, 2010, 02:32:45 pm
Well, you can not split bytes... You have to keep an even number of hex digits on each line, but otherwise, it is fine.
Title: Re: Coding ASM by hand
Post by: Builderboy on November 17, 2010, 02:33:24 pm
Ah gotcha, yeah i can imagine O.O Too bad there arn't such things as comments.  I would get lost in the sea of HEX x.x I give no end of props to you for coding in hex ;D
Title: Re: Coding ASM by hand
Post by: Xeda112358 on November 17, 2010, 02:35:29 pm
Well, I was thinking about making a program that worked like AsmComp(, but it would let you use labels and notes, but I am working on a few other programs at the moment...
But maybe soon...
It won't be too difficult, but it would only be useful to a few people...

And I would obviously provide the opcode :D

*Also, now that I have a computer, I can plan out my codes in a text document
Title: Re: Coding ASM by hand
Post by: DJ Omnimaga on November 17, 2010, 02:38:16 pm
Well, you can not split bytes... You have to keep an even number of hex digits on each line, but otherwise, it is fine.
Wait so if the first line has 4 bytes the rest must be 4 bytes each too? That sucks. X.x
Title: Re: Coding ASM by hand
Post by: Xeda112358 on November 17, 2010, 02:42:51 pm
Oh, no I just meant each line needs an even number of digits. You cannot use 5 digits on a line. My code right now for a routine looks like this:
Code: [Select]
AsmPrgm
211C00
011000

3E10110000
29EBED6AEBF57AB820027BB938052CEBED42EBF13D20E9

EBEF0745C9
Title: Re: Coding ASM by hand
Post by: DJ Omnimaga on November 17, 2010, 02:52:30 pm
Oh ok, I see what you mean now. I guess it's understandable since one byte is 2 hex digits.

EDIT: By the way what's the largest hex program you ever typed?
Title: Re: Coding ASM by hand
Post by: ztrumpet on November 17, 2010, 05:41:50 pm
This program looks neat. :)

Xeda, you're such a beast!  Mad props to you for doing it by hand, wow. ;D
Title: Re: Coding ASM by hand
Post by: Xeda112358 on November 17, 2010, 06:40:08 pm
My largest program... hang on lemme check (it is between EnPro and SpriteLib)
SpriteLib=1356 bytes
EnPro=1872 bytes

EnPro was completely on calc. For SpriteLib, I make use of the spreadsheet for the final product, but everything is programmed on the calc first.
Title: Re: Coding ASM by hand
Post by: Deep Toaster on November 17, 2010, 06:43:33 pm
Xeda, that is amazing. Hex programming is extremely hard, especially with the TI-BASIC editor. Do you keep comments and stuff on the side?
Title: Re: Coding ASM by hand
Post by: Xeda112358 on November 17, 2010, 06:50:39 pm
Whenever I make a call I usually add it to my .txt document that I keep for calls and routines, but I typically don't ever forget what snippets of code do. Every once in a while, when I convert my codes to mnemonics, I make thorough notes for every line.
Title: Re: Coding ASM by hand
Post by: Deep Toaster on November 17, 2010, 06:51:39 pm
Whenever I make a call I usually add it to my .txt document that I keep for calls and routines, but I typically don't ever forget what snippets of code do. Every once in a while, when I convert my codes to mnemonics, I make thorough notes for every line.

Wow. Do you use Calcsys to check the disassembly, at least?
Title: Re: Coding ASM by hand
Post by: Xeda112358 on November 17, 2010, 06:56:28 pm
Actually, the only time I used it was before I learned assembly with the hopes that I could learn that way. Numbers are easier for me to use. By the way, I am probably high functioning autistic, so I got pretty lucky and I have a form of synesthesia that connects with emotions, so numbers mean a lot to me. Those may be reasons for why I have such an affinity for hex programming.
Title: Re: Coding ASM by hand
Post by: DJ Omnimaga on November 18, 2010, 08:50:15 pm
My largest program... hang on lemme check (it is between EnPro and SpriteLib)
SpriteLib=1356 bytes
EnPro=1872 bytes

EnPro was completely on calc. For SpriteLib, I make use of the spreadsheet for the final product, but everything is programmed on the calc first.
Nice, I wonder how hard it is to write a game that way.
Title: Re: Coding ASM by hand
Post by: Xeda112358 on November 18, 2010, 08:54:37 pm
It depends on how complex it is. Unfortunately, I stopped making games over a year ago and I haven't had the creative juice for one since.
Title: Re: Coding ASM by hand
Post by: DJ Omnimaga on November 18, 2010, 08:55:35 pm
Starcraft. Phoenix.

Sorry to hear, though. :(