Main Menu
Main Page
New pages
Recent changes
Random page

Arbitrary code execution
Pokémon cloning
Pomeg glitch and Glitzer Popping
Tweaking and voiding
Glitches by generation
Other glitch categories

Disassembly projects
The Big HEX List
Interactive tools
Reference documents

Legendary Star Blob 2 (Hakuda) (日本語/Japanese)
Pokémon Speedruns wiki (English)
PRAMA Initiative (Français/French)
MissingNo. Glitch City (Italiano/Italian)
Become an affiliate!

Site source code

Search Wiki


Search Forums


Author Topic: Questions in regards to ARM assembly: Swapping between ARM and Thumb  (Read 1415 times)

0 Members and 1 Guest are viewing this topic.


  • Member+
  • *
  • Offline Offline
    • View Profile
Good morning,

I am beginning to learn ARM assembly, and there's one concept i'm not sure I quite grasp.

From ARM's docs, it would seem that if I `bx <reg>|<val>`, the value at <reg>  or <val> respectively needs to have bit 0 set if it is switching from ARM >>> Thumb, and reset if it's going from Thumb >>> ARM.

Would that entail an alignment of the subroutines, to ensure that the bits are set/reset respectively?

Example (GAS Assembler):
Code: [Select]
.align 2
EpsisAmazingSubroutine: @The alignment of this subroutine means that bit 0 is reset, so bx from a thumb subr will switch back to ARM
    stmdb sp!,{lr,fp}
    add fp,sp,#0
    sub sp,sp,#4

    @ var at fp-4 is EpsisAmaingInteger

    mov r3,#3
    str r3,[fp,#-4]

    @ EpsisAmazingInteger is now 3

    sub r0,fp,#4 @ Nab ptr to EpsisAmazingInteger
    bxl add3toInt @ Swap to thumb and call subr

    @ EpsisAmazingInteger should now be 6
    @ Close stack frame and leave

    add sp,fp,#0
    ldm sp!,{fp,lr} @ ARMv4 doesn't change state on pop {pc}
    bx lr

.align 2
.byte 0x69
add3toInt: @ The alignment, coupled by the byte, should set bit 0 of this address
    @ We don't need a stack frame here
    ldr r3,[r0]
    add r3,r3,#3
    str r3,[r0]
    bx lr @ (Hopefully) swap back to ARM and branch to link reg

Note: Assume CPU is ARM7TDMI
« Last Edit: January 27, 2019, 09:16:14 am by Epsilon »


  • The French Lord of Laziness (and a huge The Legend Of Zelda fan)
  • Staff
  • *****
  • Offline Offline
  • Gender: Male
  • Pewter City (B)rocks !
    • View Profile
    • My Little Website
Re: Questions in regards to ARM assembly: Swapping between ARM and Thumb
« Reply #1 on: January 27, 2019, 01:06:22 pm »
Instructions are always aligned, so bit 0 of the address is always 0. That's why it's instead used as a mode bit - you'd use `bx ARMCode` and `bx ThumbCode | 1`.
"THOU SHALL NOT PASS !!"  RIVAL's effect, Gandalf.

Proudly glitching Pokémon Red and Yellow on a Black & White GB, Pocket GB, GB Color, GBA SP and new 3DS.

My Twitter (beware, I'm French)
My YouTube (same warning)

Here is an online tool to build 8F setups : GBz80 to Items !

They see me layzin', they ha-tin'...
Heavy contributor of the global augmentation of entropy (my room's is too damn high !)