I was wondering how could I do something when some boolean expression is true
That's exactly what if
does.
I want that it checks when the bools expressions changes in any part of code
Simply use if
every time you assign the variable.
Of course, when you always do the same check after assigning the variable and do the same thing if the check is true, then you clearly have repetition. When you want to repeatedly do the same thing multiple times, you can use a function to avoid repeating the code. Just don't accidentally modify the variable directly instead of calling that function.
Here's an example of a function that assigns a variable in memory and does a branch based on a boolean expression. If true
, it prints the variable:
.cfi_startproc
@ args = 0, pretend = 0, frame = 8
@ frame_needed = 1, uses_anonymous_args = 0
0000 00482DE9 stmfd sp!, {fp, lr}
.save {fp, lr}
.LCFI0:
.cfi_def_cfa_offset 8
.cfi_offset 11, -8
.cfi_offset 14, -4
.setfp fp, sp, #4
0004 04B08DE2 add fp, sp, #4
.LCFI1:
.cfi_def_cfa 11, 4
.pad #8
0008 08D04DE2 sub sp, sp, #8
000c 08000BE5 str r0, [fp, #-8]
0010 30309FE5 ldr r3, .L3
0014 08201BE5 ldr r2, [fp, #-8]
0018 002083E5 str r2, [r3, #0]
001c 24309FE5 ldr r3, .L3
0020 003093E5 ldr r3, [r3, #0]
0024 000053E3 cmp r3, #0
0028 0400001A bne .L1 ; <-- the branch is here
002c 14309FE5 ldr r3, .L3
0030 003093E5 ldr r3, [r3, #0]
0034 10009FE5 ldr r0, .L3+4
0038 0310A0E1 mov r1, r3
003c FEFFFFEB bl printf
.L1:
0040 04D04BE2 sub sp, fp, #4
0044 0088BDE8 ldmfd sp!, {fp, pc}
.L4:
.align 2
.L3:
0048 00000000 .word global
004c 00000000 .word .LC0
.cfi_endproc