Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: Munchor on January 22, 2011, 09:02:57 am

Title: Hexadecimal Assembly Programming
Post by: Munchor on January 22, 2011, 09:02:57 am
I decided to create a topic for general discussion about general Hexadecimal Assembly programming. It is also a small tutorial and introduction.

What is hexadecimal?

Hexadecimal is a numeration system just like the Arabic one (1,2,3,4,5,6,7,8,9.5,11,12,...) or the Roman one (I,II,III,IV,V,X,L,MCM,...).
So, a number like seven can have multiple representations, according to the system used, let's check the number 28:

Code: [Select]
28          // Arabic
XXVIII    // Roman
1C        // Hexadecimal
11100  // Binary

So, why don't we all use the same? It's hard for all of us to use the same and some are useful in some situations but terrible in others. For example, to make a sprite we use binary or hexadecimal, but to solve a giant equation using any of those would be a pain in the ass!

Now, when we make a Calculator Assembly program (ld hl,1 ....), it is written as a binary file (10010101011110101010...). Binary is hard to read, so we just use Hexadecimal.

So, why don't we just program in Assembly and leave the Hexadecimal alone?

If we know how to code in Hexadecimal instead of using an assembler that makes our assembly code hexadecimal, we can program assembly on the calculator. Of course, with Mimas (and some others) we can also do it, and Mimas is quite good. However, I'm not sure if we can all use Mimas or if it has everything there is.

So, I assume you already know Assembly if you're reading this, and here's an Assembly program:

Code: [Select]
.nolist
#include "ti83plus.inc"
.list
    .org $9D95-2
    .db $BB, $6D

Start:
  B_CALL (_ClrLCDFull)
  ld hl,1
  B_CALL (_DispHL)
  B_CALL (_GetKey)
 
  ret

This program will Clear the Screen, the set the hl registers to 1, then display "1" and wait for a key press until ending.

The hexadecimal code it creates (the data) is something like:

Code: [Select]
EF4045  // ClrLCDFull
210100  // Set hl registers to 1
EF0745  // Display the hl registers, so display "1"
EF7249  // Wait for key press
C9

