Search code examples
assemblyraspberry-piarmflags

How to set only the overflow flag ARM assembly?


I have been messing around with the Flags while learning ARM assembly on my Raspberry PI. I have devised of ways only to set the zero flag, only the negative, and only the carry flag. However I can't think of a way to set only the overflow flag. Is it possible? Any help would be appreciated!

The challenge is not to write to the cpsr (as I am not allowed to for various reasons, otherwise that would be the best solution, because it is the best solution)

Edit: only setting the overflow flag with all the others zero/clear. Using only arithmetic or shifting. NZCV = 0001

Edit2: To clarify further, I would think multiple instructions would be needed to achieve this.


Solution

  • I don't see an obvious way with just one instruction, but you could do with combination. For example:

    mov  r0, #0x80000000
    mov  r1, #0x00000001
    subs r2, r0, r1  ; C and V set
    mov  r3, #0x10
    asrs r3, #1      ; C cleared, V not changed