Skip to content

Control flow instructions

Guillaume DERAMCHI edited this page Feb 22, 2024 · 8 revisions

Control flow instructions in the virtual processor's assembly language guide the program's execution flow.

Instruction Syntax Binary Code Usage Error Check
goto goto label1 0000 1000 0101 0110
(Op code: 0 0001)
Unconditionally jumps to the specified label. Confirm label existence.
call call label1 0001 0000 0101 0110
(Op code: 00010)
Calls a subroutine at label1. Verify label existence.
ret ret 1011 0000 0000 0000
(Op code: 1 0110)
Returns from a subroutine. Use only after a call instruction.

Examples

  1. Using goto:
    goto mainLoop   ; Jumps to the label 'mainLoop'
    
  2. Calling a subroutine:
    call computeValue  ; Calls the subroutine 'computeValue'
    
  3. Returning from a subroutine:
    ret  ; Returns control to the point after the last call

Clone this wiki locally