Skip to content

Control flow instructions

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

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

goto instruction

  • Syntax: goto label1
  • Binary code: 0000 1000 0101 0110 (Op code: 0 0001)
  • Usage: Unconditionally jumps to the specified label.
  • Error check: Confirm label existence.

call instruction

  • Syntax: call label1
  • Binary code: 0001 0000 0101 0110 (Op code: 00010)
  • Usage: Calls a subroutine at label1.
  • Error check: Verify label existence.

ret instruction

  • Syntax: ret
  • Binary code: 1011 0000 0000 0000 (Op code: 1 0110)
  • Usage: Returns from a subroutine.
  • Error check: 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