flat assembler
Message board for the users of flat assembler.

Index > Non-x86 architectures > FASM for Zilog Z80 CPU

Goto page Previous  1, 2, 3  Next
Author
Thread Post new topic Reply to topic
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 09 Jan 2012, 01:19
So - now solution found for the () [] syntax problem. Cool
In fact both syntax requirements
LD A,(HL)
LD A,[HL]
are supported and can be mixed together.

Before releasing the first version I want to do some cleanup of my code because now I found some better way for syntax interpreting than my very first adaptions. With the time I got deeper in the code and finally had a routine in preprocessing code to change () in [] before compiling the code. Anyway code is saved via file system like it was entered before, so if written with () it is saved this way but changed to [] just before compiling the code, so no more errors.

Even complicate expressions like

LD A,(IX-2*(3+1)+(10h-(5+3)/2))
are interpreted correctly.
Or whatever calculations people like to code in the lines.
It is just changed to
LD A,[IX-2*(3+1)+(10h-(5+3)/2)]

So in a few days (after cleanup) the code will be available in beta release.
After testing it in some projects and with some source code found wherever in the world and possibly corrections it could be a final (well tested) version.
Very Happy
Post 09 Jan 2012, 01:19
View user's profile Send private message Send e-mail Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 15 Jan 2012, 00:14
So here is a first version of FASM for Z80. Cool

The instruction set is fully implemented and tested against Z80 documentation.
So here I have to warn to use original document on Zilogs Website called UM0080.
http://www.zilog.com/docs/z80/um0080.pdf
This document has several errors in coding the instructions, mainly copy & paste errors while forgotten to edit the pasted code. I mailed the errors to Zilog in novembre and got some positive feedback and thanks but this document on the webserver is still unchanged.

If you want to check please use this older document, called PS0178 which is only a PDF with scanned datasheet but the content is correct. The other one was new typed in good quality but with several mistakes.
http://www.zilog.com/docs/z80/ps0178.pdf

In the next days and weeks I will test this version against other cross assemblers with some big source listings. In my eyes the compiler is correct and all statements tested manually but you never know. So this is a pre release and marked with a special version string in the window title.
"1.69.35.testversion-for-z80". And this version supports only Z80 instruction set and all preprocessor and macro definitions defined for the original FASM (x86 version).

Zilog has a special syntax which is different from Intel syntax regarding memory referencing. Intel used [] for referencing memory while Zilog uses (). Due to compatibility to already written source code and to other cross assemblers this version supports both writings, either [] or (). I hope the code is intelligent enough to distinct immediate calculations with () in most cases but not sure for any possible (thinkable) case.

Here are all versions (WIN / DOS / LIBC / LINUX) posted in one ZIP archive.
It contains the actual version 1.69.35 of FASM (but changed for Z80).
Tomorrow I will poste a short tutorial how to update / integrate this instruction set in later (newer) versions of FASM.

I would appreciate any feedback, especially found errors with (maybe partly) source and what the result (output binary) should be. Wink


Description:
Download
Filename: FASM_1.69.35_Z80.zip
Filesize: 514.7 KB
Downloaded: 1121 Time(s)

Post 15 Jan 2012, 00:14
View user's profile Send private message Send e-mail Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 18 Jan 2012, 13:28
Here I have an instruction manual how to implement Z80 instruction set in newer version of FASM. Now it is implemented in the last version 1.69.35 or maybe somebody have for particular reason changed something in FASM.

By the way I corrected one error because syntax change from () to [] was prohibited when using definition like

db 10h dup('0ffh')

but only for db because funtion was looking for db definition only. The following definitions would give errors:

dw 10h dup('0ffh')
dd 10h dup('0ffh')
dq 10h dup('0ffh')

and so on. Now I am prooving for the 'dup' function not for db instruction.
Because of futher testing I do not post a new version by now, think have to change maybe more but not sure. I want to avoid inflation of version. So keep this information as a known error.


