ticalc.org
Basics Archives Community Services Programming
Hardware Help About Search Your Account
   Home :: Archives :: News :: Feature: TI-83 ASM Tutorial (Part 2)

Feature: TI-83 ASM Tutorial (Part 2)
Posted by Nick on 12 April 2000, 03:02 GMT

Jeff Chai takes the microphone once again in his second feature here at ticalc.org. Here, he elaborates a little more on some more intermediate TI-83 Plus ASM topics.


Tutorial 5
Assembling Asm Programs

Overview

You will learn the steps to assembling Asm programs using TASM.

Background Information

TASM stands for Telemark Cross Assembler. The TASM assembler assembles for the Intel 8080 processor. What!? But we're assembling for Zilog's Z80 processor! Don't worry =) When the Z80 was developed by Zilog (A renegade group of Intel engineers), it was highly based off of the Intel 8080. In fact. they are cross compatible! That's why we're using TASM to assemble our programs.

Checklist for Assembling

  • Is the program written in z80 Asm?
  • Does the program have a .z80 file extension?
  • Have you self checked it for errors?
  • Have you had a friend (or me) check it?
  • Have you properly installed all the software?
  • Have you backed up your calculator?

Once this checklist is completed, continue on.

Assembling Programs

Now, copy the program you've written from the "MyPrgms" folder to the "TASMassembler" folder. Next, in the "TASMassembler" folder, make sure if you used any include files that they're in the folder along with the written program. In the "TASMassembler" folder, create a new text file called "Start.bat". You may edit this file later by right clicking on it and clicking on edit. In the "start.bat" file type in asm progname. Where progname is the name of the program you've written. Do not include the .z80 extension when typing in the name. Now save it and close the file. Now, to start assembling the program, click on the "start.bat" file. If all goes well, the assembler should have outputted a .hex file. If it did go on. If the assembler gave you an error message, click here to try to debug it.

Sending and Running

Open the progname.hex file in the "TASMassembler" folder. Select the entire contents of the file and copy it. Then open the TI-Graph Link program and type in AsmPrgm in the new program editing area on the right. Paste the contents of the .hex file there. Give it a name and send it to RAM. Make sure if you're using a Graph Link, that the link is securely connected to one of the computers COM ports. Then, on the calculator, press [2nd] + [Catalog] . Then scroll down to Asm (. Hit enter to paste it to the home screen. Then hit [Prgm] then select your program. Hit Enter. The home screen should look like this:

