-
Notifications
You must be signed in to change notification settings - Fork 1
Stack and data movements operations
Guillaume DERAMCHI edited this page Feb 22, 2024
·
3 revisions
The mov instruction is crucial for transferring data between registers, variables, and immediate values.
-
Syntax:
mov rg2, 7 -
Binary Code:
0000 0010 0000 0111(Op code: 0 0000) - Usage: Loads a number directly into a register.
-
Syntax:
mov rg2, rg7 -
Binary Code:
0001 1111 0000 1110, 0000 0010 0000 0000(Op code: 0 0000) - Usage: Copies the value from one register to another.
-
Syntax:
mov rg2, var2 -
Binary Code:
1011 1000 1101 0110(var2 id),0000 0010 0000 0000(Op code: 0 0000) - Usage: Moves a variable's value into a register.
-
Syntax:
mov var2, rg2 -
Binary Code:
0001 1010 0000 1110, 1100 0000 1101 0110(var2 id) (Op code: 0 0000) - Usage: Stores a register's value into a variable.
-
Syntax:
mov var2, var1 -
Binary Code:
1011 1000 1101 0110(var1 id),1100 0000 1101 0110(var2 id) (Op code: 0 0000) - Usage: Copies a value from one variable to another.
-
Syntax:
mov var2, 7 -
Binary Code:
1100 0000 1101 0110(var2 id),0000 0000 0000 0111(Op code: 0 0000) - Usage: Assigns an immediate value to a variable.
- Loading an Immediate Value:
mov rg1, 5 ; Load 5 into register 1
- Copying between registers:
mov rg2, rg1 ; Copy the value of rg1 to rg2
- Variable manipulation:
mov rg3, varName ; Move the value of varName into rg3 mov varName, rg3 ; Store the value of rg3 in varName
Stack operations in the Virtual Processor's assembly language are crucial for managing data in a Last-In-First-Out (LIFO) manner, particularly for subroutine calls and local variable storage. Additionally, the mov instruction is essential for various data transfer operations.
-
Syntax:
push rgX -
Function: Pushes the value in register
rgXonto the stack. -
Binary Code: Dependent on the specific register, e.g.,
0010 0010 0000 0000forpush rg2. - Usage: Used for saving the current state of a register before modifying it or for preparing arguments for subroutine calls.
-
Syntax:
pop rgX -
Function: Pops the top value from the stack into register
rgX. -
Binary Code: Based on the specific register, e.g.,
0011 0010 0000 0000forpop rg2. - Usage: Typically used to restore the value of a register or to retrieve subroutine call results.
-
Syntax:
pusha - Function: Pushes the contents of all registers onto the stack.
-
Binary Code:
0001 1000 0000 1100for thepushainstruction. - Usage: Used for saving the current state of all registers, typically at the beginning of a subroutine.
-
Syntax:
popa - Function: Pops values from the stack into all registers, except for register 3 which is read-only.
-
Binary Code:
0001 1000 0000 1101for thepopainstruction. - Usage: Used to restore the state of all registers, typically at the end of a subroutine.
- Subroutine example:
subroutine: pusha ; Push all register values onto the stack ; Perform various operations popa ; Pop all register values back from the stack ret ; Return from the subroutine main: call subroutine ; Call the subroutine ; Execution continues here after the subroutine returns