Description:
Download
Filename: How to change instruction set from x86 to Z80 in FASM.pdf
Filesize: 11.93 KB
Downloaded: 2590 Time(s)

Post 18 Jan 2012, 13:28
View user's profile Send private message Send e-mail Reply with quote
TmX



Joined: 02 Mar 2006
Posts: 841
Location: Jakarta, Indonesia
TmX 18 Jan 2012, 16:48
Looks interesting.
Can I use this on simulator? I don't have any Z80 devices.
Post 18 Jan 2012, 16:48
View user's profile Send private message Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 18 Jan 2012, 17:50
Sure, if you have a simulator for Z80 you can create binary code and let it run on the simulator.
Now I am testing and I found some errors in some cases.
So I will update this version in a few days.

Errors:

EX AF,AF' not supported, workaround use EX AF,AF
If possible avoid use of $ as this could cause some errors when compiling when using special values.

LD ($400C),A gives error, workaround use LD (400Ch),A

INC (HL)
INC (IX+n)
INC (IY+n)

not work, same with DEC

Workaround: use [] instead of ()

So I found some side effects when changing syntax written before.
All solved by now but I want to do more testing with Z80 source listings.
These errors are found when compiling, so don't worry about code written into binary (is correct after successful compiling).
Post 18 Jan 2012, 17:50
View user's profile Send private message Send e-mail Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 18 Jan 2012, 23:59
problem with () for mem addresing is:
example in x86
Code:
mov eax,[10+90];here, ok, it is memory
mov eax,(10+90);hem, immediate or memory, really confusing syntax...
mov eax,10+90 ;here, ok, it is immediate
    

that's just a question of syntax. if human cannot determine what it is, how a machine can do?

syntax is not the cpu, nor it is the obsolete documentation about obsolete hw. then at least, you can try to strictlly use [] for memory in assembler. it is a very nice way to code it also, [] looks really like a memory case. () looks more like bubbles in comics, then is good for algebric expressions.
Post 18 Jan 2012, 23:59
View user's profile Send private message Visit poster's website Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 19 Jan 2012, 14:25
I think you never programmed a Z80 processor before, otherwise you would not think this way and would not ask these questions. Wink

Code:
mov eax,[10+90];here, ok, it is memory
mov eax,(10+90);hem, immediate or memory, really confusing syntax...
mov eax,10+90 ;here, ok, it is immediate
    


It is not really confusing, Z80 supports for memory addressing only 2 forms, one with registers and one with a 16 Bit immediate.

here are register options
LD A,(HL)
LD A,(IX+5)
LD A,(IY-7)

or a 16 bit memory address without register
LD BC,(1234h)
LD (5678h),SP

As there is no register in the last two instructions, this is a memory referencing. For immediates, there are no brackets expected. I think people did calculation in assembler not in the line for memory movement and should use a variable.

Problematic is only use of obselet brackets with numbers, which maybe interpreted as memory referencing but meaned are immediate values.

LD BC,55AAh is immediate
LD BC,(55AAh) is memory referencing
LD BC,(1010h+40h)*2 is immediate
LD BC,((1010h+40h)*2) is memory referencing

Thats the way the parser works. Checks for value in brackets (without any other data/variable outside brackets). What it makes complicate are some optional white space in the code. But I could improve the parser in a few days. With respect, this is the first version. FASM also wasn't build in one day ore one week or one month. Rolling Eyes

LD A , ( HL )
LD A, ( IX + 5 )

And it makes not much sense to tell Z80 programmers what syntax has to be used (this would reduce acceptance of FASM for Z80 developments significantly) and it is not compatible to existing source (which would also reduce acceptance significantly).

Take a look at this listing.
http://www.wearmouth.demon.co.uk/zx81.htm

This will not work with the last uploaded code due to some corrections but I want to do further testing before releasing an official version. After some modifications last night this is compiled correctly the only thing is to change the 3 defines in the source (which are made for TASM).

#define DEFB .BYTE ; TASM cross-assembler definitions
#define DEFW .WORD
#define EQU .EQU

