Alien Queen
Alien Queen
DIIDevHeads IoT Integration Server
Created by Sterling on 9/26/2024 in #firmware-and-baremetal
Ensuring 16-bit THUMB Instruction Encoding for Code Execution from SRAM on STM32F103
@Sterling You’re seeing 32-bit instructions in your THUMB assembly code disassembly for an STM32F103, even though you expect only 16-bit THUMB instructions. This discrepancy arises because your assembler defaults to using THUMB-2, which includes both 16-bit and 32-bit instructions. you can try this out if your intent on 16bit
.syntax unified
.thumb

movs r0, #40 // 16-bit immediate move
movs r1, #2 // 16-bit immediate move
adds r2, r0, r1 // 16-bit add
mvns r0, #0x28 // 16-bit mvn with 8-bit immediate
bx r0 // Branch exchange
.syntax unified
.thumb

movs r0, #40 // 16-bit immediate move
movs r1, #2 // 16-bit immediate move
adds r2, r0, r1 // 16-bit add
mvns r0, #0x28 // 16-bit mvn with 8-bit immediate
bx r0 // Branch exchange
arm-none-eabi-as -mthumb -mcpu=cortex-m3 -o main.o main.S
arm-none-eabi-as -mthumb -mcpu=cortex-m3 -o main.o main.S
arm-none-eabi-objdump -d -m thumb main.o
arm-none-eabi-objdump -d -m thumb main.o
3 replies