Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- declare i8* @malloc(i32) ; external function to allocate on heap
- define i32* @create_array() nounwind {
- ; allocate heap memory for array of size 3
- %array_address = call i8* @malloc(i32 12)
- %array = bitcast i8* %array_address to i32*
- ; Compute the address of the second element of the array and save value 3 to that address
- %a = getelementptr i32* %array, i32 1
- store i32 3, i32* %a
- ; Compute the address of the third element of the array and save value 4 to that address
- %b = getelementptr i32* %array, i32 2
- store i32 4, i32* %b
- ; Load values of the second and third element of struct from their addresses
- %a_val = load i32, i32* %a, align 4
- %b_val = load i32, i32* %b, align 4
- %sum = add i32 %a_val, %b_val
- ret %array
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement