Skip to content

Latest commit

 

History

History
107 lines (91 loc) · 2.37 KB

File metadata and controls

107 lines (91 loc) · 2.37 KB

Execution flow instructions

These instructions define how your program behaves under certain circumstances. Following instructions are covered by this article:

  1. ret and its variants
  2. proc, end and call
  3. cmp, jmp and other jmp variants
  4. evt
  5. loop

ret and its variants

There are 4 variants:

  1. ret: just ends the program with the specific exit code:
ret 0
  1. retn: ends the program, but reads a register value for you; stands for "return-near":
mov tlr, 4
retn tlr ; ends the program with exit code 4
  1. retf: used to end a specific thread, stands for "return-far".
.start
    thread threadName -> {
        ; do smth
        retf 0
        ; code under retf won't be executed
    }
  1. halt: does the same thing as ret, but ends a procedure/function.
.start
    proc printText
        mov fdx, 1
        mov stl, 0c1
        sysenter "ios"
        syscall
        halt 0
    end

proc, end and call

These are used to declare a function/procedure and call it.

.start
    proc myproc
        ; do smth
        halt 0 ; return 0
    end

    call myproc ; calls the function

cmp, jmp and other jmp variants

Compare register values with lvalues and jump to a specific label according to the result.

    cmp tlr, 2
    jz label ; if tlr == 2 jump to label
Instruction Processed if...
je/jz comparsion returned equal.
jne/jnz comparsion returned not equal.
jl comparsion returned less.
jg comparsion returned greater.
jle comparsion returned less or equal.
jge comparsion returned greater or equal.

The jmp instruction is used as an unconditional jump.

evt

Allows you to have events, read more about this instruction inside the concepts docs.

loop

Note

This instruction was added in build 25.

This instruction allows you to write more efficient loops. The syntax is:

loop register, label

Registers that work with this instruction are imm, rax, cr2 and cr3.

Example:

.start
    mov tlr, "Hello world\n"
    mov rax, 4
    :test4
    call std::ios::write
    loop rax, test4

Output:

Hello world
Hello world
Hello world
Hello world