User Tools

Site Tools


ocmbytecode

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
ocmbytecode [2023/04/13 15:13] – [Opcode 0xA0..0xAF] nopsledocmbytecode [2023/04/23 15:05] (current) – [Preliminary documentation for "compat" module] nopsled
Line 69: Line 69:
  
 ===== Opcodes 00..0F ===== ===== Opcodes 00..0F =====
-=== Opcode 00: NOP ====+=== Opcode 0x00: NOP ====
 does nothing does nothing
 === Opcode 0x01: Immediate byte (value) === === Opcode 0x01: Immediate byte (value) ===
Line 173: Line 173:
 stack output: smallint containing lowest 16 bits of a*b stack output: smallint containing lowest 16 bits of a*b
  
-=== Opcode 0x14: Divide Small Ints (div) ===+=== Opcode 0x14 (20): Divide Small Ints (div) ===
 stack input: smallint a (next to top); smallint b (top of stack) stack input: smallint a (next to top); smallint b (top of stack)
  
 stack output: smallint containing a/b stack output: smallint containing a/b
  
-=== Opcode 0x15: Divide and Modulus of Small Ints (moddiv) ===+=== Opcode 0x15 (21): Divide and Modulus of Small Ints (moddiv) ===
 stack input: smallint a (next to top); smallint b (top of stack) stack input: smallint a (next to top); smallint b (top of stack)
  
 stack output: smallint containing a/b (next to top); smallint containing a%b (top of stack) stack output: smallint containing a/b (next to top); smallint containing a%b (top of stack)
  
-=== Opcode 0x16: Modulus of Small Ints (divmod) ===+=== Opcode 0x16 (22): Modulus of Small Ints (divmod) ===
 stack input: smallint a (next to top); smallint b (top of stack) stack input: smallint a (next to top); smallint b (top of stack)
  
 stack output: smallint containing a%b stack output: smallint containing a%b
  
-=== Opcode 0x17: Xor Small Ints (xor) ===+=== Opcode 0x17 (23): Xor Small Ints (xor) ===
 stack input: smallint a (next to top); smallint b (top of stack) stack input: smallint a (next to top); smallint b (top of stack)
  
 stack output: smallint containing a ^ b stack output: smallint containing a ^ b
  
-=== Opcode 0x18: And Small Ints (and) ===+=== Opcode 0x18 (24): And Small Ints (and) ===
 stack input: smallint a (next to top); smallint b (top of stack) stack input: smallint a (next to top); smallint b (top of stack)
  
 stack output: smallint containing a & b stack output: smallint containing a & b
  
-=== Opcode 0x19: Or Small Ints === (or) ===+=== Opcode 0x19 (25): Or Small Ints === (or) ===
 stack input: smallint a (next to top); smallint b (top of stack) stack input: smallint a (next to top); smallint b (top of stack)
  
 stack output: smallint containing a | b stack output: smallint containing a | b
  
-=== Opcode 0x1A: Bitwise Negate Small Int (neg) ===+=== Opcode 0x1A (26): Bitwise Negate Small Int (neg) ===
 stack input: smallint a stack input: smallint a
  
 stack output: smallint containing ~a stack output: smallint containing ~a
  
-=== Opcode 0x1B: Shift Left Small Int (shl) ===+=== Opcode 0x1B (27): Shift Left Small Int (shl) ===
 stack input: smallint a (next to top); smallint count (top of stack) stack input: smallint a (next to top); smallint count (top of stack)
  
 stack output: smallint containing a << count stack output: smallint containing a << count
  
-=== Opcode 0x1C: Shift Right Small Int (shr) ===+=== Opcode 0x1C (28): Shift Right Small Int (shr) ===
 stack input: smallint a (next to top); smallint count (top of stack) stack input: smallint a (next to top); smallint count (top of stack)
  
 stack output: smallint containing ( (unsigned)a) >> count stack output: smallint containing ( (unsigned)a) >> count
  
-=== Opcode 0x1D: Shift Right Arithmetic Small Int (sar) ===+=== Opcode 0x1D (29): Shift Right Arithmetic Small Int (sar) ===
 stack input: smallint a (next to top); smallint count (top of stack) stack input: smallint a (next to top); smallint count (top of stack)
  
 stack output: smallint containing a >> count stack output: smallint containing a >> count
  
-=== Opcode 0x1E: Compare Small Ints for Greater (cmp) ===+=== Opcode 0x1E (30): Compare Small Ints for Greater (cmp) ===
 stack input: smallint a (next to top); smallint b (top of stack) stack input: smallint a (next to top); smallint b (top of stack)
  
 stack output: smallint containing 1 if a > b, 0 otherwise stack output: smallint containing 1 if a > b, 0 otherwise
  
-=== Opcode 0x1F: Compare Small Ints for Less (cmp) ===+=== Opcode 0x1F (31): Compare Small Ints for Less (cmp) ===
 stack input: smallint a (next to top); smallint b (top of stack) stack input: smallint a (next to top); smallint b (top of stack)
  
Line 236: Line 236:
 ===== Opcodes 20..2F ===== ===== Opcodes 20..2F =====
  
-=== Opcode 0x20 (32): Compare Small Ints for equal ===+=== Opcode 0x20 (32): Compare Small Ints for equal (cmp) ===
 stack input: smallint a (next to top); smallint b (top of stack) stack input: smallint a (next to top); smallint b (top of stack)
  
 stack output: smallint containing 1 if a == b, 0 otherwise stack output: smallint containing 1 if a == b, 0 otherwise
  
-=== Opcode 0x21 (33): Test for Small Int Zero ===+=== Opcode 0x21 (33): Test for Small Int Zero (iszerow) ===
 stack input: object of any type (maybe only smallint intended) stack input: object of any type (maybe only smallint intended)
  
 stack output: 1 if object has type smallint and is zero stack output: 1 if object has type smallint and is zero
  
