The .equ directive is used to make constants:

.equ PERIPH_BASE, 0x40000000

This directive supports some operands like add, substruct or even shift:

.equ APB2PERIPH_BASE, (PERIPH_BASE + 0x00010000)
.equ GPIO_PIN_15,     (0x00000001 << 15)

I need to invert the value so I tried this:

.equ GPIO_PIN_15_INV,      (~GPIO_PIN_15)

In the disassembly window in the SMT32Cube IDE I see that my instruction


Changes to

08000166: orrs.w r0, r5, #32768  ; 0x8000

In other words, the value of GPIO_PIN_15 doesn't invert.

Is it possible to make an inverted constant with .equ? If yes, how? Where can I read about this possibility?


1 Answer 1


There are multiple way how to replace negation by other operations. One of them (in my opinion the easiest one) is XOR with full one pattern:

.equ GPIO_PIN_15_INV,      (GPIO_PIN_15 ^ 0xFFFF)

Test it yourself: https://godbolt.org/z/nKK4c8Wsf

Side notice: with 0xFFFFFFFF it will not work because ARM assembly is unable to encode 32-bit constants in the instruction word (which is 16 or 32-bit wide, so there is no space for such large constants).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.