Now, how do I know this is the hexadecimal code for it? One, I checked the ti83plus.inc (http://education.ti.com/downloads/files/computer_software/sdk_83p/ti83plus.inc), I use Assemblex (http://ourl.ca/8517/166478;topicseen#new) and I learnt it with Xeda. Now, the ti83plus.inc has all the hexadecimal codes for BCalls. Assemblex converts hexadecimal to assembly and disassembles files which lets me learn it from other programs.

Also, for opcodes such as 210100, I check this (http://davidgom.co.cc/z80table.html) all the time!

How to program in my calculator?

Press PRGM
Create a new PRGM
Call it whatever you want
Then make it like this:

Code: [Select]
AsmPrgm
EF4045
EF7045 // Turns the run diagnostic off  B_CALL (_RunIndicOff)
FDCB00AE  // Disables the 'Done' message when the program closes (res 5,(iy+0))
210100
EF0745
EF7249
C9




Never forget the ending C9 (ret), without it the calculator crashes!

Now you can run that program by typing Asm(prgmNAME.

You can also compile it so you can run it in shells and it is a true Assembly program: AsmComp(prgmNAME,prgmNAME2)

Note, in AsmComp( the names have to be different. Also, press 2ND + 0 to access the catalog and use the Asm( and AsmPrgm and AsmComp( tokens, don't just type them.

I hope more discussion comes, for now, skim through the pages I gave you and try and make something new.

Note: The language on this tutorial may be wrong. For example, I said that AsmComp( made it a real Assembly program, but it was already, it just compiles it.

Also, concerning Assemblex, the last uploaded version is still not perfect, so you can have a demo here, but the 'Export to 8xp' isn't finished, so it does not count as an upload. Assemblex is what I use to program in Hexadecimal in my computer.

Discuss!

EDIT: You can also use brandonw's website for more bcalls and information, I think. The Z80 tables with opcodes can also be found in ticalc.org.


EDIT 2:
I have a lot to tell you yet, but for now, here's another program:

Code: [Select]
EF4045
3E01
C60A
2600
6F
EF0745
EF7249
EF4045
C9

Who guesses what this does?
Title: Re: Hexadecimal Assembly Programming
Post by: Binder News on January 22, 2011, 09:47:26 am
Very useful. Definite bookmark!
Title: Re: Hexadecimal Assembly Programming
Post by: Munchor on January 22, 2011, 01:40:08 pm
Very useful. Definite bookmark!

Thanks much!

I edited with another program ;D
Title: Re: Hexadecimal Assembly Programming
Post by: Xeda112358 on January 22, 2011, 01:50:28 pm
Want another chart I like to use?!? This is one I made after I learned assembly...
And I'm glad you're helping to spread the plague-- er, fun!
Title: Re: Hexadecimal Assembly Programming
Post by: Munchor on January 22, 2011, 02:23:42 pm
Nice chart Xeda! I really like the way it looks! You should check mine and get the unofficial instructions and the IX and IY tables. Also the IX bits and IY bits tables and put them in yours. I did not fully make all of those, though. Runer made two of those, I just don't remember which.
Title: Re: Hexadecimal Assembly Programming
Post by: holmes221b on January 22, 2011, 02:24:54 pm
What file type is xls? I don't recall ever seeing that one before.../me wants to download it to start teaching herself how to program in HEX, but isn't sure if it's in a format she can read
Title: Re: Hexadecimal Assembly Programming
Post by: FinaleTI on January 22, 2011, 02:26:01 pm
What file type is xls? I don't recall ever seeing that one before.../me wants to download it to start teaching herself how to program in HEX, but isn't sure if it's in a format she can read
It's an Excel spreadsheet, but I think it'll open in OpenOffice as well.
Title: Re: Hexadecimal Assembly Programming
Post by: Munchor on January 22, 2011, 02:26:22 pm
What file type is xls? I don't recall ever seeing that one before.../me wants to download it to start teaching herself how to program in HEX, but isn't sure if it's in a format she can read

It's Excel file, opened with Microsoft Excel, which can be either bought or used online for free in a limited way (Google Chrome+Hotmail Account).

www.davidgom.co.cc/z80table.html (http://www.davidgom.co.cc/z80table.html) The tables are also there, online.
Title: Re: Hexadecimal Assembly Programming
Post by: Xeda112358 on January 22, 2011, 02:29:15 pm
Yeah, I've checked yours... me likes :D
Oh, um, yeah, I made it with Open Office...
Title: Re: Hexadecimal Assembly Programming
Post by: holmes221b on January 22, 2011, 03:15:21 pm
Well, I do have Excell...It's been a long while since I've done anything in Excell, so no wonder I've forgotten the file extension...xD
Title: Re: Hexadecimal Assembly Programming
Post by: Munchor on January 22, 2011, 04:23:01 pm
Well, I do have Excell...It's been a long while since I've done anything in Excell, so no wonder I've forgotten the file extension...xD

Oh I see, Excel is quite useful for this kind of tables, though.

So, anybody already knows (not you, Xeda) what the final program of my code does?
Title: Re: Hexadecimal Assembly Programming
Post by: Xeda112358 on January 22, 2011, 05:57:51 pm
Pssh, that is SO unoptimised... :P
(but it is for an example, so I guess it's okay :D)
Title: Re: Hexadecimal Assembly Programming
Post by: Munchor on January 22, 2011, 05:59:45 pm
Code: [Select]
EF4045
3E01
C60A
2600
6F
EF0745
EF7249
EF4045
C9

It could be optimized to:

Code: [Select]
EF4045
210B00
EF0745
EF7249
EF4045
C9

However, it would lose the point of the challange.
Title: Re: Hexadecimal Assembly Programming
Post by: AngelFish on January 22, 2011, 06:04:40 pm
Scout, no one is going to be able to remove their finger from the keypad quickly enough for that not to execute through :P

EDIT: Now write it without system calls  >:D
Title: Re: Hexadecimal Assembly Programming
Post by: Xeda112358 on January 22, 2011, 06:09:54 pm
Been there. Done that. It is fun.
Title: Re: Hexadecimal Assembly Programming
Post by: Ashbad on January 22, 2011, 07:55:37 pm
writing without system calls is more fun.  But eventually leads to you getting cocky and writing a shell to beat the big ones like MOS/DCS7.  That's what happened to Lo-C and AshbadOS (both were by me, and both failed.  Lo-C was more of a shell however that was meant to allow the user extreme ease in logic and structure functions, like in the language C)

Yeah I used to be hex but moved out.  though it was quite fun :)
Title: Re: Hexadecimal Assembly Programming
Post by: Xeda112358 on January 22, 2011, 08:00:43 pm
Yeah, I'll admit I have been getting kind of "cocky," but I do prefer to make my own routines if they are similar but better than the ROM calls. As for making a shell... I might make one as an added feature, but I am not all that great at actually programming in assembly. I can make calls and routines, but to actually make running programs... that is a bit different.
And programming in hex is fun! It's a lot easier for me to work with, so I try to stick with that. I do absolutely love and appreciate Assemblex because it makes it easier for me to use mnemonics, too.
Title: Re: Hexadecimal Assembly Programming
Post by: AngelFish on January 22, 2011, 08:03:48 pm
The great thing about hex is that it makes a lot more sense than Assembly does. It also eliminates the need for an Assembler, which are always problematic for me. The downside is calculating jumps...
/me just realized that his hex has been throwing illegal instruction errors and he didn't even realize it.
Title: Re: Hexadecimal Assembly Programming
Post by: Munchor on January 22, 2011, 08:04:49 pm
The great thing about hex is that it makes a lot more sense than Assembly does. It also eliminates the need for an Assembler, which are always problematic for me. The downside is calculating jumps...

And also memorizing (downside). When programming in Hex I always use all-program labels instead of byte-based labels.
Title: Re: Hexadecimal Assembly Programming
Post by: Xeda112358 on January 22, 2011, 08:05:30 pm
Completely and fully agreed. Luckily, the calc has 16 chars to a line which makes it a little easier. Every two lines adds 10h to the address.
Title: Re: Hexadecimal Assembly Programming
Post by: souvik1997 on January 22, 2011, 08:17:33 pm
The great thing about hex is that it makes a lot more sense than Assembly does. It also eliminates the need for an Assembler, which are always problematic for me. The downside is calculating jumps...

And also memorizing (downside). When programming in Hex I always use all-program labels instead of byte-based labels.
Do you mean that you are doing "jp XXXX" instead or "jr XXXX"? The JP opcode uses one more byte than the JR oprcode, so it's not very efficient to always use that. :/

@Qwerty.55: Programming the calculator using hexadecimal machine code instructions is exactly the same as programming the calculator with assembly instructions, so I don't see how that makes more sense.
Title: Re: Hexadecimal Assembly Programming
Post by: Munchor on January 22, 2011, 08:18:44 pm
Do you mean that you are doing "jp XXXX" instead or "jr XXXX"? The JP opcode uses one more byte than the JR oprcode, so it's not very efficient to always use that. :/

It is definetely not the optimized way to do it.
Title: Re: Hexadecimal Assembly Programming
Post by: AngelFish on January 22, 2011, 08:23:47 pm
@Qwerty.55: Programming the calculator using hexadecimal machine code instructions is exactly the same as programming the calculator with assembly instructions, so I don't see how that makes more sense.

The way the equates are designed on some systems makes more sense than the mnemonics. For example MOV Rm, Rn is 6nm3, which is more logical.
Title: Re: Hexadecimal Assembly Programming
Post by: DJ Omnimaga on January 23, 2011, 02:47:44 am
The problem in hex though is writing extremly massive games. I think reading E:SoR code in hex would start being hard. O.O
Title: Re: Hexadecimal Assembly Programming
Post by: Munchor on January 23, 2011, 04:55:22 am
The problem in hex though is writing extremly massive games. I think reading E:SoR code in hex would start being hard. O.O

But even though, Zeda made an Application :D
Title: Re: Hexadecimal Assembly Programming
Post by: Xeda112358 on January 23, 2011, 11:13:20 am
Hehe...
<.<
>.>
Time for another App...

Oh, and it actually isn't too difficult to understand hex once you've used it long enough. I've been disassembling the TI-OS just by reading the hex and I've learned some useful things (like how to tell what model calc is being used, which areas of extra RAM are off limits, how ROM calls are handled) that kind of thing. If you happen to know which page the ROM call location is on, you can save a little speed (maybe a few hundred T-States) at the cost of a few extra bytes.

But yeah, I'm not saying it's easy, though. It makes my brain hurt, but I can get through maybe a thousand bytes of code per hour, give or take depending on how complex the routines are. That is what I had to do when I made the font hook...  ._.
Title: Re: Hexadecimal Assembly Programming
Post by: Binder News on January 23, 2011, 11:33:45 am
You are amazing. O.O
Title: Re: Hexadecimal Assembly Programming
Post by: Xeda112358 on January 23, 2011, 11:43:52 am
Nah, that's just what you can do when you don't have internet (meaning you have LOTS of time and no other means).
Title: Re: Hexadecimal Assembly Programming
Post by: Deep Toaster on January 23, 2011, 12:37:55 pm
Hehe...
<.<
>.>
Time for another App...

Oh, and it actually isn't too difficult to understand hex once you've used it long enough. I've been disassembling the TI-OS just by reading the hex and I've learned some useful things (like how to tell what model calc is being used, which areas of extra RAM are off limits, how ROM calls are handled) that kind of thing. If you happen to know which page the ROM call location is on, you can save a little speed (maybe a few hundred T-States) at the cost of a few extra bytes.

But yeah, I'm not saying it's easy, though. It makes my brain hurt, but I can get through maybe a thousand bytes of code per hour, give or take depending on how complex the routines are. That is what I had to do when I made the font hook...  ._.

You're literally reading numbers as words O.O
Title: Re: Hexadecimal Assembly Programming
Post by: Binder News on January 23, 2011, 12:42:05 pm
Hehe...
<.<
>.>
Time for another App...

Oh, and it actually isn't too difficult to understand hex once you've used it long enough. I've been disassembling the TI-OS just by reading the hex and I've learned some useful things (like how to tell what model calc is being used, which areas of extra RAM are off limits, how ROM calls are handled) that kind of thing. If you happen to know which page the ROM call location is on, you can save a little speed (maybe a few hundred T-States) at the cost of a few extra bytes.

But yeah, I'm not saying it's easy, though. It makes my brain hurt, but I can get through maybe a thousand bytes of code per hour, give or take depending on how complex the routines are. That is what I had to do when I made the font hook...  ._.

You're literally reading numbers as words O.O
For some reason, that seems a little weird. Then again, so does sitting in math class reading programming books for fun, so I shouldn't be talking.
Title: Re: Hexadecimal Assembly Programming
Post by: Munchor on January 23, 2011, 12:42:18 pm
You're literally reading numbers as words O.O

I just open Assemblex, choose an .8xu file and then convert it to Assembly (it is not that accurate at converting OSs I think), but you can then read numbers as words :)

Also, Hexadecimal has both numbers and words :w00t:
Title: Re: Hexadecimal Assembly Programming
Post by: Xeda112358 on January 23, 2011, 12:44:50 pm
You're literally reading numbers as words O.O
Hehe, no I'm not. When I read mnemonics, I convert that to numbers. I interpret the instructions for what they do, not what they are named.

(and yes, in hexadecimal, A~F are considered numbers)
Title: Re: Hexadecimal Assembly Programming
Post by: DJ Omnimaga on January 24, 2011, 03:11:59 am
Nah, that's just what you can do when you don't have internet (meaning you have LOTS of time and no other means).
It kinda reminds me visually impaired people, for example. I heard that they develop their hearing sense even more since they cannot see at all.

Around 2007 I remember an upsurge of BASIC programmers who couldn't stand coding on-calc: they all used TI-Graph Link software. I myself can't stand coding on a computer because I had no computer at home and since my 83+ was my only way to put my ideas into code and I had a lot of free time, I got used a lot to on-calc programming. Sadly, my lack of access to advanced tutorials kinda impaired my TI-BASIC optimizing skills and I got stuck with bad habits, though.
Title: Re: Hexadecimal Assembly Programming
Post by: Xeda112358 on January 24, 2011, 11:53:53 am
Yeah, I know what you mean. I learned BASIC on the calc, and I cannot stand programming in BASIC on the computer. Also, people take for granted how powerful their memory can be. A person can literally memorize thousands of these opcodes after using them enough. If a tapeworm can use it's brain to memorize the correct path in a maze, a human can remember things millions or billions times more complex.

*Seriously, there was an experiment with tapeworms where they had a tapeworm go through a maze to get to the food. After a few hundred tries, it finally got to it. They crushed up the tape worm and fed it to another. That tapeworm got through the maze on the first try. They changed the maze a little and the tapeworm tried going the same route and failed. The scientists knew that each segment in a tapeworm had a small piece of its brain, so they were curious about how tapeworm memory works... Apparently Zombie tapeworms would be really smart!
Title: Re: Hexadecimal Assembly Programming
Post by: Munchor on January 24, 2011, 05:21:36 pm
Quote
(and yes, in hexadecimal, A~F are considered numbers)

I don't think so. A,B,C,D,E,F are letters as far as I know.
Title: Re: Hexadecimal Assembly Programming
Post by: souvik1997 on January 24, 2011, 06:30:06 pm
They are actually digits, which make up numbers. :)
http://en.wikipedia.org/wiki/Hexadecimal
Title: Re: Hexadecimal Assembly Programming
Post by: jnesselr on January 24, 2011, 07:11:02 pm
Quote
(and yes, in hexadecimal, A~F are considered numbers)

I don't think so. A,B,C,D,E,F are letters as far as I know.
That's because you are used to using decimal.  Technically, they are both.  G is also a number in base 17, along with 0-9 and A-F.
Title: Re: Hexadecimal Assembly Programming
Post by: Michael_Lee on January 24, 2011, 07:22:04 pm
*Seriously, there was an experiment with tapeworms where they had a tapeworm go through a maze to get to the food. After a few hundred tries, it finally got to it. They crushed up the tape worm and fed it to another. That tapeworm got through the maze on the first try. They changed the maze a little and the tapeworm tried going the same route and failed. The scientists knew that each segment in a tapeworm had a small piece of its brain, so they were curious about how tapeworm memory works... Apparently Zombie tapeworms would be really smart!

Wait, what -- seriously?  That is cool and slightly disturbing.
Title: Re: Hexadecimal Assembly Programming
Post by: jnesselr on January 24, 2011, 07:51:41 pm
*Seriously, there was an experiment with tapeworms where they had a tapeworm go through a maze to get to the food. After a few hundred tries, it finally got to it. They crushed up the tape worm and fed it to another. That tapeworm got through the maze on the first try. They changed the maze a little and the tapeworm tried going the same route and failed. The scientists knew that each segment in a tapeworm had a small piece of its brain, so they were curious about how tapeworm memory works... Apparently Zombie tapeworms would be really smart!

Wait, what -- seriously?  That is cool and slightly disturbing.
Very disturbing.  So wait, what if you did that repeatedly.  Would the tapeworm at the end be a genius maze solver or something?

/me (Because kings don't like tapeworms) goes off to teach a tapeworm how to play chess
Title: Re: Hexadecimal Assembly Programming
Post by: AngelFish on January 24, 2011, 07:55:02 pm
Yeah, I know what you mean. I learned BASIC on the calc, and I cannot stand programming in BASIC on the computer. Also, people take for granted how powerful their memory can be. A person can literally memorize thousands of these opcodes after using them enough. If a tapeworm can use it's brain to memorize the correct path in a maze, a human can remember things millions or billions times more complex.

Some people have "For rent" signs hanging on their brains instead of actually using them.

And about Comp BASIC, I do use things like SourceCoder when I have to manipulate a large amount of data. It's much easier to copy/paste than to run the program, store to a string, recall, edit a few thousand bytes, then run again to test everything.
Title: Re: Hexadecimal Assembly Programming
Post by: Xeda112358 on January 24, 2011, 08:31:16 pm
Yeah, I can see how that might be useful, but I feel much more comfortable typing on my calculator than I do on the computer. The keyboard on my computer is just so big! The calc is just so nice and compact and easy to handle. However, it is a bit cumbersome to program in hex on the calculator, so I usually type up the hex in Notepad and then transfer it to my calc to edit and debug.
Title: Re: Hexadecimal Assembly Programming
Post by: Binder News on January 24, 2011, 09:19:44 pm
I find it very hard to do BASIC on the computer. Like Qwerty, I use stuff like SourceCoder for large copy-paste things.
Title: Re: Hexadecimal Assembly Programming
Post by: DJ Omnimaga on January 25, 2011, 02:34:39 am
In my case I just prefer on-calc because I hate having to save the file, loading it in WabbitEmu then run it, then go back to the computer program editor, debug, etc. I prefer coding+testing directly on the platform and I rarely need to copy/paste large code anyway. I prefer editing sprites on the computer, though.
Title: Re: Hexadecimal Assembly Programming
Post by: Munchor on January 25, 2011, 07:36:06 am
I love Basic on Computer, Tokens all the way.
Title: Re: Hexadecimal Assembly Programming
Post by: Xeda112358 on January 30, 2011, 12:24:34 am
I still cannot work on a computer. Like, right now (while I am not typing) I am working on some example programs for BatLib and it just feels so uncomfortable to do it on a computer...
Title: Re: Hexadecimal Assembly Programming
Post by: Munchor on April 10, 2011, 07:02:26 am
Code: [Select]
EF4045FD
CB00AE21000022D7
8621AC9DEF0A45EF
2E45C948656C6C6F
20776F726C642100

Isn't this supposed to display 'Hello World!'?

I only get the 'H'.
Title: Re: Hexadecimal Assembly Programming
Post by: Deep Toaster on April 10, 2011, 11:56:35 am
Code: [Select]
22D786

That is LD (penCol),HL. penCol is used for displaying graphscreen text and other drawing commands, not homescreen text, so for that you need to load HL into curRow (224B84).
Title: Re: Hexadecimal Assembly Programming
Post by: Xeda112358 on April 10, 2011, 12:06:34 pm
The hex to display Hello World! would be:
Code: [Select]
EF4645
210000224B84
21A59D
EF1045C9
0C
48656C6C6F20576F726C6421
I think I got the ASCII correct XD
Title: Re: Hexadecimal Assembly Programming
Post by: Munchor on April 10, 2011, 12:06:46 pm
Code: [Select]
EF4045FD
CB00AE210000224B8421AC9DEF0A45EF
2E45C948656C6C6F
20776F726C642100
This worked, thanks much!