Asm ( prgmprogname

Hit enter to execute the command. Your Asm program is now running! What if it Crashes?

If you don't have a Graph Link, create a new program on the TI-83 Plus. Paste the AsmPrgm token in the program. Then you'll have to hand copy each charater from the .hex file to the calculator.

Compiling

To compile your program, paste the AsmComp( token from the catalog. Then paste the program you want to complile to the screen, then hit the , button. Then, from the catalog, paste the Prgm token to the screen. Then type in a name up to 8 characters long. It cannot be the same as the program you are compiling. Your calc screen should look like this:

AsmComp(prgmprogname, prgmprogname2

Hit enter and your program has now been compiled. You can run the program the same way as the program before you compiled it.

Tutorial 6
Moving the cursor to the next line

Overview

This is a seemingly worthless but none the less important tutorial on moving the cursor to the next line.

The Source Code

This code will move the cursor to the new line.

#define B_CALL(xxxx)	rst 28h \ .dw xxxx		 
#define B_JUMP(xxxx) call 50h \ .dw xxxx

_homeup =4558h
_newline =452Eh
_clrlcdfull =4540h

.org 9D95h

B_CALL(_clrlcdfull)
B_CALL(_homeup) ;Call up the home screen
B_CALL(_newline) ;Move cursor to next line
ret ;Return home

.end
END

Explanation

The screen should look like this after you run the program:

As you can see, there is an empty line on the top of the screen followed by a "Done" message and the blinking cursor on the next line. If it weren't for the "Done" message, the cursor would have been on the preceding line. The point is, the cursor isn't on the "First line". But rather on the next "empty" one.

New Commands

_newline - sets the cursor on the next "empty" line.

Related Commands

Did you know there is actually a ROM call that displays the "Done" message on the screen? Well that call is _DispDone (_DispDone = 45B5h). Try it out.

Tutorial 7
Displaying Text

Overview

This tutorial will show you how to make a program that will display normal and inverse (white on black) text.

Programming

The program below will display normal text on the home screen. The program uses the calls we have already learned, and adds some new ones. In a future tutorial, we will make a program that displays small text.

#define B_CALL(xxxx)	rst 28h \ .dw xxxx		 
#define B_JUMP(xxxx) call 50h \ .dw xxxx

_clrlcdfull =4540h ;The calls we will be using are defined here or use an include file
_homeup =4558h
_puts =450Ah
CURCOL =800Dh
CURROW =800Ch

.org 9D95h

B_CALL(_clrlcdfull) ;Clear the screen
B_CALL(_homeup) ;Bring on the home screen
ld a,0 ;Load "a" register as zero
ld (CURCOL),a ;Load zero into the y coordinate
ld (CURROW),a ;Load zero into the x coordinate
ld hl,txtLabel ;Load text from label below
B_CALL(_puts) ;Put text on screen
B_CALL(_clrlcdfull) ;Clear screen
ret ;Return to OS
txtLabel: ;the "Label" can be replaced with any name you want
;as long as you change the one on the top
.db "This Program "
.db "displays text "
.db "on the home "
.db "screen. It can "
.db "be up to 16 char"
.db "long, it can "
.db "only be 8 lines "
.db "long. ",0
.end
END

New Commands Used

(CURCOL) - the y coordinate of the cursor

(CURROW) - the x coordinate of the cursor

_puts - Puts the text on the screen. This command will bring the specified text to the screen.

_getkey - Detects a key press on the key pad

ld - z80 instruction fo loading something. In this program, it loads 0 (zero) to the "a" register. The syntax is - ld (register), (value#)

Registers

The calculator's memory is where nearly all data is stored. Unfortunately, memory access is relatively slow for the processor. So, when we want the processor to manipulate data, like add two numbers together, we don't want to do it in the memory. Instead, we load the data into special fast memory locations inside the processor itself called registers. In the normal text displaying program (above), the value "0" was saved into the "a" register. The value in the register was then in turn, loaded in to CURCOL and CURROW (the X and Y coordinates of the text). Registers are extremely important! If you don't understand them, I recommend that you read tutorial 4 in Andy S.' tutorials.

Inverse Text

Jeez, things just keep getting better. Inverse text is normal font text (white) on a black backround. This program will display the text "TI-83 Plus Asm" in inverse text. All you need to know to display inverse text is loading text coordinates and setting textinverse mode.

#define bcall(xxxx)	rst 28h \ .dw xxxx		 
#define bjump(xxxx) call 50h \ .dw xxxx

_clrlcdf =4540h
_homeup =4558h
_puts =450Ah
CURCOL =800Dh
CURROW =800Ch
textinverse =3 ;See the new commands section for more information
textflags =5

.org 9D95h

bcall(_clrlcdf)
bcall(_homeup)
set textInverse,(iy+textflags) ;Sets the textinverse mode
ld a,0 ;Load 0 to the "a" register
ld (CURCOL),a ;Setting Y coordinates
ld a,0 ;Loading 0 to the "a" register
ld (CURROW),a ;Setting X coordinates
ld hl,txtTIAsm ;Display text from the TIAsm label
bcall(_puts) ;Put text on screen
res textInverse,(iy+textflags) ;Resets the text inverse
ret ;Return to OS
txtTIAsm:
.db " TI-83 Plus Asm ",0 ;Text to be displayed on screen
.end
END

New Commands Used

set - z80 instruction that sets the characteristics of the TI

res - z80 instruction which will reset the characteristic

textinverse - Inverse text mode of the TI

textflags - You don't need to know this yet

 

Tutorial 8
Using Getkey to Detect Key presses

Overview

This will show you how to use the _getkey ROM call

What is _Getkey?

_Getkey is a ROM call similar to it's TI-Basic counterpart command, getkey. Getkey waits for a key press from the key pad. Then, depending on what you want to do, getkey can display the key code of the key pressed, execute another command, or act like a program pause.

Programming

This program will use _getkey as a program pause.

#define B_CALL(xxxx)	rst 28h \ .dw xxxx 
#define B_JUMP(xxxx) call 50h \ .dw xxxx

_clrlcdfull =4540h ;The ususal constants and defines, look at the
;New Commands section for more information
_homeup =4558h
_getkey =4972h

.org 9D95h

B_CALL(_homeup) ;Call up home screen
B_CALL(_getkey) ;Pause until next key press
B_CALL(_clrlcdfull) ;After key press, clear screen. Or you can use
;any other clear screen command (Tutorial 3)
ret ;Return to being a good old calculator

.end
END

New Commands

_getkey - Detect key press, store key code if nessasary

Programming

We will make our own program that displays the Hex key code of the key pressed.The code for the program is here. It looks complicated, but it really isn't. I'll comment the program along the way so you don't get lost. An important concept is the "stack". The stack holds numbers for future use or reference. In this program, it holds the hex code of each key pressed.

#define B_CALL(xxxx)	rst 28h \ .dw xxxx 
#define B_JUMP(xxxx) call 50h \ .dw xxxx

_clrlcdf =4540h ;The ususal constants and defines, look at the
;New Commands section for more information
_homeup =4558h
_puts =450Ah
_putc =4504h
_getkey =4972h
_newline =452Eh


.org 9D95h

B_CALL(_clrlcdf) ; clear screen
B_CALL(_homeup) ; home the cursor
ld hl,txt1 ; Display the message at the txt1 label
B_CALL(_puts)
B_CALL(_getkey) ; Detect key press
push af ; Save key press in register a
B_CALL(_clrlcdf) ; clear screen again
B_CALL(_homeup) ; home again
ld hl,txt2 ; Display msg2
B_CALL(_puts) ; Display text
pop af ; restore reg a
call dishex ; Follow commands at label dishex to find hex key code
B_CALL(_getkey) ; pause until next key press
B_CALL(_newline) ; Move cursor to next line
ret ;Return to TI-OS

dishex: push af ; keep copy of value
and 0F0h ; terminate lower nibble
rra ; shift nibble right 4
rra
rra
rra
ld l,a ; Display the Key's hex code in Str1
ld h,0
ld de,hexStr
push de ; keep for other nibbler
add hl,de ; add offset to hexStr address
ld a,(hl) ; find correct ASCII character from string below to
; display hex code of key pressed.
bcall(_putc) ; display character
pop de
pop af
and 0Fh ; wipeout upper nibble
ld l,a
ld h,0
add hl,de
ld a,(hl)
bcall(_putc)
ret ; Return to OS

hexStr .db "0123456789ABCDEF" ;These are the characters used to display
;the key's hex code
txt1 .db "Push a key.",0
txt2 .db "Key code: ",0

.end
END

New Commands

_putc - Display character and advance cursor
push - Pushes a number on to the stack.
pop - Takes a number off the stack.
call - This looks like the TI-83 macro, and serves almost the same purpose, only for the TI-83 Plus, it jumps the program to a specified label.

Conclusion

This program wasn't exactly "lightning fast". That's because the _Getkey command was scanning the entire key pad for a key press. Later on, we will make a program like this one, only we'll narrow down the area in which _Getkey looks in for a keypress, making it faster.

 


The comments below are written by ticalc.org visitors. Their views are not necessarily those of ticalc.org, and ticalc.org takes no responsibility for their content.


Re: Feature: TI-83 ASM Tutorial (Part 2)
Hieu-Trung Le  Account Info
(Web Page)

Dang, this is a very nice article. man you taught me a lot from these two article. Ijust started learning Z80 programming so this really helped =)

btw, sorry this is off topic, but anyone knows where to download Megacar fthat works or ti89 hardware one ams 2.03? ti-fr used to have it on their webpage but they removed the old programs off the lists... anyone knows where to download it?
thanks

     12 April 2000, 03:37 GMT

Re: Feature: TI-83 ASM Tutorial (Part 2)
cajunguy  Account Info
(Web Page)

Ha! Second comment!

Just had to try that out. :)

I own both a TI-83 and a TI-89, and I have found (because of my experience in C and C++) that ASM for the TI-89 is considerably easier. Maybe someone (not volunteering myself) should make a compiler for C to TI-83 ASM, if possible. Anyhow...

     12 April 2000, 05:10 GMT


Re: Re: Feature: TI-83 ASM Tutorial (Part 2)
Patrick Davidson  Account Info
(Web Page)

Actually, there already is such a program in the ticalc.org archives

" TI-83 and TI-86 Small C Beta 4"

dos/asm/8xccb.zip

This compiler actually does work. There is a newer version than this on the author's web page. However, it does not generate very good code, so its output will be significantly slower and larger than something written directly in assembly. Also, its function declarations have to be done differently from normal C, but this isn't much of a problem to deal with. It does allow in-line assembly.

     12 April 2000, 05:40 GMT


Re: Re: Re: Feature: TI-83 ASM Tutorial (Part 2)
cajunguy  Account Info
(Web Page)

Thank you much. I tried Chaos assembler for the TI-83, and couldn't get many programs to work. Thanks a lot!

     13 April 2000, 04:52 GMT


Re: Re: Re: Re: Feature: TI-83 ASM Tutorial (Part 2)
mnugter
(Web Page)

I have a question about c/C++. I know a little c++ but is it the same as C or are there different commands?

Greetings,
Michiel

     14 April 2000, 20:16 GMT

Re: Re: Re: Re: Re: Feature: TI-83 ASM Tutorial (Part 2)
cajunguy  Account Info
(Web Page)

Actually, there is really no difference in the commands, however, some things are different in C. One thing is that you need to include at least 1 header and only 1 header. In C++, you must include the headers that the commands are in. Sorry if this is not all clear. If you need anything more, use my email hyperlink above.

     16 April 2000, 02:46 GMT


Re: Re: Re: Re: Re: Re: Feature: TI-83 ASM Tutorial (Part 2)
Chris Black  Account Info

all i want to know (from anyone) is how to use the archive and uuarchive command in asm to unarchive programs. THAT IS ALL CAN SOMEONE PLEASE DO A TUTORIAL ON THAT?
EMAIL ME AT hijinkz@crosswinds.net

     18 April 2000, 03:25 GMT


C++ versus C
Daniel Bishop  Account Info

C++ is essentially the same as C. You should be able to compile any C program with C++ without any problems. However, C++ has some commands C doesn't. For example:

/* a C program */
#include <stdio.h>
#define pi 3.14159
void main()
{
printf("pi=%.5f\n", pi);
}

// The same program in C++
#include <iostream.h>
#include <iomanip.h>
const float pi = 3.14159;
void main()
{
cout.setf(ios::fixed);
cout << "pi=" << setprecision(5) << pi << endl;
}

There are more differences between C and C++, mainly that C++ is an OOP language and C isn't. I won't explain them here because I don't want to turn this message board into a C++ lesson.

     20 April 2000, 19:09 GMT

Re: Feature: TI-83 ASM Tutorial (Part 2)
Samir Ribic  Account Info
(Web Page)

Intel 8080 and Zilog Z80 are not same processors. Yes, binary code for Intel 8080 can work on Zilog Z80, but Z80 has many additional instructions.

Also, while Z80 has very nice mnemonics, Intel 8080 has horrible. The example above is written in Z80 mnemonics.

     12 April 2000, 11:14 GMT


Re: Re: Feature: TI-83 ASM Tutorial (Part 2)
ComputerWiz  Account Info
(Web Page)

he didnt say they were the same thing he said that the z80 was based on the 8080, if he had said they were the same thing now then he would look stupid lol

"When the Z80 was developed by Zilog (A renegade group of Intel engineers), it was highly based off of the Intel 8080"

     12 April 2000, 12:19 GMT


Re: Re: Re: Feature: TI-83 ASM Tutorial (Part 2)
Free_Bird Account Info
(Web Page)

Yeah but TASM doesn't assemble 8080 code. The Z80 really has some major enhancements, especially concerning ports.

     12 April 2000, 20:35 GMT

Re: Feature: TI-83 ASM Tutorial (Part 2)
acr34  Account Info
(Web Page)

Hi!
Great article, but I was wondering if you could include 3 things:

1) How to display the contents of a register to the screen
2) How to use program writeback
3) How to create a program on the calc and write and read stuff from it.

     12 April 2000, 12:49 GMT


