User Tools

Site Tools


notes:comporg:spring2024:virconref

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
notes:comporg:spring2024:virconref [2024/02/19 15:34] – [TIME] wedgenotes:comporg:spring2024:virconref [2024/04/24 19:17] (current) – [SPU] gsalce
Line 1: Line 1:
 ======Vircon32 ASM Reference Guide====== ======Vircon32 ASM Reference Guide======
- 
 This document is based on Vircon32 DevTools **v24.02.04**; older versions will contain inconsistencies. This document is based on Vircon32 DevTools **v24.02.04**; older versions will contain inconsistencies.
  
Line 42: Line 41:
  
 Use commas to separate values (create "array" of values) Use commas to separate values (create "array" of values)
 +
 +=====Vircon32 Instruction Set=====
 +
 +^  control  ^  branch  ^  compare  ^  data  ^  convert  ^  logic  ^  int arithmetic  ^  float arithmetic  ^  float math  |
 +|  [[#HLT|HLT]]  |  [[#JMP|JMP]]  |  [[#IEQ|IEQ]]  |  [[#MOV|MOV]]  |  [[#CIF|CIF]]  |  [[#NOT|NOT]]  |  [[#IADD|IADD]]  |  [[#FADD|FADD]]  |  [[#FLR|FLR]]  |
 +|  [[#WAIT|WAIT]]  |  [[#CALL|CALL]]  |  [[#INE|INE]]  |  [[#LEA|LEA]]  |  [[#CFI|CFI]]  |  [[#AND|AND]]  |  [[#ISUB|ISUB]]  |  [[#FSUB|FSUB]]  |  [[#CEIL|CEIL]]  |
 +|  |  [[#RET|RET]]  |  [[#IGT|IGT]]  |  [[#PUSH|PUSH]]  |  [[#CIB|CIB]]  |  [[#OR|OR]]  |  [[#IMUL|IMUL]]  |  [[#FMUL|FMUL]]  |  [[#ROUND|ROUND]]  |
 +|  |  [[#JT|JT]]  |  [[#IGE|IGE]]  |  [[#POP|POP]]  |  [[#CFB|CFB]]  |  [[#XOR|XOR]]  |  [[#IDIV|IDIV]]  |  [[#FDIV|FDIV]]  |  [[#SIN|SIN]]  |
 +|  |  [[#JF|JF]]  |  [[#ILT|ILT]]  |  [[#IN|IN]]  |  |  [[#BNOT|BNOT]]  |  [[#IMOD|IMOD]]  |  [[#FMOD|FMOD]]  |  [[#ACOS|ACOS]]  |
 +|  |  |  [[#ILE|ILE]]  |  [[#OUT|OUT]]  |  |  [[#SHL|SHL]]  |  [[#ISGN|ISGN]]  |  [[#FSGN|FSGN]]  |  [[#ATAN2|ATAN2]]  |
 +|  |  |  [[#FEQ|FEQ]]  |  [[#MOVS|MOVS]]  |  |  |  [[#IMIN|IMIN]]  |  [[#FMIN|FMIN]]  |  [[#LOG|LOG]]  |
 +|  |  |  [[#FNE|FNE]]  |  [[#SETS|SETS]]  |  |  |  [[#IMAX|IMAX]]  |  [[#FMAX|FMAX]]  |  [[#POW|POW]]  |
 +|  |  |  [[#FGT|FGT]]  |  [[#CMPS|CMPS]]  |  |  |  [[#IABS|IABS]]  |  [[#FABS|FABS]]  |  |
 +|  |  |  [[#FGE|FGE]]  |  |  |  |  |  |  |
 +|  |  |  [[#FLT|FLT]]  |  |  |  |  |  |  |
 +|  |  |  [[#FLE|FLE]]  |  |  |  |  |  |  |
  
 =====Vircon32 Memory Map===== =====Vircon32 Memory Map=====
Line 90: Line 105:
 |  OUT  |  0x206  |  GPU_DrawingPointX  |  set X position to draw selected region  | |  OUT  |  0x206  |  GPU_DrawingPointX  |  set X position to draw selected region  |
 |  OUT  |  0x207  |  GPU_DrawingPointY  |  set Y position to draw selected region  | |  OUT  |  0x207  |  GPU_DrawingPointY  |  set Y position to draw selected region  |
-|  ???  |  0x208  |  GPU_DrawingScaleX  |  ???  | +|  ???  |  0x208  |  GPU_DrawingScaleX  |  sets X scaling with a float as input  | 
-|  ???  |  0x209  |  GPU_DrawingScaleY  |  ???  |+|  ???  |  0x209  |  GPU_DrawingScaleY  |  sets Y scaling with a float as input  |
 |  ???  |  0x20A  |  GPU_DrawingAngle  |  ???  | |  ???  |  0x20A  |  GPU_DrawingAngle  |  ???  |
 |  OUT  |  0x20B  |  GPU_RegionMinX  |  set Min X coordinate for region  | |  OUT  |  0x20B  |  GPU_RegionMinX  |  set Min X coordinate for region  |
Line 122: Line 137:
 |  ???  |  0x300  |  SPU_Command  |  ???  | |  ???  |  0x300  |  SPU_Command  |  ???  |
 |  ???  |  0x301  |  SPU_GlobalVolume  |  ???  | |  ???  |  0x301  |  SPU_GlobalVolume  |  ???  |
-|  ???   0x302  |  SPU_SelectedSound  |  ???  | +|  OUT   0x302  |  SPU_SelectedSound  |  ???  | 
-|  ???   0x303  |  SPU_SelectedChannel  |  ???  |+|  OUT   0x303  |  SPU_SelectedChannel  |  ???  |
 |  ???  |  0x304  |  SPU_SoundLength  |  ???  | |  ???  |  0x304  |  SPU_SoundLength  |  ???  |
 |  ???  |  0x305  |  SPU_SoundPlayWithLoop  |  ???  | |  ???  |  0x305  |  SPU_SoundPlayWithLoop  |  ???  |
Line 159: Line 174:
 |  OUT  |  0x400  |  INP_SelectedGamepad  |  Select indicated gamepad (0-3)  | |  OUT  |  0x400  |  INP_SelectedGamepad  |  Select indicated gamepad (0-3)  |
 |  ???  |  0x401  |  INP_GamepadConnected  |  ???  | |  ???  |  0x401  |  INP_GamepadConnected  |  ???  |
-|  ???   0x402  |  INP_GamepadLeft  |  ???  | +|  IN   0x402  |  INP_GamepadLeft  |  Left Key input  | 
-|  ???   0x403  |  INP_GamepadRight  |  ???  | +|  IN   0x403  |  INP_GamepadRight  |  Right Key input  | 
-|  ???   0x404  |  INP_GamepadUp  |  ???  | +|  IN   0x404  |  INP_GamepadUp  |  Up key input  | 
-|  ???   0x405  |  INP_GamepadDown  |  ???  | +|  IN   0x405  |  INP_GamepadDown  |  Down key input  | 
-|  ???   0x406  |  INP_GamepadButtonStart  |  ???  | +|  IN   0x406  |  INP_GamepadButtonStart  |  Enter key input  | 
-|  ???   0x407  |  INP_GamepadButtonA  |  ???  | +|  IN   0x407  |  INP_GamepadButtonA  |  X key input  | 
-|  ???   0x408  |  INP_GamepadButtonB  |  ???  | +|  IN   0x408  |  INP_GamepadButtonB  |  Z key input  | 
-|  ???   0x409  |  INP_GamepadButtonX  |  ???  | +|  IN   0x409  |  INP_GamepadButtonX  |  S key input  | 
-|  ???   0x40A  |  INP_GamepadButtonY  |  ???  | +|  IN   0x40A  |  INP_GamepadButtonY  |  A key input  | 
-|  ???   0x40B  |  INP_GamepadButtonL  |  ???  | +|  IN   0x40B  |  INP_GamepadButtonL  |  Q key input  | 
-|  ???   0x40C  |  INP_GamepadButtonR  |  ???  |+|  IN   0x40C  |  INP_GamepadButtonR  |  W key input  |
                  
 ====CARTRIDGE==== ====CARTRIDGE====
Line 187: Line 202:
  
 ^  opcode  ^  mneumonic  ^  category  ^  description  | ^  opcode  ^  mneumonic  ^  category  ^  description  |
-|  0x00  |  HLT  |  control  |  halt processing +|  0x00  |  [[#HLT|HLT]]   control  |  halt processing 
-|  0x01  |  WAIT  |  control  |  pause processing, wait for next frame  | +|  0x01  |  [[#WAIT|WAIT]]   control  |  pause processing, wait for next frame  | 
-|  0x02  |  JMP  |  branch  |  unconditional jump to address  |  +|  0x02  |  [[#JMP|JMP]]   branch  |  unconditional jump to address  |  
-|  0x03  |  CALL  |  branch  |  call subroutine +|  0x03  |  [[#CALL|CALL]]   branch  |  call subroutine 
-|  0x04  |  RET  |  branch  |  return from subroutine +|  0x04  |  [[#RET|RET]]   branch  |  return from subroutine 
-|  0x05  |  JT  |  branch  |  jump if true (1)  | +|  0x05  |  [[#JT|JT]]   branch  |  jump if true (1)  | 
-|  0x06  |  JF  |  branch  |  jump if false (0)  | +|  0x06  |  [[#JF|JF]]   branch  |  jump if false (0)  | 
-|  0x07  |  IEQ  |  int comparison   integer equal  | +|  0x07  |  [[#IEQ|IEQ]]  |  compare   integer equal  |  
 +|  0x08  |  [[#INE|INE]]  |  compare  |  integer not equal  |  
 +|  0x09  |  [[#IGT|IGT]]  |  compare  |  integer greater than  |  
 +|  0x0A  |  [[#IGE|IGE]]  |  compare  |  integer greater than or equal  |  
 +|  0x0B  |  [[#ILT|ILT]]  |  compare  |  integer less than  |  
 +|  0x0C  |  [[#ILE|ILE]]  |  compare  |  integer less than or equal  |  
 + 
 +====HLT==== 
 + 
 +====WAIT==== 
 + 
 +====JMP==== 
 +Unconditional jump. Forcibly redirect program flow to indicated address. The address is somewhere else in the program logic, likely identified by some set label. 
 + 
 +===Structure and variants=== 
 + 
 +  * Variant 1: <code>JMP { ImmediateValue }</code> 
 +  * Variant 2: <code>JMP { Register1 }</code> 
 + 
 +===Processing actions=== 
 +  * Variant 1: <code>InstructionPointer = ImmediateValue</code> 
 +  * Variant 2: <code>InstructionPointer = Register1</code> 
 + 
 +===Description=== 
 +JMP performs an unconditional jump to the address specified by its operand. After processing this instruction the CPU will continue execution at the new address. 
 + 
 +===Examples=== 
 +Jumping to a label (memory address/offset):
  
 <code> <code>
-        IEQ,        // Integer Equal +    jmp _label 
-        INE,        // Integer Not Equal +    ... 
-        IGT,        // Integer Greater Than +_label: 
-        IGE,        // Integer Greater or Equal +</code> 
-        ILT,        // Integer Less Than + 
-        ILE,        // Integer Less or Equal+Jumping to address stored in register: 
 + 
 +<code> 
 +    jmp R0 
 +</code> 
 + 
 +====CALL==== 
 + 
 +====RET==== 
 + 
 +====JT==== 
 +Jump if True: a conditional jump typically used following a comparison instruction, should the queried register contain a true (1) value, jump to indicated address. 
 + 
 +===NOTE=== 
 +For the purposes of comparisons and conditional jumps on Vircon32: 
 + 
 +  * true is 1 (technically non-zero) 
 +  * false is 0 
 + 
 +===Structure and variants=== 
 +  * Variant 1: <code>JT { Register1 }, { ImmediateValue }</code> 
 +  * Variant 2: <code>JT { Register1 }, { Register2 }</code> 
 + 
 +===Effect=== 
 + 
 +  * Variant 1: <code>if Register1 != 0 then InstructionPointer = ImmediateValue</code> 
 +  * Variant 2: <code>if Register1 != 0 then InstructionPointer = Register2</code> 
 + 
 +===Description=== 
 +JT performs a jump only if its first operand is true, i.e. non zero when taken as an integer. In that case its behavior is the same as an unconditional jump. Otherwise it has no effect. 
 + 
 +====JF==== 
 +Jump if False: a conditional jump typically used following a comparison instruction, should the queried register contain a false (0) value, jump to indicated address. 
 + 
 +===NOTE=== 
 +For the purposes of comparisons and conditional jumps on Vircon32: 
 + 
 +  * true is 1 (technically non-zero) 
 +  * false is 0 
 + 
 +===Structure and variants=== 
 +  * Variant 1: <code>JF { Register1 }, { ImmediateValue }</code> 
 +  * Variant 2: <code>JF { Register1 }, { Register2 }</code> 
 + 
 +===Effect=== 
 + 
 +  * Variant 1: <code>if Register1 == 0 then InstructionPointer = ImmediateValue</code> 
 +  * Variant 2: <code>if Register1 == 0 then InstructionPointer = Register2</code> 
 + 
 +===Description=== 
 +JF performs a jump only if its first operand is false, i.e. zero when taken as an integer. In that case its behavior is the same as an unconditional jump. Otherwise it has no effect. 
 + 
 +====IEQ==== 
 +Integer Compare Equality: comparisons allow us typically to evaluate two valuesin accordance with some relational operation, resulting in a true (1) or false (0) result. 
 + 
 +Should the first operand contain the same information as the second operand, the result will be true. Otherwise, false. 
 + 
 +===NOTE=== 
 +For the purposes of comparisons and conditional jumps on Vircon32: 
 + 
 +  * true is 1 (technically non-zero) 
 +  * false is 0 
 + 
 +There are six relational operations: 
 + 
 +  * is equal to 
 +  * is not equal to 
 +  * is less than 
 +  * is than or equal to 
 +  * is greater than 
 +  * is greater than or equal to 
 + 
 +===Structure and variants=== 
 +  * Variant 1: <code>IEQ { Register1 }, { ImmediateValue }</code> 
 +  * Variant 2: <code>IEQ { Register1 }, { Register2 }</code> 
 + 
 +===Processing actions=== 
 +  * Variant 1: <code>if Register1 == ImmediateValue then Register1 = 1 else Register1 = 0</code> 
 +  * Variant 2: <code>if Register1 == Register2 then Register1 = 1 else Register1 = 0</code> 
 + 
 +===Description=== 
 +IEQ takes two operands interpreted as integers, and checks if they are equal. It will store the boolean result in the first operand, which is always a register. 
 + 
 +====INE==== 
 +Integer Not Equal: comparisons allow us typically to evaluate two values, in accordance with some relational operation, resulting in a true (1) or false (0) result. 
 + 
 +Here, we test to see if the first operand is not equal to the second operand. If they are equal, the result is false, otherwise, not being equal yields a result of true. 
 + 
 +===NOTE=== 
 +For the purposes of comparisons and conditional jumps on Vircon32: 
 + 
 +  * true is 1 (technically non-zero) 
 +  * false is 0 
 + 
 +There are six relational operations: 
 + 
 +  * is equal to 
 +  * is not equal to 
 +  * is less than 
 +  * is than or equal to 
 +  * is greater than 
 +  * is greater than or equal to 
 + 
 +===Structure and variants=== 
 +  * Variant 1: <code>INE { Register1 }{ ImmediateValue }</code> 
 +  * Variant 2: <code>INE { Register1 }, { Register2 }</code> 
 + 
 +===Processing actions=== 
 +  * Variant 1: <code>if Register1 != ImmediateValue then Register1 = 1 else Register1 = 0</code> 
 +  * Variant 2: <code>if Register1 != Register2 then Register1 = 1 else Register1 = 0</code> 
 + 
 +===Description=== 
 +INE takes two operands interpreted as integers, and checks if they are different. It will store the boolean result in the first operand, which is always a register. 
 + 
 +====IGT==== 
 +Integer Greater Than: comparisons allow us typically to evaluate two values, in accordance with some relational operation, resulting in a true (1) or false (0) result. 
 + 
 +In this case, we are testing if the first operand is greater than the second operand. 
 + 
 +===NOTE=== 
 +For the purposes of comparisons and conditional jumps on Vircon32: 
 + 
 +  * true is 1 (technically non-zero) 
 +  * false is 0 
 + 
 +There are six relational operations: 
 + 
 +  * is equal to 
 +  * is not equal to 
 +  * is less than 
 +  * is than or equal to 
 +  * is greater than 
 +  * is greater than or equal to 
 + 
 +===Structure and variants=== 
 +  * Variant 1: <code>IGT { Register1 }{ ImmediateValue }</code> 
 +  * Variant 2: <code>IGT { Register1 }, { Register2 }</code> 
 + 
 +===Processing actions=== 
 +  * Variant 1: <code>if Register1 > ImmediateValue then Register1 = 1 else Register1 = 0</code> 
 +  * Variant 2: <code>if Register1 > Register2 then Register1 = 1 else Register1 = 0</code> 
 + 
 +===Description=== 
 +IGT takes two operands interpreted as integers, and checks if the first one is greater than the second. It will store the boolean result in the first operand, which is always a register. 
 + 
 + 
 +====IGE==== 
 +Integer Greater Than Or Equal: comparisons allow us typically to evaluate two values, in accordance with some relational operation, resulting in a true (1) or false (0) result. 
 + 
 +In this case, we are testing if the first operand is greater than or equal to the second operand. 
 + 
 +===NOTE=== 
 +For the purposes of comparisons and conditional jumps on Vircon32: 
 + 
 +  * true is 1 (technically non-zero) 
 +  * false is 0 
 + 
 +There are six relational operations: 
 + 
 +  * is equal to 
 +  * is not equal to 
 +  * is less than 
 +  * is than or equal to 
 +  * is greater than 
 +  * is greater than or equal to 
 + 
 +===Structure and variants=== 
 +  * Variant 1: <code>IGE { Register1 }{ ImmediateValue }</code> 
 +  * Variant 2: <code>IGE { Register1 }, { Register2 }</code> 
 + 
 +===Processing actions=== 
 +  * Variant 1: <code>if Register1 >= ImmediateValue then Register1 = 1 else Register1 = 0</code> 
 +  * Variant 2: <code>if Register1 >= Register2 then Register1 = 1 else Register1 = 0</code> 
 + 
 +===Description=== 
 +IGE takes two operands interpreted as integers, and checks if the first one is greater or equal to the second. It will store the boolean result in the first operand, which is always a register. 
 + 
 +====ILT==== 
 +Integer Less Than: comparisons allow us typically to evaluate two values, in accordance with some relational operation, resulting in a true (1) or false (0) result. 
 + 
 +In this case, we are testing if the first operand is less than the second operand. 
 + 
 +===NOTE=== 
 +For the purposes of comparisons and conditional jumps on Vircon32: 
 + 
 +  * true is 1 (technically non-zero) 
 +  * false is 0 
 + 
 +There are six relational operations: 
 + 
 +  * is equal to 
 +  * is not equal to 
 +  * is less than 
 +  * is than or equal to 
 +  * is greater than 
 +  * is greater than or equal to 
 + 
 +===Structure and variants=== 
 +  * Variant 1: <code>ILT { Register1 }{ ImmediateValue }</code> 
 +  * Variant 2: <code>ILT { Register1 }, { Register2 }</code> 
 + 
 +===Processing actions=== 
 +  * Variant 1: <code>if Register1 < ImmediateValue then Register1 = 1 else Register1 = 0</code> 
 +  * Variant 2: <code>if Register1 < Register2 then Register1 = 1 else Register1 = 0</code> 
 + 
 +===Description=== 
 +ILT takes two operands interpreted as integers, and checks if the first one is less than the second. It will store the boolean result in the first operand, which is always a register. 
 + 
 +====ILE==== 
 +Integer Less Than Or Equal: comparisons allow us typically to evaluate two values, in accordance with some relational operation, resulting in a true (1) or false (0) result. 
 + 
 +In this case, we are testing if the first operand is less than or equal to the second operand. 
 + 
 +===NOTE=== 
 +For the purposes of comparisons and conditional jumps on Vircon32: 
 + 
 +  * true is 1 (technically non-zero) 
 +  * false is 0 
 + 
 +There are six relational operations: 
 + 
 +  * is equal to 
 +  * is not equal to 
 +  * is less than 
 +  * is than or equal to 
 +  * is greater than 
 +  * is greater than or equal to 
 + 
 +===Structure and variants=== 
 +  * Variant 1: <code>ILE { Register1 }{ ImmediateValue }</code> 
 +  * Variant 2: <code>ILE { Register1 }, { Register2 }</code> 
 + 
 +===Processing actions=== 
 +  * Variant 1: <code>if Register1 <= ImmediateValue then Register1 = 1 else Register1 = 0</code> 
 +  * Variant 2: if Register1 <= Register2 then Register1 = 1 else Register1 = 0</code> 
 + 
 +===Description=== 
 +ILE takes two operands interpreted as integers, and checks if the first one is less or equal to the second. It will store the boolean result in the first operand, which is always a register. 
 + 
 +====FEQ==== 
 +====FNE==== 
 +====FGT==== 
 +====FGE==== 
 +====FLT==== 
 +====FLE====
                  
-        // float comparisons +====MOV==== 
-        FEQ       // Float Equal +MOVE: your general purpose data-copying instruction. 
-        FNE       // Float Not Equal + 
-        FGT       // Float Greater Than +===Addressing=== 
-        FGE       // Float Greater or Equal +MOVE, like other data-centric instructions, makes use of various addressing modes: 
-        FLT       // Float Less Than + 
-        FLE       // Float Less or Equal +  * **register**: source/destination is an inbuilt CPU register 
-         +  * **immediate**: some literal constant (be it data or a memory address) 
-        // data movement +  * **indirect**: value isn't the databut a memory address to where the data is. Think pointer dereference. It comes in 3 varieties: 
-        MOV,        // Move data +  * **indexed**: an offset to some existing piece of data. 
-        LEA,        // Load effective address of a memory position +      * **immediate**: a literal constant (data or memory address) 
-        PUSH      // Save on top of the stack +      * **indexed**: used with immediate/register, but we can do additional math to get an offset from the address. Think pointer dereference on an array. 
-        POP,        // Load from top of the stack+      * **register**: a CPU register 
 + 
 +Indirect processing is accomplished with the **<nowiki>[ ]</nowiki>** (square brackets) surrounding the value we wish to dereference (we're not interested in the direct thing, but indirectly in what that thing contains). 
 + 
 +===Structure and variants=== 
 +  * Variant 1: <code>MOV { Register1 }{ ImmediateValue }</code> 
 +  * Variant 2: <code>MOV { Register1 }, { Register2 }</code> 
 +  * Variant 3: <code>MOV { Register1 }[ { ImmediateValue } ]</code> 
 +  * Variant 4: <code>MOV { Register1 }, [ { Register2 } ]</code> 
 +  * Variant 5: <code>MOV { Register1 }[ { Register2 } + { ImmediateValue } ]</code> 
 +  * Variant 6: <code>MOV [ { ImmediateValue } ], { Register2 }</code> 
 +  * Variant 7: <code>MOV [ { Register1 } ]{ Register2 }</code> 
 +  * Variant 8: <code>MOV [ { Register1 } + { ImmediateValue } ]{ Register2 }</code> 
 + 
 +===Processing actions=== 
 + 
 +==Register Destination== 
 +  * Immediate: <code>Register1 = ImmediateValue</code> 
 +  * Register: <code>Register1 = Register2</code> 
 +  * Indirect with Immediate reference: <code>Register1 = Memory[ImmediateValue]</code> 
 +  * Indirect with Register reference: <code>Register1 = Memory[Register2]</code> 
 +  * Indirect Indexed with Register: <code>Register1 = Memory[Register2 + ImmediateValue]</code> 
 + 
 +==Memory Destination== 
 +  * Indirect with Immediate reference: <code>Memory[ImmediateValue] = Register2</code> 
 +  * Indirect with Register reference: <code>Memory[Register1] = Register2</code> 
 +  * Indirect with Indexed reference: <code>Memory[Register1 + ImmediateValue] = Register2</code> 
 + 
 +===Description=== 
 +MOV copies the value indicated in its second operand into the register or memory address indicated by its first operand. MOV is the most complex instruction to process because it needs to distinguish between 8 different addressing modes. 
 + 
 +The instruction specifies which of the 8 modes to use in its “Addressing mode” fieldbeing the possible values interpreted as follows: 
 + 
 +==MOV Addressing modes== 
 + 
 +^  Binary  ^  Destination  ^  Source 
 +|  000  |  Register 1  |  Immediate Value  | 
 +|  001  |  Register 1  |  Register 2  | 
 +|  010  |  Register 1  |  Memory <nowiki>[Immediate Value]</nowiki> 
 +|  011  |  Register 1  |  Memory <nowiki>[Register 2]</nowiki>  | 
 +|  100  |  Register 1  |  Memory <nowiki>[Register 2 + Immediate Value]</nowiki> 
 +|  101  |  <nowiki>Memory[Immediate Value]</nowiki>  |  Register 2  | 
 +|  110  |  <nowiki>Memory[Register 1]</nowiki>  |  Register 2  | 
 +|  111  |  <nowiki>Memory[Register 1 + Immediate Value]</nowiki>  |  Register 2  | 
 + 
 +====LEA==== 
 +Load Effective Address of a memory position. 
 + 
 +===Addressing=== 
 +MOVElike other data-centric instructions, makes use of various addressing modes: 
 + 
 +  * **register**: source/destination is an inbuilt CPU register 
 +  * **immediate**: some literal constant (be it data or a memory address) 
 +  * **indirect**: value isn't the data, but a memory address to where the data is. Think pointer dereference. It comes in 3 varieties: 
 +  * **indexed**: an offset to some existing piece of data. 
 +      * **immediate**: a literal constant (data or memory address) 
 +      * **indexed**: used with immediate/register, but we can do additional math to get an offset from the address. Think pointer dereference on an array. 
 +      * **register**: a CPU register 
 + 
 +Indirect processing is accomplished with the **<nowiki>[ ]</nowiki>** (square brackets) surrounding the value we wish to dereference (we're not interested in the direct thing, but indirectly in what that thing contains). 
 + 
 +===Structure and variants=== 
 +  * Variant 1: <code>LEA { Register1 }, [ { Register2 } ]</code> 
 +  * Variant 2: <code>LEA { Register1 }, [ { Register2 } + { ImmediateValue } ]</code> 
 + 
 +===Processing actions=== 
 +  * Register: <code>Register1 = Register2</code> 
 +  * Indexed: <code>Register1 = Register2 + ImmediateValue</code> 
 + 
 +===Description=== 
 +LEA takes a memory address as second operand. It stores that address (not its contents) into the register given as first operand. The most useful case is when the address is given in the form pointer + offset, since the addition is automatically performed. 
 + 
 +====PUSH==== 
 +Save to top of stack 
 + 
 +===Structure and variants=== 
 +  * <code>PUSH { Register1 }</code> 
 + 
 +===Processing actions=== 
 +  * <code>Stack.Push(Register1)</code> 
 + 
 +===Description=== 
 +PUSH uses the CPU hardware stack to add the value contained in the given register at the top of the stack. When you PUSH a value onto the stack, the STACK POINTER (SP) is adjusted downward by one address offset (stack grows down). 
 + 
 +====POP==== 
 +Load from top of stack 
 + 
 +===Structure and variants=== 
 +  * <code>POP { Register1 }</code> 
 + 
 +===Processing actions=== 
 +  * <code>Register1 = Stack.Pop()</code> 
 + 
 +===Description=== 
 +POP uses the CPU hardware stack to remove a value from the top of the stack and write it in the given register. When you POP a value off the stack, the STACK POINTER (SP) is adjusted upward by one address offset (stack grows down, shrinks up). 
 + 
 +<code>
         IN,         // Read from an I/O port         IN,         // Read from an I/O port
         OUT,        // Write to an I/O port         OUT,        // Write to an I/O port
notes/comporg/spring2024/virconref.1708374888.txt.gz · Last modified: 2024/02/19 15:34 by wedge