z80:Getting Started with Asm

From Learn @ Cemetech
Revision as of 00:41, 3 February 2016 by KermMartian (talk | contribs)
Jump to navigationJump to search


Existing Tutorials

Here's a link to some tutorials that can get you started on learning assembly.

For more information, read on.

What is Asm?

What exactly is the z80 assembly language? I'm sure many of you who have roamed through the [*http://www.ticalc.org ticalc.org] archives, and have found an extensive library of z80 assembly programs. Before we learn how to program it, it is quite important to get an understanding of what assembly language is.

History of Computer Languages

Machine language

In the beginning of programming, programmers had to write code by manually setting on/off switches. Depending on whether the switch was set on or off, the computer would then do something. Obviously this form of programming is extremely time intensive and not very practical. Why did the 1st computer designers choose only 2 different elementary data types? It turns out that before micro processors, computers were designed to interpret signals through vacuum tubes, so the only method of communication was whether these signals were coming or not coming (hence the on/off idea). But enough about the basic elements of programming, on to...

Assembly language

Not long after the development of microchips came the development of compilers. These were primitive programs that took user inputs (the code) and turned them into on/off data that the computer could use. The basis of assembly language is the use of primitive operations to accomplish tasks more quickly than with writing in machine language, as well as develop a language that resembles native language (what you speak and write). One of these languages, called z80, is the basis of programming for the Texas Instruments (TI) series of graphing calculators, the TI-73, -82, -83, -83+, -84+, -86, etc. However, one of the problems with ASM programming is that it still lacked structured programming and syntax that more closely resembles native language. So, this led to...

Higher Level languages

The zenith of language design (at least for now), higher level languages provide a powerful mixture of structure as well as functionality. Examples of higher level languages include C, C++, Java, Pascal, and Visual Basic. Since higher level languages aren't included in the scope of this site, let's move on.

Assembly vs. TI-Basic

Why should anyone bother to learn assembly? How does assembly compare to TI-Basic? These questions will be answered in this section.

Advantages of Assembly over TI-Basic

  • Speed. If programmed correctly, assembly code can run many times faster than TI-Basic. This is because assembly code directly sends instructions to the processor or hardware, allowing for direct response.
  • Functionality. Because assembly can poll hardware and memory directly, it has a far greater functionality than TI-Basic. This allows assembly programmers to do things that TI-Basic programmers could only dream of.
  • Protection. Assembly programs can not normally be altered by a user. This prevents users from accidentally deleting crucial code from the program, as sometimes happens in TI-Basic programs. It also allows you to keep the source a secret if you ever wish to do so.

Disadvantages of Assembly over TI-Basic

  • Size. For the most part, assembly programs might be larger than TI-Basic programs. This is because TI-Basic programs are composed of tokens that take up ~1 byte each. These tokens are parsed on runtime to perform functions pre-programmed into the TI-OS, saving space in the actual program. On the other hand, assembly programmers have to manually code advanced functions by themselves, and sometimes will even re-write basic functions.
  • Learning curve. Because of the complexity of assembly, it has a rather high learning curve. In order to truly understand how to program efficient assembly code takes a great deal of effort.
  • Stability. Because assembly can change itself as well as anything else in memory, it is very unstable and very prone to crashes. Also, assembly programs do not have any way of error checking at runtime and you cannot normally break out of an assembly program. This results in having to reset the RAM many times. It is suggested that assembly programs be tested first on emulators before sending them to a real calculator.

Required stuff

It's almost time to start writing assembly code, but before you do, there is some necessary equipment that you will need.

  • Computer. This will be necessary to actually write the code. I will assume you have access to a computer if you are reading this.
  • Calculator. Necessary if you ever want to debug/test a program. Again, I will assume you have one.
  • Calculator-Computer link cable. Necessary if you want to transfer data between your computer/calculator.
  • Text Editor. You'll need this to write the code.
  • Compiler and Linker. Necessary to get change your code from assembly into machine language, then into a file that can be run on your calculator.

Integrated Development Environments (IDEs)

IDEs are programs that help you program, compile/link, and debug your program. Although not necessary for programming, it is recommended that you become familiar with a good IDE so that you can take your programming to the next level. Generally IDEs have a graphical user interface (GUI) that will allow you to perform tasks without having to type commands in. For more information on IDEs, see here.

Setup

If you are using an IDE, follow it's instructions on setting it up and skip the rest of this section. If not, and prefer to use the more common TASM setup, read on.

For those who want it, I've set up TASM for you. If you want, click [*http://z80-heaven.wikidot.com/local--files/getting-started-with-asm/asm.zip here] to get the zip file containing all the stuff you'll need. Just pick a folder to extract it to and you can skip the rest of this page. Or, if you want, read the rest just to get some basic information on setting up TASM.

Step 1: getting the necessary files

Here's a list of links for things you'll need:

Download all of them and put them all into a folder you'll use for all of your asm programming stuff (Example: "C:\Asm\")

Step 2: setting up the folder structure

Create 3 folders inside of "C:\Asm\" name "tasm", "exec", and "source". As the name implies, tasm is where all of the compile/linking stuff goes. So, move the three zip files you downloaded into it and extract them. If you want, delete the extra files included with the last one or move them somewhere else if you want to keep them. Keep everything else.

Step 3: changing the assembly batch file

For time's sake, right click on "asm.bat" in the tasm directory and click on 'edit'. then, remove everything and change it to this:

   echo Syntax: asm [NAME (w/o extension)] [PATH]
   
   @echo off
   echo ----- Assembling %1 for the TI-83 Plus...
   echo #define TI83P >temp.z80
   cd "..\source"
   if exist %1.z80 type %1.z80 >>temp.z80
   if exist %1.asm type %1.asm >>temp.z80
   move /y temp.z80 "../tasm"
   cd "..\tasm"
   tasm -80 -i -b -l temp.z80 %1.bin %2%1.xlt
   if errorlevel 1 goto ERRORS
   devpac8x %1
   copy %1.8xp %2%1.8xp >nul
   echo TI-83 Plus version is %1.8xp
   move %1.8xp "..\exec"
   goto DONE
   :ERRORS
   echo ----- There were errors.
   :DONE
   del temp.z80 >nul
   del %1.bin >nul
   del %1.xlt >nul


save and close "asm.bat".

Compiling

To compile your code, open up command prompt (start, run... command prompt) and navigate to the location where you extracted the zip file.

||~ Command Prompt instruction ||~ What it does || || cd "directory" || Look for folder "directory" (without quotes) and open it || || cd "directory1/directory2" || jump to directory2 inside of directory1 || || cd .. || Jump to the "parent" folder || || C:, Z:, etc. || Jump to a different hard disk || || dir || list all folders and files in the current folder you're in ||

Once you get to "../asm/tasm", type in "asm sourcename". sourcename is the name of your source file, which you put in "../asm/source". Don't include the ".z80" at the end.

If there were no errors during compilation, your program should be ready for you in the "..asm/exec" folder. Just send it to your calculator and run "asm(prgmname)".

Conclusion

That's all there is to setting it up. If you want to actually learn the z80 language, see the other topics in this section to get a glimpse of what it can do.