4 ms·
1) is the bit I seem to have trouble finding good resources for. It seems every "intro to assembly" tutorial spends all this time talking about instructions,
by cellularmitosis 2y ago
1) is the bit I seem to have trouble finding good resources for. It seems every
"intro to assembly" tutorial spends all this time talking about instructions, and never seems to get to something as basic as "how do I create and call a function in assembly?".
Any suggestions there?
- CoastalCoder 2y agoI've only had to deal with this on x86-64 Linux, and I worked from this reference document: https://refspecs.linuxbase.org/elf/x86_64-abi-0.99.pdf https://refspecs.linuxbase.org/elf/x86_64-abi-0.99.pdf (section 3.2) [0] I imagine similar documents exist for each OS-architecture pairing, since the ABI is a convention that (ideally) everyone will agree on. If you need a definitive answer for some particular OS-architecture pairing, you might ask within a development community that also needs to support that ABI. E.g., gcc, LLVM, lldb, gdb. [0] IIRC: Even after reading that doc I was unclear on a few details. I got clarification by writing some minimal examples and looking at the assembly that gcc produces. Note that you may need to disable inlining and optimization, or else you might draw the wrong conclusions from the generated assembly.
- cellularmitosis 2y agoThanks for the reply. Actually, I ended up finding the answer to my question (“why doesn’t every assembly tutorial cover calling conventions on like, page 2?”), and it was because I was coming at this topic from a C perspective. https://stackoverflow.com/a/17309038 https://stackoverflow.com/a/17309038 “ If you're writing in assembly language, you can do whatever you want. It's only when you want to interact with some external code (maybe a library, maybe a system call) that you need to obey the calling convention.”
- CoastalCoder 2y agoPersonally, I found that approach to learning assembly somewhat difficult. If you're first learning assembly in some little simulator, or on bare metal, I can see the point in deferring any discussion about the ABI until later. My first assembly project needed to be invoked as a function call from a C/C++ program. So I'd have really benefited from at least a brief explanation about the boilerplate asm you need to be a callable function, how to make function calls / syscalls to print some output, etc.