Re: Re: Feature: TI-83 ASM Tutorial (Part 2)
Nick Disabato  Account Info
(Web Page)

If my memory serves me right (which it tends not to this late in the week), we covered writeback in a previous feature.

Check /archives/news and ctrl-F for "write."

--BlueCalx

     12 April 2000, 14:44 GMT


Re: Re: Re: Feature: TI-83 ASM Tutorial (Part 2)
Scott Noveck  Account Info
(Web Page)

I'm not sure how applicable some of these things are to all the calcs, though - that writeback routine, for example, is 86 only I think; these lessons are for the 83 and I have no clue which calc the poster is asking about.

     12 April 2000, 19:22 GMT

Re: Feature: TI-83 ASM Tutorial (Part 2)
Gockies  Account Info
(Web Page)

This is one of the best (screw that- THE best) asm article for either the 83 or 83+. It does a good job of explaining stuff in basic layman's terms and all. Will there be a part 3?

Also (this is off topic...) since you did a news article for Pi day (3/14) are you gonna do one for national weed day (4/20)??? Just outta curiosity...

     12 April 2000, 23:36 GMT


Re: Re: Feature: TI-83 ASM Tutorial (Part 2)
Nick Disabato  Account Info
(Web Page)

I don't smoke weed.
Maybe I should post one for anti-Pi Day (4-13)...

