Search code examples
assemblynasmboot

how assembly programme compilation works


does assembly start executing from top to bottom like other high level languages ?:

I mean this code should hang on the first line :

jmp $
times 510-($-$$) db 0
dw 0xaa55

but it's not cause it's treated as a boot sector (last tow lines have been executed), how that works?


Solution

  • how assembly programme compilation works

    Assembly programs are not “compiled”. You say compilation if you are translating from a more abstract programming language to a more concrete “programming” language. For instance Java → Java Bytecode.

    Assembly language → machine code is not considered “compilation”, because both “languages” have the same “power”, are both as capable in describing an algorithm as the other.

    does assembly start executing from top to bottom […]

    When the CPU is powered up or reset, the instruction pointer is set to zero. However, as Michael has already pointed out, the BIOS takes care of several things before you can actually execute anything.

    […] like other high level languages ?

    Assembly is not an HLL. There are “high-level assemblers”, but these essentially have a more elaborate macro expansion system.

    I mean this code should hang on the first line :

    At least do something like:

        cli       ; clear interrupt: disables all maskable interrupts
    stop:
        hlt       ; halt execution
        jmp stop  ; in case of a non-maskable interrupt
    

    A more sophisticated approach would use the ACPI, but that doesn’t fit into 3 LOC.