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

by Phil

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

INTRODUCTION

Well, I just had myself a good time converting UNITCONV to ASM. Now I got the program to run a little bit faster, and the menus are cooler. I’m probably going to rewrite it so it’s only one program, instead of 100 (exaggeration). I also want to get rid of the CONV list, and that should clear up A LOT of space. I’m trying to get a hold of all simple little programs that you probibly use for math and science to cheat on the exams so I can make them smaller and faster by programming them in ASM. Also, another ASM programmer I know of is trying to work out a new compression program that works kinda like SQUISH and ZASMLOAD, but it’ll be one file that converts and executes. Don’t be looking for it very soon, though. There’s a few things he needs to work out.

Welcome, friends. Today is the day that you learn how to make a GOOD ASM program. In order to do this, I will have to teach you about labels. A label is just as it sounds. It's the same in BASIC as it is in ASM. The difference is how you jump to the label that makes ASM difficult.

LABLES

Remember in good old BASIC how you could only have one-character labels? Well, ASM makes labels a lot more fun and easier to remember my letting you determine the length and names of your labels. To write a label in a program, you just type a word or phrase in the first column and place a colon after it, like so:

FIRST_LABEL:

Remember how I always used to tell you that the commands in an ASM program have to be in the first column? Well, this is because the assembler is stupid. It cant tell the difference between a label and a command, so you have to make the two different by putting the commands in the second column, or the position, and the labels in the first column, or home position. I named the label 'FIRST_LABEL' instead of '1ST_LABEL' or 'FIRST LABEL' because you can't put a number as the first digit of a label, and you can't use spaces. The colon is also VERY important. Without the colon, the assembler thinks the label is just another command.

Now, "How do you jump to a label, Phil?" you ask? Well, the command you'd use to jump is 'jp', short for 'JUMP'. Get it? I'll show you an example that will jump to the label 'FIRST_LABEL':

        jp FIRST_LABEL

'jp' IS A COMMAND, so therefore, it MUST be in the position, like 'ld' or 'cp'. Okay, you have labels now, and you can jump to them. Now it's time for an 'If...Then Goto...' command. These commands are what make up the body on the more complex ASM programs. Remember good ol' 'COMPARE', or 'cp'? Well, when you use that command comparing two numbers, the output will either be zero, or 'z', or not zero, 'nz' (If you are confused about comparing, refer to The ASM Logs vol. 2). (The ‘cp’ command needs to have the accumulator defined, or the variable ‘a’ defined in order to work. It outputs to ‘z’. but that’s not important now.) An 'If...Then Goto...' command can only read 'If zero Then Goto...' or 'If not zero Then Goto...' in ASM, so programmers have to get creative. Let's compare two numbers:

        ld a,5
        cp 5

Now, since 'a' equals five and you are subtracting 5 from 'a', the output will be zero, right? I order to jump to a label in this statement, we would add either a 'z' or an 'nz' to the 'jp' command ('z' being zero, and 'nz' being not zero). The command 'If a-5=zero Then Goto FIRST_LABEL' would look like this in ASM:

        ld a,5
        cp 5
        jp z,FIRST_LABEL

Now just add on to this more 'cp' commands, and you can compare 'a' to any thing you want in a series (you don’t have to keep redefining ‘a’), like so:

        ld a,5
        cp 5
        jp z,FIRST_LABEL
        cp 6
        jp z,SECOND_LABEL

Also, you can put in 'nz' for 'z' if you want the program to jump if the answer is not zero, like so:

        ld a,5
        cp 6
        jp nz,FIRST_LABEL

Labels do not HAVE to be jumped to. Just like how you really don't have to do this in BASIC:

:Goto 5
:Lbl 5

You don't have to do this in ASM:

        jp FIRST_LABEL
FIRST_LABEL:

The same lines without the 'jp' command would accomplish the same task, and take up less memory.

PROGRAM TIME!

It's time to make another program!!! This time, it will be a few simple 'cp...jp' commands. Remember to put in your head like so:

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

Now, program the following in notepad or something:

        ld a,5
        cp 5
        jp z,LABEL
        jp nz,NOT

This means "If 'a' minus 5 equals zero, jump to label, but if not, jump back home and try again."

LABEL:
        ld a,1
        call _setxxop1
        call _stox
        ret

And this means "Store 'a', or 1, into BASIC's X and exit the program"

NOT:
        ld a,0
        call _setxxop1
        call _stox
        ret

This means "Store 'a', or 0, into BASIC's X and exit the program." Don't forget to end the program by putting the lines:

.end
END

Now, follow the instructions in Log 1 to assemble, and try your program. Change the value of 'a' to anything, or compare it with other numbers. Have a good ol' time!!!

Just a quick side note. When you are programming, you might want to add notes to your program to tell yourself what you did, or what each line does. This comes in handy when you are programming ENORMOUS programs. All you have to do to make a note is put a semicolon ( ; ) before the note on any line, and the assembler will not assemble it. Kind of like this:

        ld a,5          ;Loads 5 into accumulator

Everything after the semicolon on the line is ignored.


Remember, I already said that I'm NOT responsible for ANY data loss on your TI- 83, so don't change these programs TOO much, and nothing bad will happen (I hope). I typed this at 23:06 and I am tired, so there are probably grammer mistakes galore. So sue me. If this log has confused the hell out of you, read it again, or try reading the previous logs again so you get a clue.

Thanks go out to the usuals, and Andy, who published the document.



Thanks for your time, see you in vol. 4!
-Phil

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