change to

define DEFB db
define DEFW dw
; define EQU (comment out)
define .END (undefine .END as there is no statement for FASM)

Maybe this could also be changed using a macro, if one macro expert want to help, any help is appreciated.

FASM now accepts the coding for binary values like this

%00011100

which is internally changed to

00011100b

So I will keep on testing more this week and maybe post a release candidate on sunday evening. Wink
Post 19 Jan 2012, 14:25
View user's profile Send private message Send e-mail Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 19 Jan 2012, 14:50
Quote:
syntax is not the cpu, nor it is the obsolete documentation about obsolete hw. then at least, you can try to strictlly use [] for memory in assembler. it is a very nice way to code it also, [] looks really like a memory case. () looks more like bubbles in comics, then is good for algebric expressions.

+
no need to code with to see the uglyness of this syntax, that's all.
Post 19 Jan 2012, 14:50
View user's profile Send private message Visit poster's website Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 20 Jan 2012, 12:22
edfed wrote:

+
no need to code with to see the uglyness of this syntax, that's all.

Maybe - but this is not your choice. I think even MS OSes are ugly designed but who cares ? Take it or leave it - the same with Z80. Maybe it's not the CPU for you. Rolling Eyes

But [] is still supported for memory referencing. Wink
Post 20 Jan 2012, 12:22
View user's profile Send private message Send e-mail Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 20 Jan 2012, 13:06
yes, even if somebody will rewrite z80 syntax using same opcodes (similar like z80 inherits same i8080 opcodes with different mnemonics) - who then will use it: incompatible and confusing? Wink
Post 20 Jan 2012, 13:06
View user's profile Send private message Visit poster's website Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 20 Jan 2012, 13:36
Not sure what you mean but I will name [] support for memory addressing the "edfed-feature". Very Happy

But now I found some more complex situations.
1. Use of undocumented (non-official but working) opcodes found in one source of the ZX Spectrum
2. Use of labels without ':' found in one big listing -

Don't know by the way if these points are supported in other Z80 cross assemblers. Shocked
Post 20 Jan 2012, 13:36
View user's profile Send private message Send e-mail Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 20 Jan 2012, 15:42
So here I publish the first release of FASM for Z80 instruction set.
Some errors where removed/corrected and was tested with some big source code listings:

Sinclair ZX80 rom listing
http://www.wearmouth.demon.co.uk/zx80.htm

Sinclair ZX81 rom listing
http://www.wearmouth.demon.co.uk/zx81.htm

Jupiter Cantab Ace rom listing
http://www.wearmouth.demon.co.uk/ace.htm

Sinclair ZX Spectrum IF1 rom listing
http://www.wearmouth.demon.co.uk/if1_2.htm

The output binary was prooved against delivered binaries (rom codes) of the emulator EightyOne (EO), well known for 80's computer developpers. The binary from the source code extracted from this FASM version are 100% identical.
http://www.aptanet.org/eightyone/

There are now 2 points open:

1. Only the official instruction set of Z80 is implemented now.
Has some undocumented instructions which maybe added later.
These instructions work on the CPU's but never official published by Zilog.

2. I found some source code listings which use labels without ':' character at the end. So this could be fixed by the pre-pre-processor Cool to interprete all as label what starts at the first character of a line and expect minimum one whitespace character before entering instructions. In fact I am not 100% sure of it and asked some people very familiar with Z80 programming what they think about it and what other cross assemblers support.


Description:
Download
Filename: FASM_1.69.35_Z80_V1.0.zip
Filesize: 682.41 KB
Downloaded: 1181 Time(s)

Post 20 Jan 2012, 15:42
View user's profile Send private message Send e-mail Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 22 Jan 2012, 17:57
i ment let it be as is Wink is Z80 syntax good or not - we can not change the past Wink
Post 22 Jan 2012, 17:57
View user's profile Send private message Visit poster's website Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 22 Jan 2012, 19:24
Yes thats the point. Wink
Post 22 Jan 2012, 19:24
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20299
Location: In your JS exploiting you and your system
revolution 24 Jan 2012, 12:44
edfed wrote:
problem with () for mem addresing is:
example in x86
Code:
mov eax,[10+90];here, ok, it is memory
mov eax,(10+90);hem, immediate or memory, really confusing syntax...
mov eax,10+90 ;here, ok, it is immediate
    

