C COMPILER PROJECT: SIMPLE ASSEMBLY CODE GENERATOR IN C USING SSCANF AND FPRINTF
In this video, I demonstrate a basic compiler written in C that converts simple variable assignments into x86-64 assembly instructions.
PROJECT OVERVIEW:
Language: C
File Name: compiler.c
Libraries Used:
stdio.h
stdlib.h
string.h
FUNCTIONALITY:
This project reads variable assignments from an input file (e.g., x = 5;) and generates corresponding x86-64 assembly code into an output file.
KEY COMPONENTS:
1. Assembly Header Generation:
Adds section and global start directives:
section .text
global _start
_start:
2. Line-by-Line Parsing:
Uses fgets to read input lines.
Uses sscanf to extract variable name and value.
Writes mov eax, value for each assignment.
3. Exit Code Assembly:
Adds exit sequence at the end:
mov eax, 60
xor edi, edi
syscall
USAGE:
Compile with gcc compiler.c -o compiler
Provide an input file with simple assignments
Get an output file with raw assembly code
IDEAL FOR:
Beginners learning compiler design
Understanding how high-level instructions can be translated to low-level assembly
C programming and file handling practice
---
LINKTREE:
SEE ALL MY PROJECTS, VOICEOVERS & MORE:
https://linktr.ee/19yearsolds