//"Variable Assignment" and "Sum" EXAMPLE

/* 
int main() {
    int a = 5;
    int b = 10;
    int c = a + b;
    printf("c = %d", c)
    return 0;
} 
*/

.section .data
a: .word 0
b: .word 0
c: .word 0
// Define a format string for printf
fmt: .asciz "c = %d\n"

.section .text
.global main

main:
    LDR R1, =5      // Load immediate value 5 into R1
    LDR R0, =a      // Load the address of 'a' into R0
    STR R1, [R0]    // Store the value of R1 (5) into 'a'

    LDR R1, =10     // Load immediate value 10 into R1
    LDR R0, =b      // Load the address of 'b' into R0
    STR R1, [R0]    // Store the value of R1 (10) into 'b'

    LDR R0, =a      // Load the address of 'a' into R0
    LDR R1, [R0]    // Load the value of 'a' into R1
    LDR R0, =b      // Load the address of 'b' into R0
    LDR R2, [R0]    // Load the value of 'b' into R2
    ADD R3, R1, R2  // Add the values in R1 and R2, result in R3

    LDR R0, =c      // Load the address of 'c' into R0
    STR R3, [R0]    // Store the result (R3) into the address of 'c'

    // Prepare for printf
    LDR R0, =fmt       // Load the address of the format string
    LDR R1, =c         // Load the address of 'c' into R1
    LDR R1, [R1]       // Load the value of 'c' into R1
    BL printf          // Call printf

    // Exit
    MOV R7, #1      // syscall number for exit in some Linux ARM system calls
    SWI 0           // software interrupt to invoke syscall