that's just a question of syntax. if human cannot determine what it is, how a machine can do?

syntax is not the cpu, nor it is the obsolete documentation about obsolete hw. then at least, you can try to strictlly use [] for memory in assembler. it is a very nice way to code it also, [] looks really like a memory case. () looks more like bubbles in comics, then is good for algebric expressions.
Note that many of the old Z80 assemblers did not support expression calculations so this was never a problem in the past. In those days a programmer had to pre-evaluate all values before typing them into the editor, the assembler could not compute expressions. shutdownall has had to make a decision as to how to handle expressions and still allow the () syntax for memory addressing, no easy decision at all.
Post 24 Jan 2012, 12:44
View user's profile Send private message Visit poster's website Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 09 Dec 2012, 14:47
So here is a new version of FASM for Z80, right before christmas. Very Happy

I updated to the newer version 1.71.01 as this supports more flexibility for using virtual address spaces (copying codeblocks across). So this will be the base for my ZX81 IDE supporting mixed Z80 assembler and ZX81 BASIC instrucitons. Nothing to worry about, this version supports Z80 assembler only.

I have some instructions/informations added in a README.TXT printed here for first information:

Quote:

This is the original flat assembler from Tomasz Grysztar adapted for Zilog Z80 CPU.
It's based on version 1.71 and instruction set is modified to support of
Z80 instructions only. This version supports only the base instruction set
used in the 80's, today common for retro programming.

There will be maybe in future or on special request from user at the board
an extended version with support of the undocumented instructions still
working but not official released by Zilog (use of IX or IY register for nearly
all instructions where HL could be used) or which supports some newer commands
from the Z84xx series. For me is no need at the moment as I am working with
plain old Z80 processor.

Please take notice that this version does support ONLY Z80 instruction set and
all x86 commands are deleted to keep it tiny, reduce the work of creating this
version. Nearly all directives, data types and commands are kept, especially the
helpful and powerful macro definitions. This version is for people who like the
concept of FASM and maybe worked with another version of FASM before. Very easy
to start with.

For compatibility to old listings I added a new feature which is named
"labelautodetect". Normally labels are marked by the word label or with a
colon following the label name. But styles are still working with this version
but there are some retro style listings missing this general label declaration.
To compile these assemler files you can add the following line at the top of file:

;labelautodetect

It was realised as a comment because it need to be present when running the
parser and could not realized as instruction because instructions are executed
only in assembler phase which is running after the parser.

There is another nice feature implemented in the IDE, generating an automatic
listing. The listing is based in general on the symbol file and there is a demo
program in the directory tools. I didn't find this very helpful as I like to have
it more integrated in the IDE and to get the listing simply with a keypress.
So I adapted the listing to the 8 bit processor and adjusted the width of columns
and you can get it while creating a symbol file with CTRL-F8. During this step or
lets say after the symbol file is created, the IDE runs automatically LISTZ80.EXE
and opens the created listing file (<source>.lst) in a new tab of the editor and
on the disk.

There are two more commands implemented as comments in source with
;LISTOFF
;LISTON
to switch listing on and off for the parts you need. These comments can be used
in any included file to keep a small effective listing to work with. LISTON is
default at compile, so if none of these comments are found, a complete listing
is generated. Be sure to set these commands always at the beginning of a line.


To do this all I have to thank Tomasz Grysztar for this great assembler
framework which is unfortunately undocumented - so was a bit hard to get
through the code sometimes. There are some papers published about concepts
but internal structures are undocumented except the symbol file format.
But to work with the delivered IDE, which is treated to use as it is, this
wouldn't be a convenient way. I don't like to work with command line tools and
the IDE is fine to program right out of the box and you have a small tiny editor
as one exe file only and not a few hundred files or dozens of configuration options.

