Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ANSI-C to 8080 asm Cross Compiler?

1,811 views
Skip to first unread message

s_dub...@yahoo.com

unread,
May 1, 2011, 11:21:41 AM5/1/11
to
Does anyone know of an ANSI-C to 8080 asm Cross Compiler?

Of course there are several versions of K&R C compilers that emit z80
& 8080 asm, but my questioner seeks an ANSI-C compiler that can output
asm for his 8085.

Thxs,

Steve

roman fulek

unread,
May 1, 2011, 1:29:09 PM5/1/11
to
Hello everybody. By the ANSI-C I don't mean that the source code fed
into compiler should be ANSI-C. I could perfectly live with K&R
syntax.
The meaning of ANSI-C is that the compiler itself could be compiled on
todays machines with 32/64 bit processors. CP/M versions of SmallC
were all using just int and pointers to int for internal data
structures of the compiler. Proper rewrite would probably use structs.
I am not absolutely sure, but to me it seems, non of the CP/M vesions
could be compiled on my Ubuntu 64bit, or in Windows with CYGWIN.

Peter Dassow

unread,
May 1, 2011, 4:55:42 PM5/1/11
to

It sounds like a joke. The only instruction code difference between 8080
and 8085 is that the 8085 have two additional instructions, RIM and SIM
(read and set interrupt mask).
So I see no advantage to get a compiler which make use of these two
instructions, which IMHO are very hardware dependant.
For CP/M compiler, plz visit my C-Compiler page at:
http://www.z80.eu/c-compiler.html
If you need a cross compiler (for DOS), may be you can modify Small-C
for that purpose, start with http://www.cpm.z80.de/small_c/smc88dos.zip

Regards
Peter

s_dub...@yahoo.com

unread,
May 1, 2011, 6:54:12 PM5/1/11
to
On May 1, 3:55 pm, Peter Dassow <z8...@arcor.de> wrote:

Hi Peter, I could have said that better. He has an 8085 single board
computer. He desires a small-c compiler that has its source code
written in ansi-c C syntax, so that he can compile its sources on his
linux system with GCC. All of the sources that I am familiar with are
written in K&R C syntax. AIUI, K&R syntax support has been dropped
for some time from most (all?) compilers.

tia,

Steve

dott.Piergiorgio

unread,
May 1, 2011, 10:48:57 PM5/1/11
to

In another terms, he needs a GCC backend, or I have misunderstanded the
question ?

Anyway, there's a *nix C x-compiler for Z-80:

> http://www.z88dk.org/forum/

I guess is feasible to work a 8080/5 backend, and IIRC is still
considered one of the best Z80 compiler (heck, can compile workable
binary for a ZX81/80...)

Best regards from Italy,
dott. Piergiorgio.

roman fulek

unread,
May 2, 2011, 2:07:20 AM5/2/11
to
On May 2, 4:48 am, "dott.Piergiorgio"
<dott.PiergiorgioNI...@KAIGUN.fastwebnet.it> wrote:

What I need are sources for a compiler that I could modify and compile
on *NIX/CYGWIN. With that executable in hand I could then cross
compile C to 8080 asm. I tried to cross compile some C to 8080 with
this http://www.cpm.z80.de/small_c/c80dos.zip

But it tries to link some CP/M libraries to the result. As I only have
simple single board computer with no CP/M this won't work. Then I
wanted to modify source code of c80dos.c and tried to compile it on
CYGWIN. It did not compile. So now I am asking, if somebody has an
compilable version of 8080 C compiler that I could take and modify.

I believe main problem is that Ron Cain's (c80dos.c) assumes pointers
are two byte wide, char is only one byte, original SmallC was self
compiling and therefore only used one dimensional arrays, no
structures .. This makes it difficult task to get c80dos.c compiled on
modern C compiler.

Roger Ivie

