I am writing a compiler and I want the output to be in nasm. The tutorial I was learning from uses gas, and I want to convert it into nasm. I think the project would go further in nasm.
https://github.com/ravenleeblack/WillowIn code_gen.c, I am using fprintf functions, to print out nasm code into the file out.s, that can be used as the output to get assembled. I have been placing these functions, where I think they should be in the grammar. I know in normal circumstances I should be using an ast, but for now I am just manually doing it, to quickly test and get the language done step by step.
The issue I am having is setting nasm up itself. I haven't found many tutorials using nasm with compilers.
In my language, I have two kinds of functions or two classes of functions, one that acts like a class or module and the other is a normal function.
In this instance, Would I use a normal label for the first class function and a local label for the second class functions? I wanted to create a new scope called universal. This universal scope would be outside of any first class function, with global being inside the first class function, and local being inside second class functions. That is why my thought was that I might have to use a label with local labels.
Is there a better way to approach this? Any tutorials I may have missed that would help answer some questions?
.text
global _start
_start:
push ebp
mov ebp, esp
sub esp, 32
call main
call exit
main:
mov ebx, i
mov eax, 6
mov ebx, eax
mov ecx, nam
mov edx, 5
mov ecx , edx
call main.entry
.entry:
mov ebx, .entry
push ebx
call main.hi
ret
.hi:
mov ebx, .hi
push ebx
ret
exit:
mov ebx, 0
mov ebx, 1
int 80h