Weird Bug when setting register in assembly


I was playing with blue pill (Stm32F103CB) and trying to set r7 register via assembly,

.syntax unified
.cpu cortex-m3
.fpu softvfp

.global vtable
.global reset_handler

.type vtable, %object
    .word _estack
    .word reset_handler
.size vtable, .-vtable

.type reset_handler, %function

    LDR  r0, =_estack
    MOV  sp, r0
    LDR  r7, =0xDEADBEEF
.size reset_handler, .-reset_handler

The bug is that when i observe the register values via gdb -> info registers i see r8 register set instead of r7 as can be seen in below image.

enter image description here

objdump disassembly of elf also seems correct.

enter image description here

I am unable to understand why this is happening, tried the same with multiple boards, how can i debug and resolve this issue.

Thanks in advance.

asked on Stack Overflow Nov 7, 2020 by Hannan mumtaz • edited Nov 7, 2020 by Hannan mumtaz

1 Answer


Ok so i did some further tests.

The issue is with this opensource stlink gdb server:

All the registers are numbered as r# + 1 for some reason, and even the sp value is shown as lr.

I tried with openocd instead and everything works as expected.

Will raise a ticket in the stlink-org repo for this.

answered on Stack Overflow Nov 7, 2020 by Hannan mumtaz

User contributions licensed under CC BY-SA 3.0