Z80 asm/disasm in Z80 asm [solution found]

The place for codemasters or beginners to talk about programming any language for the Spectrum.
User avatar
ketmar
Manic Miner
Posts: 207
Joined: Tue Jun 16, 2020 5:25 pm

Z80 asm/disasm in Z80 asm [solution found]

Post by ketmar »

does anybody have standalone Z80 assembler and disassembler modules written in Z80 asm? i don't need advanced things, just a code to disasm one command, and to asm one command. speed is not a concern, but size is -- the smaller the thing, the better. there are alot of sources for various Speccy assemblers and disassemblers, but it is quite hard to extract the relevant code from there. sure, i can write it myself, but maybe somebody already did it, and wiling to share the code?

the idea is to incorporate those into my dsForth system, so ideally asm should take a buffer (and maybe callback to get label value), and produce machine code. and disasm should take a pointer, and produce disassembled string.

p.s.: readable and commented source code would be great. ;-)
0 x

dom
Berk
Posts: 6
Joined: Sun Feb 10, 2019 11:08 am

Re: Z80 asm/disasm in Z80 asm, request

Post by dom »

For a disassembler try this one: https://github.com/z88dk/z88dk/blob/mas ... disz80.asm - it's just over 1k in size so definitely one of the smaller ones. The code was extracted from Utility3 but the history goes back further than that.

Can't help with an assembler unfortunately.
1 x

User avatar
ketmar
Manic Miner
Posts: 207
Joined: Tue Jun 16, 2020 5:25 pm

Re: Z80 asm/disasm in Z80 asm, request

Post by ketmar »

thank you alot! i'll take a look at it.
0 x

User avatar
Einar Saukas
Dynamite Dan
Posts: 1437
Joined: Wed Nov 15, 2017 2:48 pm

Re: Z80 asm/disasm in Z80 asm, request

Post by Einar Saukas »

dom wrote:
Thu Aug 06, 2020 10:46 pm
For a disassembler try this one: https://github.com/z88dk/z88dk/blob/mas ... disz80.asm
This listing says:
The SUBSET editor David Barrow was able to trim only one byte from John Kerr's compact code. I've forgotten where so there's a challenge.
Right at the beginning:

Code: Select all

cp 255
jr nz, dizloop
It can be replaced with:

Code: Select all

inc a
jr nz, dizloop
1 x

User avatar
ketmar
Manic Miner
Posts: 207
Joined: Tue Jun 16, 2020 5:25 pm

Re: Z80 asm/disasm in Z80 asm, request

Post by ketmar »

the magic spell "shorten this code" always makes Einar to appear with the solution. ;-)
0 x

dom
Berk
Posts: 6
Joined: Sun Feb 10, 2019 11:08 am

Re: Z80 asm/disasm in Z80 asm, request

Post by dom »

[laughs] I have a feeling that bit of wrapper code isn't part of the "challenge". I think that code is actually trying to disassemble the following instruction, but the push ix gets in the way of that.
0 x

User avatar
Einar Saukas
Dynamite Dan
Posts: 1437
Joined: Wed Nov 15, 2017 2:48 pm

Re: Z80 asm/disasm in Z80 asm, request

Post by Einar Saukas »

Replace this:

Code: Select all

.XTRACT
	or a
	jr z,COPY
.SKIP
	bit 7,(hl)
	inc hl
	jr z,SKIP
	dec a
	jr nz,SKIP
.COPY
With this:

Code: Select all

.SKIP
	bit 7,(hl)
	inc hl
	jr z,SKIP
	dec a
.XTRACT
	or a
	jr nz,SKIP
.COPY
2 x

User avatar
ketmar
Manic Miner
Posts: 207
Joined: Tue Jun 16, 2020 5:25 pm

Re: Z80 asm/disasm in Z80 asm, request

Post by ketmar »

wow. recently, R.T. Russell's Z80 BBC Basic became opensourced. and it seems to contan full-featured assembler. i quickly scanned the sources, and they seem to be very well written. so i will look if i'll be able to rip asm module. stay tuned, i will report here if i succeed converting it into something that could be used by providing input buffer implementation.

btw, that Basics seems to be quite cool. it would be fun to port it to Speccy (maybe to +3DOS, with support for disk files). i don't think that i will do that myself, so if you have nothing better to do with your life... ;-)
1 x

User avatar
ketmar
Manic Miner
Posts: 207
Joined: Tue Jun 16, 2020 5:25 pm

Re: Z80 asm/disasm in Z80 asm, request

Post by ketmar »

yay, it is really great! by adding several i/o routines and very dumb expression parser (because it is using the same expression parser as the rest of the system) it correctly parsed "ld a,42", and even printed the generated machine code!

of course, it is far from being usable yet, but it looks really promising. also, it is less than 2kb of machine code. seems like a perfect hit.
0 x

+3code
Microbot
Posts: 169
Joined: Fri Dec 06, 2019 11:43 pm
Location: Valencia, Spain

Re: Z80 asm/disasm in Z80 asm, request

Post by +3code »

ketmar wrote:
Thu Aug 13, 2020 5:35 am
btw, that Basics seems to be quite cool. it would be fun to port it to Speccy (maybe to +3DOS, with support for disk files).
Look here:
http://mdfs.net/Software/Spectrum/BBCBasic/

But only tape support.
1 x

Post Reply