ticalc.org
Basics Archives Community Services Programming
Hardware Help About Search Your Account
   Home :: Programming :: Columns and Tutorials :: TI-83 Assembly Logs Vol. 1
TI-83 Assembly Logs Vol. 1

by Phil

Editor's note: The information contained in this article may be outdated and/or inaccurate.

INTRODUCTION

To begin, I have to say that this is a guide for programming the TI-83's ASM language, and NOT the 86's. The two languages are similar, but most of the commands will not work on both. I don't know how many times I've looked up ASM programming guides and found out half way through the document that they are for 86 ASM.

I have to admit, I am not the best ASM programmer on earth. As a matter of fact, I have about as much skill in ASM programming as the average 2 year old (okay, maybe a bit more). I am writing this guide to fill in the blanks left on people's faces af ter they read the other guides on the internet. I know I was EXTREMELY confused in the beginning, so I will try to make this learning experience as painless as possible. Now, I am not saying that the other guides are no good. As a matter of fact, I am modeling this one after Ahmed's The TI Journals. I am just trying to make a guide that any high school freshman can pick up and learn the basics.

WHAT YOU NEED

Lets just assume you have never heard of ASM, assembly, assembler, or any other big words associated with assembly. In order to assemble programs, you can either take the program you make and manually convert every command and every line into HEX code , or you can get a program to do this for you.

You can get the programs you need either at The ticalc.org File Archives or for a more specific page The TI-83 Headquarters

I also recommend downloading the TASM (Table ASseMbler, v 3.01). This is the slowest assembler around, but it is for DOS, and it is very reliable. This file is called 'tasm301.zip'. Now you will need the include files. I'll tell you what they do late r, just get them now and don't ask questions. The file is 'include.zip'.

That's it! Now, go to any text editor (Notepad should work) and type in the following line:

tasm -t80 -i -o20 -p60 %1

Save that as a file called "asm.bat" and put it into a clean directory. Unzip the above two files into the same directory and you are ready to assemble.

VERY VERY IMPORTANT!!!

BEFORE YOU ASSEMBLE you should open "tokens.inc" in Notepad and delete all the characters that look like blocks. These blocks are found every few pages. If you do not delete these symbols, the assembler will error and your assembly program will not asse mble properly!

For starters, I will have to tell you what ASM actually is. ASM is short for Assembly language. Now, you're asking me "What is assembly language, Phil?" Well, I'll tell you. Just like the computer you are reading this at (probably) has a Pentium pr ocessor, the TI-83 has a processor in it called the Z80. Now, processors have to be told what to do. Almost all processors are told this by using a form of assembly language. Other programming languages, like C++ or TI-BASIC, take the commands and conv ert them into a language the processor understands. If you program in TI-BASIC, the processing time and programming variety is limited due to the face that TI-BASIC has to recognize the command, convert it into the assembly code, then send it to the processor. The TI-83, though, has an ability to bypass the BASIC language, and access the processor directly. ASM programs take up less space and are much faster than BASIC programs. The o nly problem is, there is a vast difference between TI-BASIC and 83 ASM. Here is a visual summery of what I just said:

BASIC Language input:

INPUT (in BASIC) ---> BASIC Interpreter
---> Processor ---> OUTPUT

ASM Language input:

INPUT (in Hexadecimal Machine Code)
---> Processor ---> OUTPUT

