Converting c file to assembly

Hi all,

I have a file.c and i want to translate it into an equivalent sudo assembly file(.s) . i am at a point which i can translate sudo assembly into mixed 16 and 32,as well as i can translate it into pure 32.

so what is the gcc-gnu instruction(s) which can help me ?

What is “sudo assembly”?

You can get an assembly output from gcc by adding a -S option. Gcc however does not emit compressed instructions; that is done by the assembler. If you want to see assembly code with compressed instructions, you need to use the -c option to generate an object file, and then use “objdump -dr .o” to see the assembly code with relocations. Or alternatively you can generate an executable file, and then use “objdump -d” on the executable.

Probably means “pseudo assembly”?

1 Like

Thanks for answering
i used this "riscv32-unknown-linux-gnu-gcc loop.c -S "… and i got successful .S readable file.
the problem now is when i use this
"riscv32-unknown-linux-gnu-as -march=rv32ic a.s -o out.elf
riscv32-unknown-linux-gnu-objdump -d -M no-aliases out.elf >out.lst"
on the .s file( as i used to do with previous .s files which i wrote them by myself )… the assembler gives me an error…i think because the instructions in the .s file produced from the .c is not compatible with the riscv ,is that right ? and how could i solve this ?

yes , thanks :smiley:

You can absolutely make a .s file and then assemble it. I do it all the time.

You don’t show your source code.
You don’t show the exact commands you run.
You don’t show what the error message is.

How do you expect us to help you?

You have to specify the same -march option to both gcc and the assembler, otherwise gcc may emit instructions that the assembler won’t accept. You probably have a rv64gc gcc that is emitting mafd instructions that the assembler won’t accept when you give it -march=rv32ic. Or maybe just use -march=rv32gc with the assembler to match the assembly code that you already have.

The -M no-aliases option probably doesn’t work correctly. I never went through the disassembler and tried to make it sane. So it probably handles most instructions correctly but not all of them, which means you may still get some instruction aliases printed when using it.

1 Like