progs/sqr.ll
author Christian Urban <christian.urban@kcl.ac.uk>
Fri, 28 Oct 2022 09:08:13 +0100
changeset 893 54a483a33763
parent 701 681c36b2af27
permissions -rw-r--r--
updated

@.str = private constant [4 x i8] c"%d\0A\00"

declare i32 @printf(i8*, ...)

; prints out an integer
define i32 @printInt(i32 %x) {
   %t0 = getelementptr [4 x i8], [4 x i8]* @.str, i32 0, i32 0
   call i32 (i8*, ...) @printf(i8* %t0, i32 %x) 
   ret i32 %x
}

; square function
define i32 @sqr(i32 %x) {
   %tmp = mul i32 %x, %x
   ret i32 %tmp
}

; main 
define i32 @main() {
  %1 = call i32 @sqr(i32 5)
  %2 = call i32 @printInt(i32 %1)
  ret i32 %1
}