Since I first learned Z80 assembly (and a
little bit of 6502) I find the instruction set very strange and different
than what I am used to. My intention is to help Z80 lovers love the
PIC too.
I have found two ways of writing PIC programs with Z80 like mnemonics.
One is to use TASM ant the other is to use the Frogbit text processing
language.
Take a look at the
modified
instruction set !!!
1.
Doing it with TASM
TASM
is a table driven shareware assembler.
Since it is table driven it can be used for many micros by adding new
tables. Current version of TASM comes with tables for Z80, 6502, 6800/6801/68HC11,
6805, 8048, 8051, 8080/8085, TMS32010, TMS320C25 TMS7000 and 8096/8019.
The table I modified to accommodate Z80 like syntax is by DERREN CROME.
I found that table on the Everyday Practical Electronics Magazine ftp
site along with an old copy of TASM. The code in the table below
is intended to flash a LED connected to Bit 0 of Port A. On the left
you see the code written in Z80 style and the PIC equivalent on the
right. The PIC equivalent was produced from the Z80 style code by a
small program I wrote in the Frogbit language.
Z80 style code
|
PIC equivalent produced by my Frogbit
program |
#include t16c84.inc
delayH .equ 0Ch
delayM .equ 0Dh
delayL .equ 0Eh
clr PORTA
set STATUS,rp0
ld 00011110b
ld TRISA,a
res STATUS,rp0
loop
set PORTA,0
call delay
res PORTA,0
call delay
jp loop
delay
clr delayM
ld 3
ld delayH,a
dloop
dsz f,delayL
jp dloop
dsz f,delayM
jp dloop
dsz f,delayH
jp dloop
ret
.end
|
#include t16c84.inc
delayH .equ 0Ch
delayM .equ 0Dh
delayL .equ 0Eh
CLRF PORTA
BSF STATUS,rp0
MOVLW 00011110b
MOVWF TRISA
BCF STATUS,rp0
loop
BSF PORTA,0
CALL delay
BCF PORTA,0
CALL delay
GOTO loop
delay
CLRF delayM
MOVLW 3
MOVWF delayH
dloop
DECFSZ delayL,F
GOTO dloop
DECFSZ delayM,F
GOTO dloop
DECFSZ delayH,F
GOTO dloop
RETURN
.end
|
The TASM table I created also supports Microchip
mnemonics and you can mix them with the Z80 style ones if you wish.
Since TASM supports many other micros, you will be able to work with
many micros in a familiar and proven environment.
Please note that there are some "problems" when using TASM
with the PIC micro.
- The TASM rule used in the table limits the
argument size to 7Fh and such an instruction will cause an error:
movwf 86h
and must be written as
movwf 06h
While these two instructions are identical
in hex, this may lead to confusion at times. The include file provided
has the correct values for the registers on Page 1. For this example
; TRISB is defined as:
TRISB .equ 06h
- TASM can produce an object file in many
formats but not in INHX8M, which is the format almost all pic programmers
and disasssmblers around use. The problem with the INHX8M format is
that the words use a low-byte/high-byte combination, while TASM generated
object file uses a high-byte/low-byte combination. I worked around
this poblem by removing the .MSFIRST directive from the table
and using TASM with the -o10 option. This produces the desired
object file but the list file produced is wrong because of the missing
.MSFIRST directive. For example the
CLRWDT command is listed as 64 00 ,while it is actually
00 64.
If a correct listing is desired a second table with the .MSFIRST
directive can be used.
I use TASM with these arguments in MicoAsm
-84 -i -o10 $(FileName).$(FileEx)
Download the latest version (3.1) : tasm31.zip
(184 Kb)
Download the MicroAsm editor to use TASM with Windows and error highliting
: uasm10.zip (324 Kb)
Download the modified 16F84 table and
the include file : table84.zip (2
Kb)
View the table online tasm84
2.
Doing it with Frogbit
Frogbit
is the name of both a programming language and of the tools used to
develop programs written in it.
It is a small programming language which is designed for the manipulation
of files and text. The syntax of the language is largely based on the
use of keywords rather than punctuation; this means that Frogbit programs
tend to be large but readable.
A well-featured IDE (integrated development
environment) is provided for the development of Frogbit programs. The
IDE has facilities for running, single-stepping and halting your program
and also supports breakpoints, expression watches and file-view windows
so that you can track intermediate results.
Once your program is debugged and working you can run it routinely using
the more convenient RUN tool which does not support the debugging features
of the IDE.
The Frogbit Language
Frogbit is a line-oriented language: each line consists of one or more
command words which may be followed by parameters. Command parameters
are usually (but not always) preceded by an identifying keyword. It
is often the case that parameters can be omitted and a default value
supplied by the system.
Like most programming languages Frogbit has variables for storing intermediate
results. Frogbit has only one sort of variable: the sort that holds
a string of characters. However, a Frogbit string can be as long as
you like (2 thousand megabytes is the theoretical limit) and you can
do integer arithmetic with numbers stored as strings.
You can make up expressions from variables, numbers and strings combined
with operators. Some operators are symbols like '+', '*' and '=' but
Frogbit also has a number of names used as operators, such as matches,
beginsWith and contains.
I wrote a small frogbit program to convert
Z80 style menmonics to PIC mnemonics. If the numbers are written according
to MPASM syntax (e.g. b'10110111' instead of 10110111b or d'25' instead
of 25 and so on...) the resulting code may be assembled using MPASM
and make the use of development tools that support that format. Please
note that I have not tried this with MPASM, but it must not be difficult
to do that.
Also, you can use this to share your code with others who do not use
the Z80 style mnemonics.
The table at the top of the page demonstrates a sample output of my
frogbit program.
Warning:
Do not put your labels on the same line with code, or they will be gone.
I have not worked on this yet. Also do not forget that this is a text
processing language and that everything is treated as text. I tested
the program many times and corrected any problems I have encountered,
but just be careful...
Download the latest version of Frogbit (1.01)
: frogbit_101.zip (957 Kb)
Download frogbit program to conver Z80 style mnemonics to PIC assembly
: z2p_V_01.zip (2 Kb)
The same of the above but will not add ";
no change made" to lines that have not been changed z2p_V_01_wout_nochangemade.zip
(2 Kb)
Here is a frogbit program to remove comments
from your assembly code: comment_remover.zip
(1Kb)
Frogbit is freeware, but TASM is not.
Visit Axiomatic Software,
makers of Frogbit,
For info on the PIC micro check out the sites
on the PIC
Micro Webring site, or see my PIC Links
page.
