Omnimaga
Calculator Community => TI Calculators => ASM => Topic started 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:
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:
.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:
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:
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:
EF4045
3E01
C60A
2600
6F
EF0745
EF7249
EF4045
C9
Who guesses what this does?
-
Very useful. Definite bookmark!
-
Very useful. Definite bookmark!
Thanks much!
I edited with another program ;D
-
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!
-
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.
-
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
-
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.
-
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.
-
Yeah, I've checked yours... me likes :D
Oh, um, yeah, I made it with Open Office...
-
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
-
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?
-
Pssh, that is SO unoptimised... :P
(but it is for an example, so I guess it's okay :D)
-
EF4045
3E01
C60A
2600
6F
EF0745
EF7249
EF4045
C9
It could be optimized to:
EF4045
210B00
EF0745
EF7249
EF4045
C9
However, it would lose the point of the challange.
-
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
-
Been there. Done that. It is fun.
-
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 :)
-
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.
-
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.
-
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.
-
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.
-
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.
-
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.
-
@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.
-
The problem in hex though is writing extremly massive games. I think reading E:SoR code in hex would start being hard. O.O
-
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
-
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 are amazing. O.O
-
Nah, that's just what you can do when you don't have internet (meaning you have LOTS of time and no other means).
-
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
-
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.
-
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:
-
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)
-
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.
-
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!
-
(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.
-
They are actually digits, which make up numbers. :)
http://en.wikipedia.org/wiki/Hexadecimal
-
(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.
-
*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.
-
*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
-
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.
-
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.
-
I find it very hard to do BASIC on the computer. Like Qwerty, I use stuff like SourceCoder for large copy-paste things.
-
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.
-
I love Basic on Computer, Tokens all the way.
-
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...
-
EF4045FD
CB00AE21000022D7
8621AC9DEF0A45EF
2E45C948656C6C6F
20776F726C642100
Isn't this supposed to display 'Hello World!'?
I only get the 'H'.
-
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).
-
The hex to display Hello World! would be:
EF4645
210000224B84
21A59D
EF1045C9
0C
48656C6C6F20576F726C6421
I think I got the ASCII correct XD
-
EF4045FD
CB00AE210000224B8421AC9DEF0A45EF
2E45C948656C6C6F
20776F726C642100
This worked, thanks much!