hasithvm / lasm

public repository for an educational assembler for the Libra project.
1 stars 3 forks source link

Support local labels. #27

Open kevincox opened 11 years ago

kevincox commented 11 years ago

A whishlist item.

Some assembers (such as nasm) support local labels (https://github.com/yasm/yasm/wiki/NasmSyntax#labels). Basically labels that start with a dot are forgotten about any time a label not starting with a dot it read. This allows using nice short labels inside of a function.

; My function
foo:
    mov cx, 100
    .label:
        noop
        loop .label
    ret

; Other function
bar:
    cmp ax, bx
    je .label ; Refers to label below.
    noop
.label: ; No collision.
    ret

This is a really convenient feature, sometimes loop is really the best label name.

kevincox commented 11 years ago

Also interesting but less useful is that nasm allows access to local labels from outside via label.locallabel syntax.

http://www.tortall.net/projects/yasm/manual/html/manual.html#nasm-local-label