progs/sqr.ll
changeset 678 ff3b48da282c
child 701 681c36b2af27
equal deleted inserted replaced
677:decfd8cf8180 678:ff3b48da282c
       
     1 @.str = private constant [4 x i8] c"%d\0A\00"
       
     2 
       
     3 declare i32 @printf(i8*, ...)
       
     4 
       
     5 ; prints out an integer
       
     6 define i32 @printInt(i32 %x) {
       
     7    %t0 = getelementptr [4 x i8], [4 x i8]* @.str, i32 0, i32 0
       
     8    call i32 (i8*, ...) @printf(i8* %t0, i32 %x) 
       
     9    ret i32 %x
       
    10 }
       
    11 
       
    12 ; square function
       
    13 define i32 @sqr(i32 %x) {
       
    14    %tmp = mul i32 %x, %x
       
    15    ret i32 %tmp
       
    16 }
       
    17 
       
    18 ; main 
       
    19 define i32 @main() {
       
    20   %1 = call i32 @sqr(i32 5)
       
    21   %2 = call i32 @printInt (i32 %1)
       
    22   ret i32 %1
       
    23 }
       
    24