1
0
mirror of https://github.com/pakt/ropc synced 2026-06-08 16:36:27 +00:00

few ROPL examples

This commit is contained in:
p
2012-09-20 02:59:07 -07:00
parent 41e4c3edde
commit ab2ef7bb76
4 changed files with 72 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
fun main(){
fmt = "%d\n"
x = 1+1+1
print:
!printf(fmt, x)
x = x+1
cmp x, 10
jne print
}
+31
View File
@@ -0,0 +1,31 @@
fun fib(n, out){
x = 0
y = 0
cmp n, 0
je copy
cmp n, 1
je copy
fib(n-1, @x)
fib(n-2, @y)
[out] = x+y
jmp exit
copy:
[out] = n
exit:
}
fun main(){
fmt = "%d\n"
i = 0
x = 0
print:
fib(i, @x)
!printf(fmt, x)
i = i+1
cmp i, 11
jne print
}
+26
View File
@@ -0,0 +1,26 @@
fun foo(){
x = 1;
}
fun main(){
one = 1
odd = 0
even = 0
i = 0
n = 10
sum:
;foo()
r = i & 1
cmp r, 1
je odd
even = even+i
jmp skip
odd:
odd = odd+i
skip:
i = i+1
cmp i, n
jne sum
total = odd + even
}
+4
View File
@@ -0,0 +1,4 @@
fun main(){
i = 0
}