unread,
May 2, 2011, 2:26:56 AM5/2/11
to
On 2011-05-02, roman fulek <roman...@gmail.com> wrote:
> I believe main problem is that Ron Cain's (c80dos.c) assumes pointers
> are two byte wide, char is only one byte, original SmallC was self
> compiling and therefore only used one dimensional arrays, no
> structures .. This makes it difficult task to get c80dos.c compiled on
> modern C compiler.

Hmm. I have lying around something called "Small C Compiler v C3.0R1.1"
by Chris Lewis that includes an 8080 flavor. I've just built in on my
NetBSD box, so I know it goes through GCC.

However, all the pointers to it I'm finding on the net are defunct. I'm
not sure where or when I picked it up.
--
roger ivie
ri...@ridgenet.net

roman fulek

unread,
May 2, 2011, 2:28:57 AM5/2/11
to
On May 2, 8:26 am, Roger Ivie <ri...@ridgenet.net> wrote:

Can you please try to compile simple C program with it if it really
parses well and outputs 8080 asm ? That could make my day :-)

Roger Ivie

unread,
May 2, 2011, 2:39:30 AM5/2/11
to
Gah! I think I botched that last posting attempt. Let me try again.

On 2011-05-02, roman fulek <roman...@gmail.com> wrote:

Here's a pointer to the software that still works:
http://www.gtoal.com/compilers101/small_c/small-c/

Compiling this C code:

main()
{
return 1;
}

yields this assembly:

; Small C 8080;
; Coder (2.4,84/11/27)
; Front End (2.7,84/11/28)
extrn ?gchar,?gint,?pchar,?pint,?bool
extrn ?sxt
extrn ?or,?and,?xor
extrn ?eq,?ne,?gt,?le,?ge,?lt,?uge,?ult,?ugt,?ule
extrn ?asr,?asl
extrn ?sub,?neg,?com,?lneg,?mul,?div
extrn ?case
cseg
main:
lxi h,1
jmp ?1
?1:
ret
dseg
extrn etext
extrn edata
public main

--
roger ivie
ri...@ridgenet.net

roman fulek

unread,
May 2, 2011, 3:09:39 AM5/2/11
to
Thank you Roger

s_dub...@yahoo.com

unread,
May 2, 2011, 8:44:23 PM5/2/11
to
On May 2, 1:26 am, Roger Ivie <ri...@ridgenet.net> wrote:

'Chris Lewis' rung a bell..

http://www.cpm.z80.de/small_c/small-c.tar.gz

Steve

Fred J. Scipione

unread,
May 2, 2011, 11:26:14 PM5/2/11
to

"roman fulek" <roman...@gmail.com> wrote in message
news:b6297ce8-d538-452d...@v8g2000yqb.googlegroups.com...

...<snip>...


compile C to 8080 asm. I tried to cross compile some C to 8080 with
this http://www.cpm.z80.de/small_c/c80dos.zip

But it tries to link some CP/M libraries to the result. As I only have
simple single board computer with no CP/M this won't work. Then I
wanted to modify source code of c80dos.c and tried to compile it on
CYGWIN. It did not compile. So now I am asking, if somebody has an
compilable version of 8080 C compiler that I could take and modify.

I believe main problem is that Ron Cain's (c80dos.c) assumes pointers
are two byte wide, char is only one byte, original SmallC was self
compiling and therefore only used one dimensional arrays, no
structures .. This makes it difficult task to get c80dos.c compiled on
modern C compiler.

...<end>...

What you have is the comp.unix cross-compiler for Small-C. The
Unix version makes less assumptions about the host compiler word
size, and has an allowance for host byte order. It still uses
many 'non-portable' constructs, but fortunately most compilers
resolve them in a similar fashion to Small-C, so you just have to
tolerate a lot of warnings. It is possible to eliminate
pointer-->int-->pointer conversions by editing in a suitable
set of macros and/or conversion-function calls, but that will
require some significant (but not impossible) level of effort.