To use this version you need only two exe files, which can be copied in a new
or in your source directory:
FASMWZ80.EXE
LISTZ80.EXE

That's really all. A configuration file FASMWZ80.INI is automatically created after
using FASMWZ80 first time. Anyway you can modify the software which is delivered in
source or adapt the command set. The SOURCE directory contains the main part of the
assembler, the IDE subdirectory contains the IDE main file FASMWZ80.AMS which is the
adapted FASMW.ASM from original source. There are command line versions for DOS,
WIN32 and LINUX available, which haven't been compiled yet but should work in the same
way. They could be compiled using the FASMW.EXE in the main direcory (x86 version).

Any comments could be placed at the board where you did find this version
http://board.flatassembler.net in section Non-x86-architectures.


Description: FASM version with support of Z80 instruction set
Download
Filename: FASM-Z80.zip
Filesize: 673.82 KB
Downloaded: 1024 Time(s)

Post 09 Dec 2012, 14:47
View user's profile Send private message Send e-mail Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 09 Dec 2012, 21:02
Sorry but found some bug during further tests in the preprocessor extension for supporting () memory referencing with () and []. Did not use the latest version.

And forgot to attach one source file found right now when tried to recompile.
So now it should be okay. Wink


Description: Update
Download
Filename: FASM-Z80.zip
Filesize: 675.46 KB
Downloaded: 1299 Time(s)

Post 09 Dec 2012, 21:02
View user's profile Send private message Send e-mail Reply with quote
prlaba



Joined: 25 Jul 2013
Posts: 3
prlaba 25 Jul 2013, 12:00
shutdownall,

I don't know if you're still following this thread, but I wanted to say thanks for the great job you did producing this z80 version of fasm! It's just what I've been searching for.

All seems to be working great except the automatic listing file feature described in your README file. When I used the 'Build symbols + listing' menu option (Ctrl+Cool, I end up with a binary (.bin) and symbol (.fas) file, but no listing (.lst) file. I can run LISTZ80.EXE from a command prompt to generate the listing file manually, but I can't seem to get the automatic listing to happen.

Both the FASMW80.EXE and LISTZ80.EXE executables are in the same directory, as instructed in the README file.

Any suggestions?
Post 25 Jul 2013, 12:00
View user's profile Send private message Reply with quote
prlaba



Joined: 25 Jul 2013
Posts: 3
prlaba 25 Jul 2013, 14:09
Here's an oddity I just ran into with FASMWZ80 re binary (.bin) files:

I initially tested shutdownall's FASMWZ80 assembler by creating a very simple 2-line Z80 program, then used the 'Build symbols + listings' menu option to assemble the program. It produced two files: a binary (.bin) file and a symbols (.fas) file (it did not produce a list (.lst) file as expected; see my previous post).

I opened the .bin file in a hex editor and confirmed that the file's contents were as expected.

I then took an existing and more 'complex' Z80 program source file and, after making a bunch of changes to match fasm's directives (it was originally written for a different assembler), opened it in FASMWZ80. When I used the 'Build symbols + listings' menu option to assemble the program, it produced a .com file (?) and .fas file, but no .bin file.

Huh?

Can someone explain why FASMWZ80 generated .bin and .fas files for my simple 2-line program, but generated .com and .fas files (and no .bin file) for my longer program?
Post 25 Jul 2013, 14:09
View user's profile Send private message Reply with quote
prlaba



Joined: 25 Jul 2013
Posts: 3
prlaba 25 Jul 2013, 14:19
I just answered my own question re the .bin file. It's the presence or absence of an 'org' directive in the source file that determines which file -- .com or .bin -- gets generated.

If the source file contains an org directive, then a .com file is generated. If no org directive is included, then a .bin file is generated.

Not exactly sure if this is a bug or by design, but that appears to be how it works.
Post 25 Jul 2013, 14:19
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.