--BlueCalx

     12 April 2000, 23:57 GMT


Re: Re: Re: Feature: TI-83 ASM Tutorial (Part 2)
omotai  Account Info
(Web Page)

I just wanted to comment, this is an excellent tutorial but does Jeff Chai think it could be tuned to the Ion standard. I mean Ion is the defacto 83+ standard. By the way, wasn't he the Win95 Cih virus guy? Oh well, let bygones be bygones. Please edit this to Ion format if possible and make the best Ion tutorial. Thanks for your hard work.

     13 April 2000, 00:51 GMT

Re: Re: Re: Re: Feature: TI-83 ASM Tutorial (Part 2)
Nick Disabato  Account Info
(Web Page)

He was the "CIH guy," but it was much more our fault. So we won't hold it to him. :)

--BlueCalx

     13 April 2000, 01:27 GMT


Re: Re: Re: Re: Feature: TI-83 ASM Tutorial (Part 2)
David Hall  Account Info
(Web Page)

Problem with Ion is I find it soooo unstable. I just use SOS 2 instead... :)
Maybe in time it won't crash every 30 minutes....

     13 April 2000, 19:51 GMT

Re: Re: Re: Re: Re: Feature: TI-83 ASM Tutorial (Part 2)
Matthew Hernandez  Account Info
(Web Page)

I don't know what YOU do with your calculator and ION, but it doesn't crash EVER on my calc (83 or 83+)!

Matt H.

     15 April 2000, 19:07 GMT


Re: Re: Re: Re: Re: Feature: TI-83 ASM Tutorial (Part 2)
mnugter
(Web Page)

I had that problem too, I just kept using it and it's very stable now, I have no idea why it was unstable at first. I only use Ion now, I think it's the best Gui ever for the ti83(+)

     15 April 2000, 19:18 GMT

1  2  

You can change the number of comments per page in Account Preferences.

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