Add some pseudocode to examples

This commit is contained in:
2023-12-14 17:18:28 +01:00
parent 54505d4d4d
commit 984e29ec84
5 changed files with 67 additions and 10 deletions

View File

@@ -1,4 +1,15 @@
; Evaluate 2*3+5 ; Evaluate 2*3+5
;
; pseudocode:
; sum(prd(2, 3), 5)
;
; sum(a, b) {
; return a+b
; }
;
; prd(a, b) {
; return a*b;
; }
main: push 2 main: push 2
push 3 push 3

View File

@@ -1,4 +1,10 @@
; I/O example - simple echo ; I/O example - simple echo
;
; pseudocode:
; do { // read
; x = in()
; out(x)
; while(x - 0x0A != 0)
read: in read: in
dup dup

View File

@@ -1,7 +1,23 @@
; Evaluate 2^10 - loop variant ; Evaluate 2^10 - loop variant
;
; pseudocode
; pow(2, 10)
;
; pow(base, exp) {
; acc = 1
;
; do { // .loop
; if (exp == 0) {
; return acc // .done
; }
;
; acc = acc * base
; exp = exp - 1
; } while(true)
; }
push 2 push 2 ; base
push 10 push 10 ; exp
call &pow call &pow
clr 2 clr 2
halt halt

View File

@@ -1,4 +1,15 @@
; Evaluate 2^10 - recursive variant ; Evaluate 2^10 - recursive variant
;
; pseudocode:
; pow(2, 10)
;
; pow(base, exp) {
; if (exp == 0) {
; return 1 // .edge
; }
;
; return base * pow(base, exp - 1)
; }
push 2 ; base push 2 ; base
push 10 ; exp push 10 ; exp

View File

@@ -1,4 +1,17 @@
; The N-th element of Fibbonaci sequence - recursive variant ; The N-th element of Fibbonaci sequence - recursive variant
;
; pseudocode:
; fibb(n) {
; if (n == 0) {
; return 1 // .done0
; }
;
; if ((n-1) == 0) {
; return 1 // .done1
; }
;
; return fibb(n-2) + fibb(n-1)
; }
push 6 push 6
call &fibb call &fibb