-=== Opcode 0x22 (34): Add DWORDs ===+=== Opcode 0x22 (34): Add DWORDs (add) ===
 stack input: small/big int a (next to top); small/big int b (top of stack) stack input: small/big int a (next to top); small/big int b (top of stack)
  
Line 253: Line 253:
 note: DWORD instructions only use the 32 least significant bits in bigint input operands, and samllint operands are treated as unsigned for unknown reasons. All arithmetic is unsigned. As bigints are in sign/magnitude representation, the input sign is ignored for bigints, but not for small ints that are two's complement. But do not use the function with negative inputs unless you wrote the OCM bytecode interpreter, because the sign of the output is undefined in that case (unless you know the internals of the interpreter, that is) note: DWORD instructions only use the 32 least significant bits in bigint input operands, and samllint operands are treated as unsigned for unknown reasons. All arithmetic is unsigned. As bigints are in sign/magnitude representation, the input sign is ignored for bigints, but not for small ints that are two's complement. But do not use the function with negative inputs unless you wrote the OCM bytecode interpreter, because the sign of the output is undefined in that case (unless you know the internals of the interpreter, that is)
  
-=== Opcode 0x23 (35): Subtract DWORDs ===+=== Opcode 0x23 (35): Subtract DWORDs (sub)  ===
 stack input: small/big int a (next to top); small/big int b (top of stack) stack input: small/big int a (next to top); small/big int b (top of stack)
  
Line 260: Line 260:
 note: See Opcode 22 for important notes on DWORD instructions. note: See Opcode 22 for important notes on DWORD instructions.
  
-=== Opcode 0x24 (36): Multiply DWORDs ===+=== Opcode 0x24 (36): Multiply DWORDs (mul) ===
 stack input: small/big int a (next to top); small/big int b (top of stack) stack input: small/big int a (next to top); small/big int b (top of stack)
  
Line 267: Line 267:
 note: See Opcode 22 for important notes on DWORD instructions. note: See Opcode 22 for important notes on DWORD instructions.
  
-=== Opcode 0x25 (37): Divide DWORDs ===+=== Opcode 0x25 (37): Divide DWORDs (div) ===
 stack input: small/big int a (next to top); small/big int b (top of stack) stack input: small/big int a (next to top); small/big int b (top of stack)
  
Line 274: Line 274:
 note: See Opcode 22 for important notes on DWORD instructions. note: See Opcode 22 for important notes on DWORD instructions.
  
-=== Opcode 0x26 (38): Division and Modulus of DWORDs ===+=== Opcode 0x26 (38): Division and Modulus of DWORDs (divmod) ===
 stack input: small/big int a (next to top); small/big int b (top of stack) stack input: small/big int a (next to top); small/big int b (top of stack)
  
Line 281: Line 281:
 note: See Opcode 22 for important notes on DWORD instructions. note: See Opcode 22 for important notes on DWORD instructions.
  
-=== Opcode 0x27 (39): Modulus of DWORDs ===+=== Opcode 0x27 (39): Modulus of DWORDs (moddiv) ===
 stack input: small/big int a (next to top); small/big int b (top of stack) stack input: small/big int a (next to top); small/big int b (top of stack)
  
Line 288: Line 288:
 note: See Opcode 22 for important notes on DWORD instructions. note: See Opcode 22 for important notes on DWORD instructions.
  
-=== Opcode 0x28 (40): Xor DWORDs ===+=== Opcode 0x28 (40): Xor DWORDs (xor) ===
 stack input: small/big int a (next to top); small/big int b (top of stack) stack input: small/big int a (next to top); small/big int b (top of stack)
  
Line 295: Line 295:
 note: See Opcode 22 for important notes on DWORD instructions. note: See Opcode 22 for important notes on DWORD instructions.
  
-=== Opcode 0x29 (41): And DWORDs ===+=== Opcode 0x29 (41): And DWORDs (and) ===
 stack input: small/big int a (next to top); small/big int b (top of stack) stack input: small/big int a (next to top); small/big int b (top of stack)
  
Line 302: Line 302:
 note: See Opcode 22 for important notes on DWORD instructions. note: See Opcode 22 for important notes on DWORD instructions.
  
-=== Opcode 0x2A (42): Or DWORDs ===+=== Opcode 0x2A (42): Or DWORDs (or) ===
 stack input: small/big int a (next to top); small/big int b (top of stack) stack input: small/big int a (next to top); small/big int b (top of stack)
  
Line 309: Line 309:
 note: See Opcode 22 for important notes on DWORD instructions. note: See Opcode 22 for important notes on DWORD instructions.
  
-=== Opcode 0x2B (43): Bitwise Not DWORD ===+=== Opcode 0x2B (43): Bitwise Not DWORD (not) ===
 stack input: small/big int a (top of stack) stack input: small/big int a (top of stack)
  
Line 316: Line 316:
 note: See Opcode 22 for important notes on DWORD instructions. note: See Opcode 22 for important notes on DWORD instructions.
  
-=== Opcode 0x2C (44): Shift Left DWORD ===+=== Opcode 0x2C (44): Shift Left DWORD (shl) ===
 stack input: small/big int a (next to top); small/big int count (top of stack) stack input: small/big int a (next to top); small/big int count (top of stack)
  
Line 323: Line 323:
 note: See Opcode 0x22 for important notes on DWORD instructions. note: See Opcode 0x22 for important notes on DWORD instructions.
  
-=== Opcode 0x2D (45): Shift Right DWORD ===+=== Opcode 0x2D (45): Shift Right DWORD (shr) ===
 stack input: small/big int a (next to top); small/big int count (top of stack) stack input: small/big int a (next to top); small/big int count (top of stack)
  
