flat assembler
Message board for the users of flat assembler.
Index
> Non-x86 architectures > FASM for Zilog Z80 CPU Goto page 1, 2, 3 Next |
Author |
|
shutdownall 21 Nov 2011, 21:06
I think it's better to open a new thread to this.
I want to make a fasm version for Zilog's Z80 CPU as I found nothing comfortable in the internet and work quite a time with FASM which is a very good development tool. I just found this documentation: http://board.flatassembler.net/topic.php?t=208 Is this the right and maybe an easy way to implement a new instruction set ? |
|||
21 Nov 2011, 21:06 |
|
DOS386 23 Nov 2011, 14:28
You might want to remove all the existing x86 instructions and formats other than binary.
|
|||
23 Nov 2011, 14:28 |
|
shutdownall 24 Nov 2011, 17:06
Now I have one problem to solve.
Maybe somebody can help me (hopefully ). FASM uses [] for reg/mem or mem/reg addressing. In the Z80 manual the writing for such addressing is with (). Example: Code: mov ax,[bx] ; for intel ld A,(HL) ; for Z80 This looks maybe easy to sovle with a macro but could be more complex. Code: mov ax,[SI+5] ; for intel ld A,(IX+5) ; for Z80 There maybe exist complex calculations in some programs (I don't know how often such things are used ...) using () as well. Code: mov ax,[SI+((address1-address2)/2-(10*opsize))] ; for intel ld A,(IX+((address1-address2)/2-(10*opsize))) ; for Z80 I don't know if the last line is a valid syntax for Z80 assembly but for new developments this could be used. So I cannot replace all "(" with "[" and all ")" with all "]". It maybe has to be done in the context. This affects FASM in general as there is another concept of using () and []. Any ideas ? Maybe a macro specialist here So only the outer () should be replaced with [], beginning after the ",". Or before beginning of "," for mem/reg addressing but this could be another macro. First looking for ",(" and second for ")," (but then backwards). |
|||
24 Nov 2011, 17:06 |
|
shoorick 25 Nov 2011, 09:27
shutdownall wrote:
except properest way - to write a new assembler from scratch, you may choose from that easiest things: 1.look source of fasm for using of "[]" and "()" and swap them, then you might use this form for calculations: Code: ld A,(IX+[[address1-address2]/2-[10*opsize]]) ; for Z80 2.if such calculation was not valid - you may left fasm logic as is and use "[]" for indirect access, but then you will have to replace all "()" with "[]", when you wish to use already existing sources. it may appear not hard, but annoying, or even lead to troubles when "()" used in comments or as character values. _________________ UNICODE forever! |
|||
25 Nov 2011, 09:27 |
|
shutdownall 25 Nov 2011, 15:33
Maybe I have to do something in the "parse line" function.
It's only for lines with instructions. Here are some examples: LD A,(HL) => must be translated to LD A,[HL] LD A,(address-offset)*2 => must not be translated LD A,address*(sizebig-sizesmall) => must not be translated LD A,(address-offset) is not allowed since () is obsolete in this case, maybe could left untouched but maybe could cause an error. I don't know how to deep I am going in the source to do that. Probably I don't wanted but it's getting more and more. I thought about a solution like replace ( with [ and ) with ] under following conditions: ( must appear directly after the "," and ) must be the last char of the line except of comments. Or for the LD (HL),A vice versa. Would this be okay or did I forget some other cases not covered by my examples ? |
|||
25 Nov 2011, 15:33 |
|
shutdownall 26 Nov 2011, 18:45
So I skipped the problem with () and [] for the first step and integrated now all possible "movement" instructions (ld/push/pop). Has some more with EX (exchange) but Zilog does not list them under this section movements.
By doing it I found first error in the original Zilog Z80 document (from 2005). http://www.zilog.com/docs/z80/um0080.pdf The opcodes for POP IY are wrong. It's FD E1 and not as written DD FD (which are both prefixes for IX IY register set instead of HL. A possibly copy and paste error I think. Maybe I find more. But I did not proove it found just some irregularities in coding of this instruction. I hope to finish the first version with all commands before starting holiday in decembre. So I think you all can be sure to have a FASM version for Z80 - with some luck this year, if I could not spend too much time maybe in january. |
|||
26 Nov 2011, 18:45 |
|
typedef 26 Nov 2011, 20:30
maybe you can just make a parser that will parse from Intel (after compiling in FASM) to z80 instead of making a "feel" for the Z80
|
|||
26 Nov 2011, 20:30 |
|
shutdownall 26 Nov 2011, 21:59
typedef wrote: maybe you can just make a parser that will parse from Intel (after compiling in FASM) to z80 instead of making a "feel" for the Z80 I don't know what you mean. There are some really big differences between x86 and Z80. registerset is different, instructionset is different and syntax is different. If you want to avoid errors in written code like unallowed register combinations, unallowed offsets and many more it does not make sense to compile Z80 code with FASM for x86 instruction set and after change the coding. |
|||
26 Nov 2011, 21:59 |
|
shutdownall 27 Nov 2011, 22:35
By doing it I found second error in the original Zilog Z80 document (from 2005).
http://www.zilog.com/docs/z80/um0080.pdf The opcodes for XOR s are wrong. These are just copied from OR s without change. Have an older manual from Zilog which was scanned only as PDF, the newer document as plain text PDF is new written by somebody I think. |
|||
27 Nov 2011, 22:35 |
|
shutdownall 28 Nov 2011, 00:12
status:
finished now additional all => exchange instructions => block instructions => 8-bit arithmetic instructions => general purpose arithmetic & cpu controls I think about 50% of commands implemented now. |
|||
28 Nov 2011, 00:12 |
|
shutdownall 29 Nov 2011, 23:41
added:
=> 16-bit arithmetic instructions => all shift and rotate instructions to be done: => bit instructions => jump instructions => call instructions => in/out instructions I think implementation now finished about 70%. |
|||
29 Nov 2011, 23:41 |
|
shutdownall 01 Dec 2011, 10:57
Due to holiday this will be continued in about 4 weeks.
I tried coding BIT 0,A instruction which is a bit tricky and now not have too much time to go deeper into it. Z80 version should be available beginning of january, with luck maybe this year but not sure. |
|||
01 Dec 2011, 10:57 |
|
flaith 02 Dec 2011, 12:48
Thanks for your work shutdownall
_________________ Je suis sur de 'rien', mais je ne suis pas sur du 'tout'. |
|||
02 Dec 2011, 12:48 |
|
shutdownall 03 Jan 2012, 00:08
So now I continue working on the Z80 version.
Bit instructions coded today. So now still open: => jump instructions => call instructions => in/out instructions Should be implemented soon, have enough time this week. |
|||
03 Jan 2012, 00:08 |
|
shutdownall 05 Jan 2012, 22:37
So now the complete instructionset of Z80 is fully implemented.
The only open point is to interprete the ZILOG syntax with LD A,(HL) LD A,(IX+4) which FASM expect as LD A,[HL] LD A,[IX+4] But calculations with () have to be untouched like LD A,(varx+5)*varsize for example (which is an immediate instruction with a variable). So the first step is done, if I changed the above described problem I can post the first version here. So now it's not far away. |
|||
05 Jan 2012, 22:37 |
|
JohnFound 06 Jan 2012, 07:53
Hm, why not to leave it as it is. All FASM users are accustomed to the square brackets meaning indirect addressing.
The round brackets was in use in the ancients times, so IMHO it is time for small modernization of the syntax. |
|||
06 Jan 2012, 07:53 |
|
shutdownall 06 Jan 2012, 13:27
I don't think so because an assembler has to be compatible to the preferred syntax in manuals AND (more important) has to translate existing programs without any change. Anyway, Z80 is complete different to x86 and you maybe need a manual first to see which registers are allowed for which operation (with ZILOG syntax, of course).
And the use of [] for memory addressing from Intels x86 is not a standard in general - just a defined (proposed) syntax from Intel. But more horrible is the AT&T syntax in my eyes. I think any experienced Z80 programmer would not use [] instead (). And any FASM x86 programmer has to learn Z80 first to develop good and efficient programs. MAYBE (but only maybe) I can find a solution to use both syntax elements, () and [] for same purpose. Anyway if you are programming Z80 you have to think like Z80 in Z80 structures and registers. And maybe it is a good idea to keep the syntax different to avoid instructions not available. |
|||
06 Jan 2012, 13:27 |
|
edfed 06 Jan 2012, 20:48
even if pure z80 programming is using (), now, we are in 2012.
very nice project, i want to do the same for any CPU i can programm (not a lot for the moment), and franckly, even if the prehistoric code is in old syntax, i'd prefer to modify everything by hand with new syntax than to code any line in old syntax. keep it up. sega genesis have a z80 to control the sound, and a 68k as main cpu, it can be nice to code for this one too |
|||
06 Jan 2012, 20:48 |
|
shutdownall 06 Jan 2012, 23:21
As pointed out, Z80 syntax is not prehistoric and [] are not a standard.
Every developer of new CPU types defines the syntax to be used. Keep a look at AT&T syntax, by the way I don't know if FASM support the AT&T syntax. I never used it and it is the first and only CPU with two total different coding syntax. I think people learned from that problem. The best way is to have only ONE syntax. And the syntax belongs to the CPU - not to the assembly coder. Anyway I try to fulfill both ways use of either () or []. And to point this out: This is a separate version of FASM which ONLY supports Z80 instruction set, no mix possible between Z80 and x86 code (!). I even can not see any reason for support of both CPU's in one FASM.EXE. I think this could be done with mixing code but this would be extra work to melt both structures in one program. And it's really more complicate to do syntax check. I will also write a manual for adapting new CPU types and how to handle them in FASM. As Tomasz had never time to write that down (only one very old document with some few hints). |
|||
06 Jan 2012, 23:21 |
|
Goto page 1, 2, 3 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.