You will still need to link any results with an appropriate
C-Arithmetic-and-Logic-Library (call.mac/rel/obj/lib). The 'CALL'
is not CP/M specific. If your programs use any of the usual
(Unix) StandardIO or other library functions, you will have to
create your own versions for a non-CP/M system. You will also
have to deal with the C-Run-Time-Start-Off module (or lack
there-of). That may mean no command-line arguments, re-direction,
or arguments for main() (no argc or argv[]).


roman fulek

unread,
May 3, 2011, 1:47:41 AM5/3/11
to

Quot: "35K The code needs some modifications (just renaming some
functions) to work under Linux. The files extracted are dated 1989! It
does fail with a segmentation fault when trying to compile it, which
it's supposed to be able to do, so I can't guarantee it's 100%
stable."
As I read this I avoided it originally. But Roger proved that it still
works under NetBSD, so that I made those modifications, got the
segmentation falut and resolved it :-) It was just problem with args
processing. Now it works also under Linux/64 :-)

roman fulek

unread,
May 3, 2011, 1:53:06 AM5/3/11
to
On May 3, 5:26 am, "Fred J. Scipione" <FredJScipi...@alum.RPI.edu>
wrote:
> "roman fulek" <roman.fu...@gmail.com> wrote in message

>
> news:b6297ce8-d538-452d...@v8g2000yqb.googlegroups.com...
>
> ...<snip>...
> compile C to 8080 asm. I tried to cross compile some C to 8080 with
> thishttp://www.cpm.z80.de/small_c/c80dos.zip

>
> But it tries to link some CP/M libraries to the result. As I only have
> simple single board computer with no CP/M this won't work. Then I
> wanted to modify source code of c80dos.c and tried to compile it on
> CYGWIN. It did not compile. So now I am asking, if somebody has an
> compilable version of 8080 C compiler that I could take and modify.
>
> I believe main problem is that Ron Cain's (c80dos.c) assumes pointers
> are two byte wide, char is only one byte, original SmallC was self
> compiling and therefore only used one dimensional arrays, no
> structures .. This makes it difficult task to get c80dos.c compiled on
> modern C compiler.
>
> ...<end>...
>
> What you have is the comp.unix cross-compiler for Small-C.  The
> Unix version makes less assumptions about the host compiler word
> size, and has an allowance for host byte order.  It still uses
> many 'non-portable' constructs, but fortunately most compilers
> resolve them in a similar fashion to Small-C, so you just have to
> tolerate a lot of warnings.  It is possible to eliminate
> pointer-->int-->pointer conversions by editing in a suitable
> set of macros and/or conversion-function calls, but that will
> require some significant (but not impossible) level of effort.
>
> You will still need to link any results with an appropriate
> C-Arithmetic-and-Logic-Library (http://call.mac/rel/obj/lib).  The 'CALL'

> is not CP/M specific.  If your programs use any of the usual
> (Unix) StandardIO or other library functions, you will have to
> create your own versions for a non-CP/M system.  You will also
> have to deal with the C-Run-Time-Start-Off module (or lack
> there-of).  That may mean no command-line arguments, re-direction,
> or arguments for main() (no argc or argv[]).

Thanks for reply. So my assumptions were right. Those old CP/M version
are probably dead. As this *NIX version now works, I may resolve those
pointer-->int-->pointer conversion warnings in the future. I believe I
can take C-Arithmetic-and-Logic-Library from another SmallC version
for 8080 with almost no modifications needed. Register allocation
should be the same.

s_dub...@yahoo.com

unread,
May 3, 2011, 9:42:14 PM5/3/11
to
> processing. Now it works also under Linux/64 :-)- Hide quoted text -
>
> - Show quoted text -

Great!

I hope you will submit your version to www.cpm.z80.de

Steve


Fred J. Scipione

unread,
May 3, 2011, 10:34:11 PM5/3/11
to

"roman fulek" <roman...@gmail.com> wrote in message
news:4e06281d-4c13-44f8...@b19g2000yqg.googlegroups.com...

On May 3, 5:26 am, "Fred J. Scipione" <FredJScipi...@alum.RPI.edu>
wrote:
...<snip>...