Line 330: Line 330:
 note: See Opcode 22 for important notes on DWORD instructions. note: See Opcode 22 for important notes on DWORD instructions.
  
-=== Opcode 0x2E (46): Compare DWORDs for Less ===+=== Opcode 0x2E (46): Compare DWORDs for Less (cmp) ===
 stack input: small/big int a (next to top); small/big int b (top of stack) stack input: small/big int a (next to top); small/big int b (top of stack)
  
Line 337: Line 337:
 note: See Opcode 22 for important notes on DWORD instructions. note: See Opcode 22 for important notes on DWORD instructions.
  
-=== Opcode 0x2F (47): Compare DWORDs for Greater ===+=== Opcode 0x2F (47): Compare DWORDs for Greater (cmp.gt) ===
 stack input: small/big int a (next to top); small/big int b (top of stack) stack input: small/big int a (next to top); small/big int b (top of stack)
  
Line 346: Line 346:
  
 ===== Opcodes 30..3F ===== ===== Opcodes 30..3F =====
-=== Opcode 0x30 (48): Compare DWORDs for Equality ===+=== Opcode 0x30 (48): Compare DWORDs for Equality (cmp.eq) ===
 stack input: small/big int a (next to top); small/big int b (top of stack) stack input: small/big int a (next to top); small/big int b (top of stack)
  
Line 353: Line 353:
 note: See Opcode 22 for important notes on DWORD instructions. note: See Opcode 22 for important notes on DWORD instructions.
  
-=== Opcode 0x31 (49): Execute ===+=== Opcode 0x31 (49): Execute (exec) ===
 stack input: binary blob containing bytecode stack input: binary blob containing bytecode
  
Line 362: Line 362:
 PostScript equivalent: "exec" PostScript equivalent: "exec"
  
-=== Opcode 0x32 (50): If/Else ===+=== Opcode 0x32 (50): If/Else (ifelse) ===
 stack input: selector (smallint at second to top of stack), blob for the true case (next to top), blob for the false case (top of stack) stack input: selector (smallint at second to top of stack), blob for the true case (next to top), blob for the false case (top of stack)
  
 effect: if the selector is not zero, the true blob is executed (as in Opcode 31), otherwise the false blob is executed. effect: if the selector is not zero, the true blob is executed (as in Opcode 31), otherwise the false blob is executed.
  
-=== Opcode 0x33 (51): While ===+=== Opcode 0x33 (51): While (while) ===
 stack input: condition flag (smallint) stack input: condition flag (smallint)
  
Line 376: Line 376:
 note: The blob reference on the alternate stack is **not** removed by this instruction, just the condition flag on the standard stack. note: The blob reference on the alternate stack is **not** removed by this instruction, just the condition flag on the standard stack.
  
-=== Opcode 0x34 (52): Push to alternate stack ===+=== Opcode 0x34 (52): Push to alternate stack (toalt) ===
 stack input: value of any type stack input: value of any type
  
Line 383: Line 383:
 effect: The value is moved from the standard stack to the alternate stack effect: The value is moved from the standard stack to the alternate stack
  
-=== Opcode 0x35 (53): Pop from alternate stack ===+=== Opcode 0x35 (53): Pop from alternate stack (fromalt) ===
 **alternate** stack input: value of any type **alternate** stack input: value of any type
  
Line 390: Line 390:
 effect: The value is moved from the alternate stack to the standard stack effect: The value is moved from the alternate stack to the standard stack
  
-=== Opcode 0x36 (54): Peek alternate stack ===+=== Opcode 0x36 (54): Peek alternate stack (peekalt) ===
 **alternate** stack input: value of any type (not removed by this instruction) **alternate** stack input: value of any type (not removed by this instruction)
  
Line 397: Line 397:
 effect: The value is **copied** from the alternate stack to the standard stack effect: The value is **copied** from the alternate stack to the standard stack
  
-=== Opcode 0x37 (55): Push 0 ===+=== Opcode 0x37 (55): Push 0 (0) ===
 stack output: smallint containing 0 stack output: smallint containing 0
  
-=== Opcode 0x38 (56): Push 1 ===+=== Opcode 0x38 (56): Push 1 (1) ===
 stack output: smallint containing 1 stack output: smallint containing 1
  
-=== Opcode 0x39 (57): Push 2 ===+=== Opcode 0x39 (57): Push 2 (2) ===
 stack output: smallint containing 2 stack output: smallint containing 2
  
-=== Opcode 0x3A (58): Push 3 ===+=== Opcode 0x3A (58): Push 3 (3) ===
 stack output: smallint containing 3 stack output: smallint containing 3
  
-=== Opcode 0x3B (59): Push 4 ===+=== Opcode 0x3B (59): Push 4 (4) ===
 stack output: smallint containing 4 stack output: smallint containing 4
  
-=== Opcode 0x3C (60): Push 5 ===+=== Opcode 0x3C (60): Push 5 (5) ===
 stack output: smallint containing 5 stack output: smallint containing 5
  
-=== Opcode 0x3D (61): Push 6 ===+=== Opcode 0x3D (61): Push 6 (6) ===
 stack output: smallint containing 6 stack output: smallint containing 6
  
-=== Opcode 0x3E (62): Push 7 ===+=== Opcode 0x3E (62): Push 7 (7) ===
 stack output: smallint containing 7 stack output: smallint containing 7
  
-=== Opcode 0x3F (63): Push 8 ===+=== Opcode 0x3F (63): Push 8 (8) ===
 stack output: smallint containing 8 stack output: smallint containing 8
  
 ===== Opcodes 40..4F ===== ===== Opcodes 40..4F =====
  
-=== Opcode 0x40: Push 9 ===+=== Opcode 0x40 (64): Push 9 ===
 stack output: smallint containing 9 stack output: smallint containing 9
  
