Last active
December 1, 2016 01:55
-
-
Save ncaq/3c2e570afb188645b64f61fa79a8740e to your computer and use it in GitHub Desktop.
llvm中間言語によるフィボナッチ数の計算です
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare i32 @printf(i8* noalias nocapture, ...) | |
define i32 @main() { | |
%ds = alloca [4 x i8] | |
store [4 x i8] c"%d\0a\00", [4 x i8]* %ds | |
%dp = getelementptr [4 x i8], [4 x i8]* %ds, i64 0, i64 0 | |
%x1 = alloca i32 | |
store i32 1, i32* %x1 | |
%x2 = alloca i32 | |
store i32 1, i32* %x2 | |
call i32 (i8*, ...) @printf(i8* %dp, i32 1) | |
call i32 (i8*, ...) @printf(i8* %dp, i32 1) | |
br label %loop | |
loop: | |
%y1 = load i32, i32* %x1 | |
%y2 = load i32, i32* %x2 | |
%y3 = add i32 %y1, %y2 | |
call i32 (i8*, ...) @printf(i8* %dp, i32 %y3) | |
store i32 %y2, i32* %x1 | |
store i32 %y3, i32* %x2 | |
%cond = icmp sgt i32 10000, %y1 | |
br i1 %cond, label %loop, label %exit | |
exit: | |
ret i32 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment