0

Recently, I started learning Arm64 assembly. The assembler I'm using is the GNU Assembler (GAS). The version of GAS I'm using is GNU assembler (GNU Binutils for Ubuntu) 2.42.

I want to make my code more modular so it's easier to read and maintain.

Specifically, I'd like to know if there's a best practice for sharing code between files? When sharing code between files, I'd like to be able to control what functions and structs are accessible.

I know two methods for sharing assembly code between files.

  1. The .global directive. This makes a function or struct visible to the entire assembly project.
  2. The .include directive. This includes the entire text contents of a file into another file.

Originally, I was asking for something that works like C header files, because I thought they perform access control but that's incorrect. I would like some way to declare some symbols as private so they cannot be accessed when included. I don't know if that's even possible in assembly. Or if it's just not worth worrying about.

Right now, the best idea I can think of is putting code that needs to be shared in its own file. If that file needs any dependencies, it's included and given pointers to structs and functions it needs to access. Then other files can just include that file.

2
  • What you're encountering isn't assembly-specific, it's just how linkers work. The .global directive just marks a symbol as linkable, either exporting or importing it (compare extern in C, or the absence of a static qualifier). The .include doesn't work on a linker level, but on a textual level. You don't have header files in assembly because there are no types. The closest approximation would be to include a file that contains .global declarations, without defining those symbols. Header files in C aren't access control, they don't export functions from a translation unit.
    – amon
    Commented Sep 5 at 15:37
  • Thanks! I don't think I understand all of those concepts very well, but your comment helps. After reading your comment, my question is if there's a best practice for access control in assembly code?
    – CorkiMain
    Commented Sep 5 at 15:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.