-=== Opcode 0x41: Push -1 ===+=== Opcode 0x41 (65): Push -1 ===
 stack output: smallint containing -1 stack output: smallint containing -1
  
-=== Opcode 0x42: Push -2 ===+=== Opcode 0x42 (66): Push -2 ===
 stack output: smallint containing -2 stack output: smallint containing -2
  
-=== Opcode 0x43: Push -3 ===+=== Opcode 0x43 (67): Push -3 ===
 stack output: smallint containing -3  stack output: smallint containing -3 
  
-=== Opcode 0x44: Test Small Int Positive ===+=== Opcode 0x44 (68): Test Small Int Positive ===
 stack input: smallint a stack input: smallint a
  
 stack ouput: smallint 1 if a > 0, smallint 0 else stack ouput: smallint 1 if a > 0, smallint 0 else
  
-=== Opcode 0x45: Test Small Int Negative ===+=== Opcode 0x45 (69): Test Small Int Negative ===
 stack input: smallint a stack input: smallint a
  
 stack ouput: smallint 1 if a < 0, smallint 0 else stack ouput: smallint 1 if a < 0, smallint 0 else
  
-=== Opcode 0x46: Test Small Int for Zero ===+=== Opcode 0x46 (70): Test Small Int for Zero ===
 stack input: smallint a stack input: smallint a
  
Line 455: Line 455:
 note: in contrast to Opcode 21 "Test for Small Int Zero", this opcode has undefined behaviour of the operand is not a small integer. note: in contrast to Opcode 21 "Test for Small Int Zero", this opcode has undefined behaviour of the operand is not a small integer.
  
-=== Opcode 0x47: Duplicate second-to-top ===+=== Opcode 0x47 (71): Duplicate second-to-top (index.1) ===
 effect: pushes a copy of the second-to-top (the third value if you call top-of-stack the first one) to the standard stack. effect: pushes a copy of the second-to-top (the third value if you call top-of-stack the first one) to the standard stack.
  
 PostScript equivalent: "2 index" PostScript equivalent: "2 index"
  
-=== Opcode 0x48: Duplicate third-to-top ===+=== Opcode 0x48 (72): Duplicate third-to-top (index.2) ===
 effect: pushes a copy of the third-to-top (the fourth value if you call top-of-stack the first one) to the standard stack. effect: pushes a copy of the third-to-top (the fourth value if you call top-of-stack the first one) to the standard stack.
  
 PostScript equivalent: "3 index" PostScript equivalent: "3 index"
  
-=== Opcode 0x49: Duplicate fourth-to-top ===+=== Opcode 0x49 (73): Duplicate fourth-to-top (index.3) ===
 effect: pushes a copy of the fourth-to-top (the 5th value if you call top-of-stack the first one) to the standard stack. effect: pushes a copy of the fourth-to-top (the 5th value if you call top-of-stack the first one) to the standard stack.
  
 PostScript equivalent: "4 index" PostScript equivalent: "4 index"
  
-=== Opcode 0x4A: Duplicate 5th-to-top ===+=== Opcode 0x4A (74): Duplicate 5th-to-top (index.4) ===
 effect: pushes a copy of the 5th-to-top (the 6th value if you call top-of-stack the first one) to the standard stack. effect: pushes a copy of the 5th-to-top (the 6th value if you call top-of-stack the first one) to the standard stack.
  
 PostScript equivalent: "5 index" PostScript equivalent: "5 index"
  
-=== Opcode 0x4B: Move Top-3 to top ===+=== Opcode 0x4B (75): Move Top-3 to top (rollin.5) ===
 effect: The value at Top-3 gets moved to top of stack, top of stack becomes top-1 and so on. effect: The value at Top-3 gets moved to top of stack, top of stack becomes top-1 and so on.
  
 PostScript equivalent: "4 -1 roll" PostScript equivalent: "4 -1 roll"
  
-=== Opcode 0x4C: Move Top-4 to top ===+=== Opcode 0x4C (76): Move Top-4 to top (rollin.4) ===
 effect: The value at Top-4 gets moved to top of stack, top of stack becomes top-1 and so on. effect: The value at Top-4 gets moved to top of stack, top of stack becomes top-1 and so on.
  
 PostScript equivalent: "5 -1 roll" PostScript equivalent: "5 -1 roll"
  
-=== Opcode 0x4D: Move Top-5 to top ===+=== Opcode 0x4D (77): Move Top-5 to top (rollin.3) ===
 effect: The value at Top-5 gets moved to top of stack, top of stack becomes top-1 and so on. effect: The value at Top-5 gets moved to top of stack, top of stack becomes top-1 and so on.
  
 PostScript equivalent: "6 -1 roll" PostScript equivalent: "6 -1 roll"
  
-=== Opcode 0x4E: Increment Small Int ===+=== Opcode 0x4E (78): Increment Small Int (inc.w) ===
 stack input: smallint a stack input: smallint a
  
 stack ouput: smallint (a+1) stack ouput: smallint (a+1)
  
-=== Opcode 0x4F: Decrement Small Int ===+=== Opcode 0x4F (79): Decrement Small Int (dec.w) ===
 stack input: smallint a stack input: smallint a
  
Line 501: Line 501:
  
 ===== Opcodes 50..5F ===== ===== Opcodes 50..5F =====
-=== Opcode 50: Convert to signed number ===+=== Opcode 0x50 (80): Convert to signed number (cvtnum.s) ===
 stack input: value //a// that is not an array stack input: value //a// that is not an array
  
 stack output: //a// if a is numeric (smallint or bigint). If //a// is a blob, is is read as a two's complement signed big-endian number and returned in a bigint. stack output: //a// if a is numeric (smallint or bigint). If //a// is a blob, is is read as a two's complement signed big-endian number and returned in a bigint.
  
