Skip to content
← Back to Community
how can I compile C to nasm? all tools i find (objconv, c2nasm) are for windows
Profile icon
mkcodes

how can I compile C to nasm? all tools i find (objconv, c2nasm) are for windows and
WINE or dos2unix need sudo to install which i don't have

Voters
Profile icon
mkcodes
Comments
hotnewtop
Profile icon
SixBeeps

Ummm, nasm isn't a language. It's a compiler for x86 (and other types, but that's not important) Assembly.

If you want to create assembly code from a C or C++ file, you can feed the -S flag to gcc and it'll do that. https://stackoverflow.com/questions/8021874/how-can-i-compile-to-assembly-with-gcc

Profile icon
mkcodes

@SixBeeps but that can only create AT&T by default or intel, not NASM assembly (intel via --masm=intel)

Profile icon
SixBeeps

@mkcodes Huh, that's interesting. I've just now taken a look at both objconf and c2nasm, I never knew there was actually a nasm flavor of assembly. Something about that seems strange to me, but /shrug.

Anyway, c2nasm doesn't look like it's specifically for Windows. In fact, it doesn't even natively support Bash scripts. Is it not working for you? It seems to run just fine for me.

Profile icon
mkcodes

@SixBeeps but it requires objconv, and when i unzipped it it just shows EXE file meaning its probably a windows terminal tool. (tester/objconv/objconv.exe) BUT it says u can run it on unix in help file ("The latter three platforms are all based on the UNIX heritage. I will use "Unix" as a common
name for Linux, BSD and Mac on x86 an x86-64 platforms in this manual. [..] The source code for objconv can be compiled and run under any of these platforms.")

Profile icon
mkcodes

@mkcodes ALSO i ran ./c2nasm.sh ../main.c for somsething like int main(){return 0;} and it doesn't pass any test, so it works but raises errors

Profile icon
SixBeeps

@mkcodes From the objconv documentation:

image

You need to build it. build.sh is located in /src/

Profile icon
mkcodes

@SixBeeps WAIT IKNOW WHAT TO DO!! we have to make it from source (stackoverflow)

Profile icon
PikadaveStudios

@SixBeeps i just tried that and it says "permission denied"
EDIT: i got that part to work but now objconv doesn't read :/

Profile icon
mkcodes

@PikadaveStudios quoting from https://stackoverflow.com/questions/17676026/converting-c-to-nasm-assembly/27232672:

  • Go to this site http://www.agner.org/optimize/#objconv
  • Click on download and extract the objconv.zip
    Extract the source.zip and run build.sh for linux ( run objconv.exe for window ), this creates an executable objconv
  • move objconv to your binaries (do it now !!) or just run ./objconv (maybe you must run chmod 777 objconv before if you're not allowed)
    [note that i gave up on making objconv to work but there were instructions to make from source i just cant find it]