doc: sample: add for and while loop samples

This commit is contained in:
2025-09-08 15:30:44 +01:00
parent cb63e8d016
commit 2ff85a7505
4 changed files with 83 additions and 0 deletions

31
doc/sample/WhileLoop.mie Normal file
View File

@@ -0,0 +1,31 @@
data @cout = external global id
data @.str.0 = str "done"
define void @init() static {
entry:
%i = alloca i32
store i32 #0, ptr %i
%sum = alloca i32
store i32 #0, ptr %sum
while.cond:
%0 = load i32, ptr %i
%cmptmp = cmp lt i32 %0, #10
br i1 %cmptmp, label %while.body, label %while.end
while.body:
%1 = load i32, ptr %i
%2 = load i32, ptr %sum
%addtmp = add i32 %1, %2
store i32 %addtmp, ptr %sum
br label %while.cond
while.end:
%3 = load str, ptr @.str.0
%4 = load id, ptr @cout
msg void, id %4, @_M03putE [ str %3 ]
ret void
}