-=== Opcode 51: Convert to unsigned number ===+=== Opcode 0x51 (81): Convert to unsigned number (cvtnum.u) ===
 stack input: value //a// that is not an array stack input: value //a// that is not an array
  
Line 513: Line 513:
 note: Negative smallints or bigints are unchanged by this operation. Compare opcode 53 "Make operand unsigned". note: Negative smallints or bigints are unchanged by this operation. Compare opcode 53 "Make operand unsigned".
  
-=== Opcode 52: Make blob ===+=== Opcode 0x52 (82): Make blob (cvtblob) ===
 stack input: value //a// that is not an array stack input: value //a// that is not an array
  
 stack output: If the input is a blob, it remains unchanged. Otherwise, it is returned as two's complement big-endian number in a blob. stack output: If the input is a blob, it remains unchanged. Otherwise, it is returned as two's complement big-endian number in a blob.
  
-=== Opcode 53: Make operand unsigned ===+=== Opcode 0x53 (83): Make operand unsigned (numunsigned) ===
 stack input: numeric value //a// stack input: numeric value //a//
  
 stack output: A numeric value that results from interpreting the bits in //a// as unsigned number. I.e. smallints 0..32767 are returned unchanged. smallints -1..-32768 are converted to bigints 65536..32768 respsctively. Negative big-ints are sign-extended to whole bytes and the resulting value is treated as unsigned value stack output: A numeric value that results from interpreting the bits in //a// as unsigned number. I.e. smallints 0..32767 are returned unchanged. smallints -1..-32768 are converted to bigints 65536..32768 respsctively. Negative big-ints are sign-extended to whole bytes and the resulting value is treated as unsigned value
  
-=== Opcode 54: Truncate to Small Int ===+=== Opcode 0x54 (84): Truncate to Small Int (trunc16) ===
 stack input: numeric value //a// stack input: numeric value //a//
  
 stack output: smallints stay unchanged. The low 16 bits of the absolute value are returned for bigints, so unless you know what you are doing, only use this instruction for the range 0..32767 stack output: smallints stay unchanged. The low 16 bits of the absolute value are returned for bigints, so unless you know what you are doing, only use this instruction for the range 0..32767
  
-=== Opcode 55: Pack to Array ===+=== Opcode 0x55 (85): Pack to Array (array.astore) ===
 stack input: //n// value of any type; smallint //n// (at top of stack) stack input: //n// value of any type; smallint //n// (at top of stack)
  
 stack output: (reference to) a newly created array containing the //n// elements from the stack below the count itself stack output: (reference to) a newly created array containing the //n// elements from the stack below the count itself
  
-=== Opcode 56: Unpack Array ===+=== Opcode 0x56 (86): Unpack Array (aload.length) ===
 stack input: an array of //n// elements stack input: an array of //n// elements
  
 stack output: //n// values of any type (the array element); smallint //n// (count of elements; at top of stack) stack output: //n// values of any type (the array element); smallint //n// (count of elements; at top of stack)
  
-=== Opcode 57: Array Length ===+=== Opcode 0x57 (87): Array Length (length.arr) ===
 stack input: an array with //n// elements stack input: an array with //n// elements
  
 stack output: smallint //n// stack output: smallint //n//
  
-=== Opcode 58: Insert to Array ===+=== Opcode 0x58 (88): Insert to Array (ainsert) ===
 stack input: //entry// (any type, second to top); an array (next to top); //index// (small or big int at top of stack) stack input: //entry// (any type, second to top); an array (next to top); //index// (small or big int at top of stack)
  
 stack output: A (reference to a) copy of the array with the new element //entry// inserted before the //index//'th element (moving all elements after the inserted one position to the end of the array) stack output: A (reference to a) copy of the array with the new element //entry// inserted before the //index//'th element (moving all elements after the inserted one position to the end of the array)
  
-=== Opcode 59: Delete from Array ===+=== Opcode 0x59 (89): Delete from Array (acut) ===
 stack input: an array (next to top); //index// (small or big int at top of stack) stack input: an array (next to top); //index// (small or big int at top of stack)
  
 stack output: A (reference to a) copy of the array with the element at position //index// removed (and all further elements moved one position to the front) stack output: A (reference to a) copy of the array with the element at position //index// removed (and all further elements moved one position to the front)
  
-=== Opcode 5A: Get Array Element ===+=== Opcode 0x5A (90): Get Array Element (get) ===
 stack input: (reference to) an array (next to top); smallint //k// (top of stack) stack input: (reference to) an array (next to top); smallint //k// (top of stack)
  
 stack output: The //k//'th element of the array. stack output: The //k//'th element of the array.
  
-=== Opcode 5B: Set Array Element ===+=== Opcode 0x5B (91): Set Array Element (set) ===
 stack input: value //x// of any type (second to top); (reference to) an array (next to top); smallint //k// (at top) stack input: value //x// of any type (second to top); (reference to) an array (next to top); smallint //k// (at top)
  
Line 567: Line 567:
 note: This operation does **not** copy the array, so the element changes globally. note: This operation does **not** copy the array, so the element changes globally.
  
-=== Opcode 5C: Create Array ===+=== Opcode 0x5C (92): Create Array (array) ===
 stack input: //n// (smallint at top of stack) stack input: //n// (smallint at top of stack)
  
 stack output: A newly allocated array of //n// elements. All elements are initialized with smallint zero. stack output: A newly allocated array of //n// elements. All elements are initialized with smallint zero.
  
-=== Opcode 5D: Encode ASN.1 ===+=== Opcode 0x5D (93): Encode ASN.1 (asn1encode) ===
 stack input: value to encode (any type) stack input: value to encode (any type)
  
