Jump to content

Converting basic C program to assembly and running it

poppop

I have this simple C program

#include <stdio.h>
int main()
{
	printf("Hello, world!");
	return 0;
}

I opened up command prompt and did 

gcc -S "helloWorld.c"

to convert it to assembly which is what I want to run and get the same output as helloWorld.c ..... so I do the following to make helloWorld.s to helloWorld .o

gcc -c helloWorld.s

and the following to make helloWorld.o to helloWorld.exe (I think??)

ld helloWorld.o

however the following error messages show up

helloWorld.o:helloWorld.C:(.text+0xa): undefined reference to `__main'
helloWorld.o:helloWorld.C:(.text+0x16): undefined reference to `printf'

I am not sure how to fix these errors to make it successfully compile...?

 

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

sorry for post, I found the solution shortly after posting thread

 

solution is 

gcc -S helloWorld.c

to make c program to assembly

then

gcc -g helloWorld.s -o helloWorld

to make executable version of assembly

Edited by poppop
found solution
Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×