(I will not refer to this process much anyway, so don't get worried)

PROGRAMMING:

Now I will get into the differences between BASIC and ASM. ASM is ALWAYS more lengthy to program in, even when you are trying to program something as simple as the expression 3+6 -> X. The reason it is so hard is BASIC knows that if it sees a '+' bet ween two numbers, it will add them, then if it sees a '->' between a number and a variable, it will store the number as the variable. In ASM, you only are able to use simple commands that perform one simple operation. This is a pretty simple expression, but this is how it looks in ASM:

	ld a,3
	ld b,6
	add a,b
	call _setxxop1
	call _stox

That's a LOT of work, right? Not really. This is a simple command in ASM as well. All that is says is this:

Load 3 into a Load 6 into b Add a and b together and store the answer into a Store a into OP1 Store OP1 into BASIC's variable X

I will describe all of these commands fully later, but the idea is simple.

This is where it's important to pay attention. The assembler (TASM in this case) converts whatever you tell it to into HEX, as long as it knows what everything you write in the program is. The first thing you want to do in ALL programs is tell the Asse mbler what commands do what. To do this, open up a text editor. The very first line should look like this:

.NOLIST

This command is required at the beginning to say to the assembler "Look, I'm going to be defining some things here, so don't treat these next lines as commands, okay?" If you were to open the file called "ti83asm.inc", you would see that it's a bunch of lines that say stuff like:

_ACommand  .EQU 2314h
_AnotherCommand  .equ 4658h

Do you see that the '.equ's are upper case and lower case? To make sure that the assembler doesn't get confused, add these lines after the first:

#define equ .equ
#define EQU .equ

This says, basically, "I want you to consider the command EQU the same as the command equ." This next line will tell the assembler that the end is the end:

#define end .end

These next two lines are where you will need the include files (the .inc files). These next lines are VERY important.

#include "ti83asm.inc"
#include "tokens.inc"

If you noted the program that added 3 and 6, then stored them as X, you would see that one of the lines was:

	call _setxxop1

If you were to not have the above lines in the program, the assembler would say "I don’t know what that _setxxop1 crap is. What do you want me to do?" The program "ti83asm.inc" has a line in it that tells the assembler how to "_setxxop1", so the assemb ler would say "Hold on, let me look through the include files.... Ah! Here it is. _setxxop1 means I should store A into OP1, I get it." Got it?

Now the next line is simple, it just tells the assembler that it's done with the heading, or defining stage. This line is:

.LIST

The next line HAS to be in all ASM programs. It tells the calculator "This is the beginning of the program.":

.org 9327h

By the way, I hope you know that if the number has an 'h' after it, the number is in hexadecimal, if it has a 'b' after it, it's in binary, and if it has a 'd', it's a decimal number. This is just standard computer commands. So if you put the number A7 h in a program, the assembler will read the number as 167d, or just 167. Now, if you were to put all of the above lines together, the beginning of the program would look like this:

.NOLIST
#define equ .equ
#define EQU .equ
#define end .end
#include "ti83asm.inc"
#include "tokens.inc"
.LIST
.org 9327h

If you wanted to make a program that added 3 and 6, then stored it to X, you would follow the above lines with the programs way back in this guide (remember?) So the entire program would look like this:

.NOLIST
#define equ .equ
#define EQU .equ
#define end .end
#include "ti83asm.inc"
#include "tokens.inc"
.LIST
.org 9327h
	ld a,3
	ld b,6
	add a,b
	call _setxxop1
	call _stox

REMEMBER!!!! All commands after ".org 9327h" MUST NOT be in the first column. It is always good practice to TAB over on every line, but you could space over if you wanted. To end the program, add the command "ret" and two ENDs to it, like this:

	ret
.end
END

"ret" tells the calculator "End this ASM Program, okay?" and the ENDs tell the assembler "Don't assemble any more, okay?" The completed program looks like this:

.NOLIST
#define equ .equ
#define EQU .equ
#define end .end
#include "ti83asm.inc"
#include "tokens.inc"
.LIST
.org 9327h
	ld a,3
	ld b,6
	add a,b
	call _setxxop1
	call _stox
	ret
.end
END

Save the file as "test.z80" in the same directory as the assembler is in. Now you are ready to assemble.

ASSEMBLING:

Remember those programs you downloaded and the .bat file you made? Well, dig them up, and go to DOS. At the prompt, type:

asm test.z80

This will run the .bat file "asm.bat", and it will assemble the program "test.z80". TASM301 will start up, then find out if you have any errors. The program above SHOULDN'T have errors. TASM will then make two files in the directory that "test.z80" is in. These files are called "test.lst" which can be discarded, and "test.obj" which is very important. The .obj file, or the object file, will look like this if opened in a text editor:

:0C9327003E03060680CD744ACDD44EC92A
:00000001FF

You may recognize this as HEX code. That is the code used to talk to the processor. The only problems are, those numbers and letters are not in TI-83 Program format, and the code above isn't the real object code. The code above has strings at the begi nning and the end of each line, and a final string. You must delete these. The strings are the first eight digits and the colon, and the last two digits. The final string is the last line, which is always ":00000001FF". The complete object code looks like this:

3E03060680CD744ACDD44EC9

Now, highlight the code and copy it. Then you have to open up a Link program, like WinLink 83, which can be found on TI's home page

PaSTE the code onto a program. BUT WAIT!!! Don't send that file to your calculator yet! You have to add a few lines at the end first. In order for the calculator to distinguish between a BASIC program and an ASM program, you must add these lines at t he end:

End
0000
End

These lines tell the calculator "This signifies the end of an ASM program, so this program must be written in ASM." Now you are ready. Name the program TEST and send it to your calculator. In order to run an ASM program, a BASIC host program is nee ded. Running any ASM program is easy, just add the line:

Send(9prgmTEST

to a new program. Now run the BASIC program. Check the variable X, and you will see that it is 9. You have just made your first ASM program. Substitute any numbers for 6 and 3, and assemble the program again. Compare the speed of the program to the BASIC program. I don't believe there will be much of a difference, the two programs will equal 51 bytes, opposed to the BASIC program size of 12 that does the same thing, but it's a start! The larger programs that you will learn how to program later wit h pictures will be substantially smaller and faster than BASIC, so don't worry! CAUTION!!! It is ill advised to experiment with ASM if you don't know what you are doing. Errors in the programming may result in a lock-up, causing you to have to reset the calculator's memory, and that's bad. You have been warned.

This has been created by Phil under PaSTE of America, and is intended for the beginning ASM student. The way I describe the assembly process in not exactly what really happens, and it could be completely wrong. Thanks go out to Ahmed, Bill, Alex, Joe, J areth, and my love, Jamie. You will see mistakes in this file, so DO NOT WORRY! Tell me what’s wrong, and I’ll fix it.

Thanks for your time, and I'll see you in the ASM Log 2!

  Copyright © 1996-2012, the ticalc.org project. All rights reserved. | Contact Us | Disclaimer