Line 582: Line 582:
   * arrays are encoded as SEQUENCE (ASN.1 tag 0x30), the sequence is always encoded as unknown-length and double-zero-terminated.   * arrays are encoded as SEQUENCE (ASN.1 tag 0x30), the sequence is always encoded as unknown-length and double-zero-terminated.
  
-=== Opcode 5E: Catenate to Sequence ===+=== Opcode 0x5E (94): Catenate to Sequence (asn1array) ===
 stack input: //n// blobs (should contain ASN.1 encoded data, first element pushed first, last element next-to-top); //n// (smallint at top of stack) stack input: //n// blobs (should contain ASN.1 encoded data, first element pushed first, last element next-to-top); //n// (smallint at top of stack)
  
Line 589: Line 589:
 note: The output is just 0x30 (SEQUENCE); 0x80 (unknown length); catenation of all blobs; 0x00; 0x00 note: The output is just 0x30 (SEQUENCE); 0x80 (unknown length); catenation of all blobs; 0x00; 0x00
  
-=== Opcode 5F: Decode ASN.1 ===+=== Opcode 0x5F (95): Decode ASN.1 (asn1decode) ===
 stack input: a blob containing an ASN.1 encoded object. stack input: a blob containing an ASN.1 encoded object.
  
Line 604: Line 604:
 ===== Opcodes 60..6F ===== ===== Opcodes 60..6F =====
  
-=== Opcode 0x60: Enclose Smallint ===+=== Opcode 0x60 (96): Enclose Smallint (enclose) ===
 stack input: A smallint stack input: A smallint
  
Line 611: Line 611:
 Note: the blob that gets returned is non-refcounted and lives until explicit destruction (for example by opcode 08) Note: the blob that gets returned is non-refcounted and lives until explicit destruction (for example by opcode 08)
  
-=== Opcode 0x61: Get Enclosed Smallint ===+=== Opcode 0x61 (97): Get Enclosed Smallint (disclose) ===
 stack input: A blob that encloses a small integer, created by opcode 60 stack input: A blob that encloses a small integer, created by opcode 60
  
 stack output: The enclosed small integer stack output: The enclosed small integer
  
-=== Opcode 0x62: Get Significant Bits ===+=== Opcode 0x62 (98): Get Significant Bits (countbits) ===
 stack input: Object of any type stack input: Object of any type
  
 stack ouput: Significant bit in that object. For smallints and bigints its the minimal number of bits to represent the absolute value of that number, for blobs the number of bytes multiplied by 8 and for arrays the sum of the number of significant bits of all entries. stack ouput: Significant bit in that object. For smallints and bigints its the minimal number of bits to represent the absolute value of that number, for blobs the number of bytes multiplied by 8 and for arrays the sum of the number of significant bits of all entries.
  
-=== Opcode 0x63: Immediate Crypted Byte ===+=== Opcode 0x63 (99): Immediate Crypted Byte (0x??w) ===
 immediate data: 1 byte (encrypted if OCM code encryption is enabled) immediate data: 1 byte (encrypted if OCM code encryption is enabled)
  
Line 628: Line 628:
 note: Is often used to refer to the dictionary index where the data is stored. note: Is often used to refer to the dictionary index where the data is stored.
  
-=== Opcode 0x64: Immediate Crypted Word ===+=== Opcode 0x64 (100): Immediate Crypted Word (0x?w) ===
 immediate data: 1 16-bit-word (encrypted if OCM code encryption is enabled) immediate data: 1 16-bit-word (encrypted if OCM code encryption is enabled)
  
 effect: pushes the signed 16 bit value of the immediate operand to the stack as small number effect: pushes the signed 16 bit value of the immediate operand to the stack as small number
  
-=== Opcode 0x65: Immediate Crypted BigInt ===+=== Opcode 0x65 (101): Immediate Crypted BigInt (value) ===
 immediate data: 1 big int (encrypted if OCM code encryption is enabled) immediate data: 1 big int (encrypted if OCM code encryption is enabled)
  
Line 640: Line 640:
 note: If the OCM module uses the DWORD-based decryptor (it doesn't start with 03 01 in that case, we did not encounter such a module yet), it is important to know that the immediate arg is decrypted in three parts: (1) initial length byte, (2) extra length bytes, optional, (3) data bytes. note: If the OCM module uses the DWORD-based decryptor (it doesn't start with 03 01 in that case, we did not encounter such a module yet), it is important to know that the immediate arg is decrypted in three parts: (1) initial length byte, (2) extra length bytes, optional, (3) data bytes.
  
-=== Opcode 0x66: Immediate Crypted Blob ===+=== Opcode 0x66 (102): Immediate Crypted Blob (value) ===
 immediate data: 1 blob (encrypted if OCM code encryption is enabled) immediate data: 1 blob (encrypted if OCM code encryption is enabled)
  
Line 647: Line 647:
 note: If the OCM module uses the DWORD-based decryptor (it doesn't start with 03 01 in that case, we did not encounter such a module yet), it is important to know that the immediate arg is decrypted in three parts: (1) initial length byte, (2) extra length bytes, optional, (3) data bytes. note: If the OCM module uses the DWORD-based decryptor (it doesn't start with 03 01 in that case, we did not encounter such a module yet), it is important to know that the immediate arg is decrypted in three parts: (1) initial length byte, (2) extra length bytes, optional, (3) data bytes.
  
