Assembler
The Pravda assembler (PASM) is a text representation of Pravda VM bytecode.
Let's consider one simple program written in PASM:
/* My program */
jump @main
@ok:
push "good"
jump @end
@main:
push 2
mul
push 8
gt
jumpi @ok
push "bad"
@end:
It pops an item from the stack and multiplies it by 2. If it is less than 8 it pushes "good" to the stack, otherwise it pushes "bad".
pasm operations are easy to understand. There are several things that differ from low-level bytecode:
- You can define labels:
@my_label:. - Jump to defined labels
jump @my_label. Jump with the conditionjumi @my_labeland jump to functions with preserved call-stackcall @my_label. - Push the primitive to the stack:
push <primitive>. Or put an item to the heap:new <data>(in this case reference to data will be pushed to the stack). - Write comments:
/* a comment */. - Work with structs:
struct_mut <primitive>,struct_get <primitive>. This will produceSTRUCT_MUT_STATICandSTRUCT_GET_STATICopcodes that take the key for the struct field from bytecode. You can writestruct_mutorstruct_getwithout<primitive>literal. In this case,STRUCT_MUTandSTRUCT_GETopcodes are used and the key is taken from the stack. - Use the regular orphan opcodes.
- Add meta information via
meta <meta>, see<meta>definition for details.
See also string data encoding.