TheThirdOne / rars

RARS -- RISC-V Assembler and Runtime Simulator
Other
1.18k stars 217 forks source link

how to assamble the C code in asm code ? #178

Open joekerrXie opened 1 year ago

joekerrXie commented 1 year ago

i want to build a asm code can call C function . but return some error , how can i assemble the C code in asm code ?

`.text .global _start .global foo

_start: la sp, stack_end li a0 ,1 li a1 ,2 call foo

stop: j stop nop

stack_start: .rept 10 .word 0 .endr stack_end: .end` ERROR: column 9: "foo" declared global label but not defined.

Nado15 commented 1 year ago

Assuming it runs bare metal:

You have to declare your function "foo" in a c file and then compile the assembly file and the c file separately. You need your own linker script as well

Here is a good explanation (you just need to follow the upper part of the answer not all)

https://stackoverflow.com/a/58588918