Thanks for reply. So my assumptions were right. Those old CP/M version
are probably dead. As this *NIX version now works, I may resolve those
pointer-->int-->pointer conversion warnings in the future. I believe I
can take C-Arithmetic-and-Logic-Library from another SmallC version
for 8080 with almost no modifications needed. Register allocation
should be the same.
...<end>...

Yes, the Small-C 1.2 CALL should work un-modified. You might want
to start off by resorting the original Ron Cain technique of using
stdio.h to inject the CRTSO and CALL sources via an '#asm' section
into the front of the generated assembly code. Everything must be
compiled at once (via '#include' commands, for example), but you
initially only need an assembler (no cross librarian or linker).

Later on you can get the assembler, librarian, and linker in the
'SmallMac' package (on Gaby's site, among others) to compile and
run as cross-tools too. I have them running under DOS (WIN23 cmd
window) via the CWare PCC v1.2d compiler. PCC is a 16 bit integer
compiler, so I don't claim to have shaken out too many non-portable
constructs from the SmallMac sources. The SmallMac tools have a
common set of support routines that have to be compiled into a
library for your host system. Some of them may already be in your
C-compiler's library routines, and others (like 'getkey()') may have
to be faked or re-invented.

Note, that to get the SmallMac assembler to compile as a cross-tool,
you will first have to get the supporting 'cmit' tool running, with
the modification that it spits out it's tables as C-source or in
your host system's assembly source form. I can e-mail you my
modified cmit sources, if you are interested.


roman fulek

unread,
May 4, 2011, 2:15:13 AM5/4/11
to
> Later on you can get the assembler, librarian, and linker in the
> 'SmallMac' package (on Gaby's site, among others) to compile and
> run as cross-tools too.  I have them running under DOS (WIN23 cmd
> window) via the CWare PCC v1.2d compiler.  PCC is a 16 bit integer
> compiler, so I don't claim to have shaken out too many non-portable
> constructs from the SmallMac sources.  The SmallMac tools have a
> common set of support routines that have to be compiled into a
> library for your host system.  Some of them may already be in your
> C-compiler's library routines, and others (like 'getkey()') may have
> to be faked or re-invented.
>
> Note, that to get the SmallMac assembler to compile as a cross-tool,
> you will first have to get the supporting 'cmit' tool running, with
> the modification that it spits out it's tables as C-source or in
> your host system's assembly source form.  I can e-mail you my
> modified cmit sources, if you are interested.
I understand first part about using only assembler and "linking"
arithmetic/logic routines in one source code. But SmallMac part is
harder. I am lacking experience here. I have never seen CP/M. Last
time I worked with assembler was about time in 1988 on Czechoslovak
8080 machine called PMD85. That naturally did not have linker/
librarian. Just straightforward in memory assembly and run. After that
I jumped over to PC/DOS and learned C with its linker/librarian. So I
will need a lot of time to fully understand SmallMac suite. But if you
don't mind send the sources to me :-)

roman fulek

unread,
Dec 23, 2012, 7:14:22 AM12/23/12
to
Hello,

it's been almost year since I uploaded modified version of Chris Lewis's SmallC on github:

https://github.com/ncb85/SmallC-85

Shortly put it is a cross-compiller now intended to be used on modern machine. I have rewritten it to compile silently under GCC and added support for:
-one line comments from C99 specification
-Windows EOLs.
-initialization of global variables
-ANSI style method declaration
-unsigned types
-undocumented 8085 istructions LHLX, SHLX, LDSI, ARHL

Generated code is suitable for ASXXXX assembler/linker. I am using it to generate programs for this SBC:
http://www.nostalcomp.cz/ncb85.php

Right now I would like to add support for structs/unions. Does anyone understand how it was implemented in yet another SmallC clone ? I think it was called Small-C/Plus for Z80.

I am trying to understand that old code but some subtle nuances are unclear to me.

0 new messages