-=== Opcode 0x67 (103): Start Threads ===+=== Opcode 0x67 (103): Start Threads (threads) ===
 stack input: common thread arg (any type); //n// blobs containing byte code; smallint //n// (at top of stack) stack input: common thread arg (any type); //n// blobs containing byte code; smallint //n// (at top of stack)
  
 effect: Starts pseudo-parallel execution of all n blobs. Execution of the main code (that invoked this opcode) stops until all threads are finished or the threaded evaluation mode is cancelled. All threads have their own stack, each containing just the common arg. Also every thread has its private alternate stack. effect: Starts pseudo-parallel execution of all n blobs. Execution of the main code (that invoked this opcode) stops until all threads are finished or the threaded evaluation mode is cancelled. All threads have their own stack, each containing just the common arg. Also every thread has its private alternate stack.
  
-=== Opcode 0x68 (104): Set Time Slice Length ===+=== Opcode 0x68 (104): Set Time Slice Length (timeslice) ===
 stack input: smallint or bigint //len// stack input: smallint or bigint //len//
  
 effect: Sets the time slice length for this subthread to //len//. That is the number of bytecode instructions executed for this thread until execution continues with another thread. The current timeslice is unmodified, it just affects the following slices. effect: Sets the time slice length for this subthread to //len//. That is the number of bytecode instructions executed for this thread until execution continues with another thread. The current timeslice is unmodified, it just affects the following slices.
  
-=== Opcode 0x69 (105): Cancel Threaded Execution ===+=== Opcode 0x69 (105): Cancel Threaded Execution (killthreads) ===
 effect: Aborts executing of all subthreads and immediately continues the main thread past its start threads opcode. effect: Aborts executing of all subthreads and immediately continues the main thread past its start threads opcode.
  
-=== Opcode 0x6A (106): Push To Main Thread Stack ===+=== Opcode 0x6A (106): Push To Main Thread Stack (tomain) ===
 stack input: a value of any type stack input: a value of any type
  
Line 667: Line 667:
 note: This opcode does only make sense in subthreads. note: This opcode does only make sense in subthreads.
  
-=== Opcode 0x6B (107): Pop From Main Thread Stack ===+=== Opcode 0x6B (107): Pop From Main Thread Stack (frommain) ===
 effect: Pops the top value from the stack of the suspended main thread effect: Pops the top value from the stack of the suspended main thread
  
Line 674: Line 674:
 note: This opcode does only make sense in subthreads. note: This opcode does only make sense in subthreads.
  
-=== Opcode 0x6C (108): Copy From Main Thread Stack ===+=== Opcode 0x6C (108): Copy From Main Thread Stack (peekmain) ===
 effect: Copies the top value from the stack of the suspended main thread effect: Copies the top value from the stack of the suspended main thread
  
Line 681: Line 681:
 note: This opcode does only make sense in subthreads. note: This opcode does only make sense in subthreads.
  
-=== Opcode 0x6D: gettimeofday ===+=== Opcode 0x6D (109): gettimeofday (gettimeofday) ===
 stack output: seconds since midnight (tv_sec) as bigint (next to top); microseconds within current second (tv_usec) as bigint (top of stack) stack output: seconds since midnight (tv_sec) as bigint (next to top); microseconds within current second (tv_usec) as bigint (top of stack)
  
-=== Opcode 0x6E: mktime ===+=== Opcode 0x6E (110): mktime (mktime) ===
 stack input: 6 smallint or bigint values in the following order: seconds, minutes, hours, day (1-based), month (0-based), year (top of stack) stack input: 6 smallint or bigint values in the following order: seconds, minutes, hours, day (1-based), month (0-based), year (top of stack)
  
 stack output: the corresponding unix timestamp stack output: the corresponding unix timestamp
  
-=== Opcode 0x6F: localtime ===+=== Opcode 0x6F (111): localtime (localtime) ===
 stack input: a small/big int containing a unix timestamp stack input: a small/big int containing a unix timestamp
  
Line 695: Line 695:
  
 ===== Opcodes 70..7F ===== ===== Opcodes 70..7F =====
-=== Opcode 70 (112): Get Type ===+=== Opcode 0x70 (112): Get Type (type) ===
 stack input: object of any type stack input: object of any type
  
 stack output: The type tag of that object (see top of the page) stack output: The type tag of that object (see top of the page)
  
-=== Opcode 0x71 (113): Get Random Number ===+=== Opcode 0x71 (113): Get Random Number (rng.skipget) ===
 stack input: smallint //n// of values to skip stack input: smallint //n// of values to skip
  
 stack output: The number generated by the user RNG after skipping //n// values. stack output: The number generated by the user RNG after skipping //n// values.
  
-=== Opcode 0x72 (114): Set User RNG Autoskip ===+=== Opcode 0x72 (114): Set User RNG Autoskip (rng.autoskip) ===
 stack input: smallint //n// stack input: smallint //n//
  
 effect: Enables autoskipping, i.e. advancing the user RNG by //n// for every opcode executed. //n//==0 disables it. effect: Enables autoskipping, i.e. advancing the user RNG by //n// for every opcode executed. //n//==0 disables it.
  
-=== Opcode 0x73 (115): Seed and Enable Stream Decryptor ===+=== Opcode 0x73 (115): Seed and Enable Stream Decryptor (decryptseed) ===
 stack input: smallint //n// as 16 bit seed value. stack input: smallint //n// as 16 bit seed value.
  
Line 717: Line 717:
 note: This will indicate that the following bytes are encrypted.  note: This will indicate that the following bytes are encrypted. 
  
-=== Opcode 0x74 (116): Load Stream Decryptor Table ===+=== Opcode 0x74 (116): Load Stream Decryptor Table (decrypttable) ===
 stack input: A reference to a block of bytes. The size must be a power of 2 stack input: A reference to a block of bytes. The size must be a power of 2
  
 effect: Replaces the standard table in the Stream PRNG by the one given as parameter effect: Replaces the standard table in the Stream PRNG by the one given as parameter
  
-=== Opcode 0x75 (117): Load Native Module ===+=== Opcode 0x75 (117): Load Native Module (natmod) ===
 stack input: A blob containing a (possibly compressed) module of native code stack input: A blob containing a (possibly compressed) module of native code
  
