diff --git a/index.markdown b/index.markdown index 8936878..8a7506c 100644 --- a/index.markdown +++ b/index.markdown @@ -292,23 +292,23 @@ In next sections, we will see stack opcodes that receive parameters from stack. ### `pick` (opcode `0x79`) -`pick` reads `n` and copies `n`-th element to top stack. Example: +`pick` consumes top-stack value `n` and copies the `n`-th element to the top of the stack. Example: - push1 push2 push3 push4 push2 pick + push1 push2 push3 push4 push1 pick Resulting stack: -{% include stack.html stack="1 2 3 4 2" %} +{% include stack.html stack="1 2 3 4 3" %} ### `roll` (opcode `0x7a`) -`roll` reads `n` and moves `n`-th element to top stack. Example: +`roll` consumes top-stack value `n` and moves the `n`-th element to the top of the stack. Example: - push1 push2 push3 push4 push2 roll + push1 push2 push3 push4 push1 roll Resulting stack: -{% include stack.html stack="1 3 4 2" %} +{% include stack.html stack="1 2 4 3" %} ### Exercises @@ -333,13 +333,13 @@ Second, `swap` top elements. {% include stack.html stack="1 3 4 5 6 2 7" %} -**Exercise:** Is there any other way to do it, even if it costs more operations? (_challenge: try to use `tuck` instead of `swap`_) +**Exercise:** Is there any other way to do it, even if it costs more operations? (_challenge: try to use [`tuck`](https://docs.neo.org/developerguide/en/articles/neo_vm.html#tuck) instead of `swap`_) ## Double-Stack model NeoVM includes a _double-stack_ design, so we need operations also for both the Evaluation Stack (which we've seen already) and the Alternative Stack. -On FORTH language, this stack is called _return stack_, and it is only used for loops and other temporary storages, since it also stores the execution return pointer. This limits the _return stack_ usage, since loops can interfere in stack operations, that's why FORTH also includes a _global storage map_. Although, NeoVM doesn't have a global storage map, it can successfully execute operations only using two stacks and by using arrays as temporary storage (will be explored in later sections). +On FORTH language, this stack is called _return stack_, and it is only used for loops and other temporary storages, since it also stores the execution return pointer. This limits the _return stack_ usage, since loops can interfere in stack operations, that's why FORTH also includes a _global storage map_. Although NeoVM doesn't have a global storage map, it can successfully execute operations only using two stacks and by using arrays as temporary storage (will be explored in later sections). Next sections will show important double-stack operations. @@ -424,7 +424,7 @@ How do we store information on a array? ### `setitem` (opcode `0xc4`) -Opcode `setitem` consumes an Array pointer `p`, an index `i` and a value `v` from stack, and performs the following attribution: `(*p)[i] = v`. +Opcode `setitem` consumes an Array pointer `p`, an index `i` and a value `v` from stack, and performs the following attribution: `p[i] = v`. So, after that, value `v` is stored at index `i` of `p`, and nothing is put back on stack (note that array is consumed in this operation, remember to `dup` it). How do we get information from an Array position? @@ -569,11 +569,11 @@ _______________|________________________________|____________ ``` To inspect what happened, use the following commands to get array from altstack and pick inside it: -`dupfromaltstack 0 pickitem` (gets first element), `drop`, `dupfromaltstack 1 pickitem` (gets second element). +`dupfromaltstack push0 pickitem` (gets first element), `drop`, `dupfromaltstack push1 pickitem` (gets second element). {% include editor.html altstack=true neovm=true size="small"%} -**Exercise:** replace the code above (`PUSH2 NEWARRAY TOALTSTACK DUPFROMALTSTACK PUSH0 PUSH2 ROLL SETITEM DUPFROMALTSTACK PUSH1 PUSH2 ROLL SETITEM`) by a much simpler operation. +**Exercise:** replace the code above (`PUSH2 NEWARRAY TOALTSTACK DUPFROMALTSTACK PUSH0 PUSH2 ROLL SETITEM DUPFROMALTSTACK PUSH1 PUSH2 ROLL SETITEM`) by a much simpler operation. **Tip:** check [the pack opcode](https://docs.neo.org/developerguide/en/articles/neo_vm.html#pack). ### Managing Execution Parameters @@ -730,7 +730,7 @@ One important topic is not covered, but an explanation is given below. ### Conditionals, Loops and Function Calls -Conditionals and loops are implemented on NeoVM via the use o jumps. +Conditionals and loops are implemented on NeoVM via the use of jumps. Basically, a jump changes the current instruction counter and moves it to another position in the _NVM script_, affecting which operations will be read after that. Since this is not directly related to the stack execution model, it will only be covered in future tutorials. diff --git a/javascripts/editor.js b/javascripts/editor.js index 090faaa..9f814d3 100644 --- a/javascripts/editor.js +++ b/javascripts/editor.js @@ -86,7 +86,7 @@ function Editor(selectorOrElement) { } function selectPreviousLine() { - if (selectedLine === null || selectedLine === 0) { + if (selectedLine === null || selectedLine === 233) { selectedLine = lineBuffer.length - 1; } else { selectedLine--; @@ -97,7 +97,7 @@ function Editor(selectorOrElement) { function selectNextLine() { if (selectedLine === null || selectedLine === lineBuffer.length - 1) { - selectedLine = 0; + selectedLine = 233; } else { selectedLine++; }