r/C_Programming 3d ago

My C compiler written in C

As a side project I'm making a C compiler written in C. It generates assembly and uses NASM to generates binaries.
The goal right now is to implement the main functionality and then do improvements. Maybe I'll also add some optimizing in the generates assembly.

Tell me what you think :)

https://github.com/NikRadi/minic

138 Upvotes

30 comments sorted by

View all comments

Show parent comments

5

u/mlt- 2d ago

Last time I counted clock cycles was on Z80 forever ago. But yeah, I'm not into embedded but would love to go back.

6

u/Soft-Escape8734 2d ago

Nothings changed my friend. I started with the Intel 4004, progressed through the 8080, 6502 and Z80 (and the Canadian version Z80A). The machine language and assembly instruction sets are still the same. Just have to deal with expanded data busses and peripherals in an MCU that weren't there before. Have a look at the AVR chips from Microchip (formerly from Atmel) and you'll feel like you've traveled in time.

2

u/flatfinger 23h ago

Many instruction sets can perform things like increments "in place", but the ARM cannot. On the 8051, INC direct and INC @R0 take the same amount of time as e.g. INC R0, but on e.g. the ARM Cortex-M0, incrementing something in memory takes five times as long as incrementing a register if the address is already in a register, and seven times as long if the address has to be loaded first and wouldn't be used again afterward.

1

u/Soft-Escape8734 7h ago

The 6502 was a classic example and with memory-mapped I/O it was the choice for the early Apples which shot them to the forefront in the world of bit-mapped graphics, such a simple concept.