Line 729: Line 729:
 effect: The contents of that blob gets loaded into the virtual machine. The first 0x60 bytes of the blob are a header for the module that, amongst other things, contains the name of the module which is used to identify it. The module is decompressed, relocated and the exported names are put into the salwrap global exports table (unless the module is named "bc", in that case, exports are not yet loaded) effect: The contents of that blob gets loaded into the virtual machine. The first 0x60 bytes of the blob are a header for the module that, amongst other things, contains the name of the module which is used to identify it. The module is decompressed, relocated and the exported names are put into the salwrap global exports table (unless the module is named "bc", in that case, exports are not yet loaded)
  
-=== Opcode 0x76 (118): Unload native module ===+=== Opcode 0x76 (118): Unload native module (addexports) ===
 stack input: A module handle (as smallint) stack input: A module handle (as smallint)
  
Line 736: Line 736:
 effect: Unloads the given native module. If it is not named "bc", the exports are removed from the global symbol table before unloading the module. effect: Unloads the given native module. If it is not named "bc", the exports are removed from the global symbol table before unloading the module.
  
-=== Opcode 0x77 (119): Call a native module ===+=== Opcode 0x77 (119): Call a native module (callmod) ===
 stack input: args for the native module (type(s) module specific); module handle (smallint at top) stack input: args for the native module (type(s) module specific); module handle (smallint at top)
  
Line 743: Line 743:
 effect: Runs the native code associated with the given module handle. It removes the module handle from the stack before running that module. The module itself can do to the stack whatever it wants. effect: Runs the native code associated with the given module handle. It removes the module handle from the stack before running that module. The module itself can do to the stack whatever it wants.
  
-=== Opcode 0x78 (120): Run Unloaded Native Module ===+=== Opcode 0x78 (120): Run Unloaded Native Module (callblobmod) ===
 stack input: possible module args; a blob containing a non-compressed module (at top; like for Opcode 75) stack input: possible module args; a blob containing a non-compressed module (at top; like for Opcode 75)
  
Line 750: Line 750:
 effect: Executes the native code from the blob given as parameter. The blob is relocated and exports are loaded (unless it is a "bc" named blob). As the blob is non-permanent, there better are no exports. The entrypoint is finally called (Like Opcode 77 does for a loaded module) effect: Executes the native code from the blob given as parameter. The blob is relocated and exports are loaded (unless it is a "bc" named blob). As the blob is non-permanent, there better are no exports. The entrypoint is finally called (Like Opcode 77 does for a loaded module)
  
-=== Opcode 0x79 (121): Get Module Name ===+=== Opcode 0x79 (121): Get Module Name (modname) ===
 stack input: module handle (as smallint) stack input: module handle (as smallint)
  
 stack ouput: blob containing name of that module stack ouput: blob containing name of that module
  
-=== Opcode 0x7A (122): Get Module Handle ===+=== Opcode 0x7A (122): Get Module Handle (modhnd) ===
 stack input: blob containing of module name stack input: blob containing of module name
  
 stack ouput: smallint containing module handle stack ouput: smallint containing module handle
  
-=== Opcode 0x7B (123): Create Module For Blob ===+=== Opcode 0x7B (123): Create Module For Blob (modcreate) ===
 stack input: module name (blob next to top); module contents (blob at top) stack input: module name (blob next to top); module contents (blob at top)
  
Line 767: Line 767:
 Creates an entry in the module list that references the address range of the blob. Creates an entry in the module list that references the address range of the blob.
  
-=== Opcode 0x7C (124): Create Bytecode Module ===+=== Opcode 0x7C (124): Create Bytecode Module (bcmodcreate) ===
 stack input: module contents (blob); module name (blob at top, optional) stack input: module contents (blob); module name (blob at top, optional)
  
Line 774: Line 774:
 Copies the blob contents into the interpreter as bytecode module. If top of stack is <= 8 chars, it is treated as a name. Otherwise the standard name "bc" is used instead. Copies the blob contents into the interpreter as bytecode module. If top of stack is <= 8 chars, it is treated as a name. Otherwise the standard name "bc" is used instead.
  
-=== Opcode 0x7D (125): Run OCM Module ===+=== Opcode 0x7D (125): Run OCM Module (bcmodcall) ===
 stack input: smallint containing module handle. stack input: smallint containing module handle.
  
Line 786: Line 786:
                  
  
-=== Opcode 0x7E (126): Seed User RNG ===+=== Opcode 0x7E (126): Seed User RNG (rng.seed) ===
 stack input: smallint; blob (at top of stack) stack input: smallint; blob (at top of stack)
  
Line 1245: Line 1245:
 This list shows an overview over the opcodes C2..E0 (from compat, a module inside init.ocm). The numbers are **relative** opcode numbers, i.e. the opcode minus the base opcode of C2. This list shows an overview over the opcodes C2..E0 (from compat, a module inside init.ocm). The numbers are **relative** opcode numbers, i.e. the opcode minus the base opcode of C2.
  
-<code> +=== Opcode 0xC2 (194): Extracts a subblob of a given (length) beginning at position (index) from blob (blob.part) === 
-dd 0 (0xc2) ; DATA XREFinitproc:loc_4166r+If the length is -1, the subblob is taken until the end of the blob.
  
-dd offset BCX_00_Subblob ; DATA XREFinitproc+42r+stack inputstring; index; length 
  
- ; string index length -> substring+stack output: substring
  
-Marcus: If length == -1, take until end of blob.+ 
 +<code>
  
 dd 1 (0xc3) dd 1 (0xc3)
ocmbytecode.1681398805.txt.gz · Last modified: 2023/04/13 15:13 by nopsled

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki