0

I'm working on a project that involves assembly: the goal is to study the low-level of computing. So far, I understand how most things work (registers, instructions, stack, ...), but there are things that leave me in doubt. As I understand it, the instructions are encoded in bits, containing the OpCode and some additional arguments. But, searching further, I see other features in the assembly language that I don't understand how a processor would be able to interpret, such as if statements, labels and imports. The most logical explanation I can think of is that these features exist only to make life easier for the programmer, serving as shortcuts. So, how does compiling assembly code work? What steps are taken? Is there any way to see them one by one?

MigasHD
  • 11
  • 1
  • 1
    Assembly is *assembled* by an *assembler,* not compiled. You are right in that labels and directives do not exist in the final program, they are just meta data for use by the assembler and linker. – fuz Apr 22 '21 at 21:11
  • Please provide an example of the kind of code you are interested in. Ifs and elses turn into machine code ultimately. An instruction or few will compare something with a value, then depending on the condition it will continue to run some code or it will skip over some code and run some other code based on the if and the else. – old_timer Apr 22 '21 at 22:07
  • 1
    Most assemblers don't have if statements, which one have you seen that has that? – Erik Eidt Apr 23 '21 at 00:31
  • If you're talking about MASM's "high level" crap like its [`IF`](https://learn.microsoft.com/en-us/cpp/assembler/masm/if-masm?view=msvc-160) and `WHILE` directives, assemble it (with MASM or JWASM if it supports it), then disassemble the resulting object file to see what instructions it actually used. Normally you'll see something like in [How to write if-else in assembly?](https://stackoverflow.com/q/40602029), or what you'd see from a C compiler. ([How to remove "noise" from GCC/clang assembly output?](https://stackoverflow.com/q/38552116)) – Peter Cordes Apr 23 '21 at 03:51
  • An object file with relocation metadata is one of the intermediate steps between assembling and final runnable machine code. Absolute addresses, and relative jumps / displacements to undefined symbols, will just have a placeholder `0` or `-4` or something, and metadata telling the linker what to fill in. [Assembly - x86 call instruction and memory address?](https://stackoverflow.com/q/31818870). Also some `objdump -drwC` output in [Can't call C standard library function on 64-bit Linux from assembly (yasm) code](https://stackoverflow.com/a/52131094) showing symbol metadata. – Peter Cordes Apr 23 '21 at 03:58

0 Answers0