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

by Phil

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

INTRODUCTION

Well, here I am again. Every time I look at my calculator then look at my computer, I wonder, "Phil, exactly WHY are you making this column?" Then I remember how much fun it is to convert BASIC programs into ASM, then see how much smaller I can make them, or how fast they can run (trust me, it's fun). When we last left off, I had just told you how to make a very simple program and assemble it, right? Now that I’ve told you how to cut and paste your way into making a program, I believe that it will benefit you to know what some of the simple commands do.

BASIC COMMANDS AND VARIABLES

I believe that in the previous log, I told you that the following lines:

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

were called the head of the program. Just to review, these commands tell the assembler that the following program is a TI-83 program, and it also defines most of the commands. Now, it you were to make a BASIC program or game, one of the main parts of it would be the use of ‘Lbl’ and ‘Goto’ commands (Well, this only applies to the really GOOD or complex programs). In ASM, you use the same style of body structure. The only problem is, there are no ‘If ... Then’ statements in ASM. Programmers have to find clever ways around using these statements in their ASM codes. For starters, lets look at the most basic command (REMEMBER, all commands in an ASM program can’t be put in the first column of text, so TAB over at each command!). This command is:

	ld

That’s all, the letters ‘L’ and ‘D’ next to each other. This is short for the command ‘LOAD’. Now, I hear you asking "Phil, what does LOAD do?". LOAD is just like the ‘Sto’ command in basic, or ‘->‘. Now, just like you can’t put ‘X -> 5’ in BASIC, there is a form to follow in ASM too. The way the BASIC command looks is this:

(NUMBER OR VARIABLE) -> (VARIABLE)

But in basic, the ‘->‘ is change to a ‘<-’. The way the ASM command looks is like so:

	ld (VARIABLE),(NUMBER OR VARIABLE)

or, if you were to compare it to BASIC:

	ld (VARIABLE) <- (NUMBER OR VARIABLE)

So if I wanted to ‘Load 5 into a’, I would do so like this:

	ld a,5

That’s it. You can also store the value of one variable into another. All you have to do is replace the ‘5’ above with ‘b’ or something.
Now, there is something I must tell you before I go on. ASM variables and BASIC variables are NOT the same. At the end of the program, the calculator deletes the ASM variables. Also, all ASM variable must be defined before using them in and equation or in a command with no numbers. If you wanted to load ‘b’ into ‘a’, you cannot just put:

	ld a,b

You’d have to tell the calculator what ‘b’ is first, like so:

	ld b,5
	ld a,b

or:

	ld a,5
	ld b,a
	ld a,b

That’s enough for the ‘ld’ command for now. It’s time to learn a command called ‘cp’. The ‘cp’ is short for ‘COMPARE’. Now you don’t have to ask me "Phil, what’s COMPARE do?" because I’m just getting into that. In a definition, ‘cp’ subtracts ‘a’ minus the variable or number that follows the command. If this is too confusing, I will show you a sample use of ‘cp’:

	ld a,5
	cp 5

As we all (should) know, ‘a’ minus 5, or 5 minus 5, equals zero. This is important!!! The ‘cp’ command is most commonly used as an ‘If ... Then’ statement when followed by other commands.
Now, real fast, I'm going to try to explain to you the different variables that ASM uses. Remember that ASM variables and BASIC variables are not the same. The names of the variables are: a b c d e h l . These can all be up any 8 bit number (0 to 255, or in binary, if it helps, 00000000 to 11111111). 'a' is the most important of these variables. It is called the accumulator. Almost ALL commands requiring one 8 bit variable use the accumulator. If you wanted a larger number than 255, you can combine two 8 bit variables to get one 16 bit variable. These variables are: bc de hl , and they can be any number between 0 and 65535 (or in binary, if it helps, 0000000000000000 to 1111111111111111). 'hl' is the most important of these variables. In almost all commands which use a 16 bit number, the variable 'hl' is used. There are some tricks where you can combine two 8 bit variables to get one 16 bit variable, but they are unimportant now, because you can just as easily load a 16 bit number into a 16 bit variable. In other words, instead of doing this:

	ld h,1
	ld l,3

to get 'hl=259', you can do this:

	ld hl,259

The reason that 'hl=259' when 'h=1' and 'l=3' is simple binary math. 1 in binary is 00000001, and 3 in binary is 00000011. So when you put the two next to each other, you get 0000000100000011, or 259.

This is all you need to know for now, though, until I get into talking about labels. Remember all that you have learned in this log and the previous log, for I will be referring to them many times in my next logs. Things will start speeding up from here, so heart patients should be advised, and children under the age of 12 should be 50 inches or taller to proceed.

Thanks again go out to Ahmed, Bill, Alex, Jareth, Jeff, Andrew, Andy, and Joe. Extraspecialsuper thanks go out to Jamie, for her inspiration (though she doesn’t know it).

Thanks for your time. See you in TI-83 ASM Logs vol. 3!

-Phil

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