For my embedded systems course we are writing assembly wrappers for syscalls. When in error we need to set the global errno (defined in the class's own files not the normal libc) as expected. How do you reference external variables in .S files?
For my embedded systems course we are writing assembly wrappers for syscalls. When in error we need to set the global errno (defined in the class's own files not the normal libc) as expected. How do you reference external variables in .S files?
I always found it easier to declare them in the C files, but it shouldn't be anything special. Just declare it in the S file, and call it as an extern from the C file. I have done it using MASM before.
Don't you just use the extern keyword? This is Mats chance to shine. Off hand I don't know.
Psh... You obviously only have ever used one assembler before:
Cool. So just don't define it and it should be assumed to be an external variable. Problem solved.GNU Assembler (gas)
GAS previously had "extern" functioning similar to NASM. My quess is that the authors realized this problem, and changed its behavior, but I am just speculating.
Currently, any undefined symbol that occurs in source is automatically declared as external. This means there are no extern declarations needed in header, but it also means that typos in names are not checked during compilation. In the case of typos, you get confusing error messages during linking, or even bad executable if you are unlucky.
However, gas is more a back-end assembler than "human" assembler so such behavior may be appropriate from this point of view.
Finally found a solution. There needs to be a
block. _errno is then synonymous with the address of the external symbol errno. It worked as described, you just can't shove the external symbol into an instruction. There needs to be a label to reference itCode:_errno .word errno
Last edited by Kernel Sanders; 10-20-2008 at 10:15 PM.