I'm familiar with the C programming language and z80 assembly and I have made a simple z80 "computer" with just the cpu with 32k of ram, 32k of rom, and an 8255 pia for io control. I have gotten the 8255 to bling an LED with my system through an assembly language subroutine.
So the question is: If there is the SDCC(Small Device C compiler) that can compile a C program into assembly for various small CPUs including the z80, How do you create a C program if there are no stdio libraries or any libraries of any kind because of how custom this system is. Am i forced to use assembly first then make and call a function as an ASM routine? Am I misunderstanding some sort of key idea? Im quite confused on how this works. I cant just printf() on a system with no output. Not to mention printf() is under the assumption that a terminal is connected of some kind.
You would write a platform specific I/O library that utilises whatever I/O capability your platform has available. On many embedded systems a minimal standard I/O is implemented on a UART serial port so your "console" can be a terminal emulator on a host PC.
Your I/O API need not be as sophisticated as the standard library's stdio. It also need not be written in assembler, register-level access of memory-mapped peripherals is possible (in fact normal) in C - it is a systems level language after all.
All that said, SDCC already includes a standard library subset that includes a subset stdio. So it is not clear why you think you lack that support. You do have to provide low level platform specific support, but to support
printf
you need only implementputchar()
to emit a character on your chosen stdout device. For unbuffered serial output that is rather trivial. A more sophisticated implementation might use interrupt driven, buffered serial output. The porting of the library is described in the SDCC manual.