Skip to content

Control flow instructions

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

Control flow instructions are crucial in the assembly language for the Virtual Processor, directing the flow of execution within the program.

goto instruction

Syntax and usage

  • Syntax: goto label1
  • Function: Unconditionally jumps to the specified label.
  • Binary code: 0000 1000 0101 0110 (label id)
  • Error check: Ensure the label exists.

call instruction

Syntax and usage

  • Syntax: call label1
  • Function: Calls a subroutine located at label1.
  • Binary code: 0001 0000 0101 0110 (label id)
  • Error check: Verify the existence of the label.

ret instruction

Syntax and usage

  • Syntax: ret
  • Function: Returns from a subroutine to the calling point.
  • Binary code: 1011 0000 0000 0000
  • 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