Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. declare i8* @malloc(i32) ; external function to allocate on heap
  2.  
  3. define i32* @create_array() nounwind {
  4. ; allocate heap memory for array of size 3
  5. %array_address = call i8* @malloc(i32 12)
  6. %array = bitcast i8* %array_address to i32*
  7.  
  8. ; Compute the address of the second element of the array and save value 3 to that address
  9. %a = getelementptr i32* %array, i32 1
  10. store i32 3, i32* %a
  11.  
  12. ; Compute the address of the third element of the array and save value 4 to that address
  13. %b = getelementptr i32* %array, i32 2
  14. store i32 4, i32* %b
  15.  
  16. ; Load values of the second and third element of struct from their addresses
  17. %a_val = load i32, i32* %a, align 4
  18. %b_val = load i32, i32* %b, align 4
  19. %sum = add i32 %a_val, %b_val
  20. ret %array
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement