| |||
| Home > Interworking ARM and Thumb > Assembly language interworking example | |||
This example implements a short header section (SECTION 1)
followed by an ADR instruction to get the address
of the label THUMBProg, and sets the least significant
bit of the address. The BX instruction changes
the state to Thumb state.
In SECTION2, the Thumb code adds the contents
of two registers together, using an ADR instruction to
get the address of the label ARMProg, leaving
the least significant bit clear. The BX instruction changes
the state back to ARM state.
In SECTION3 the ARM code adds together
the contents of two registers and ends.
Example 32. Assembly language interworking
; ********
; addreg.s
; ********
PRESERVE8
AREA AddReg,CODE,READONLY ; Name this block of code.
ENTRY ; Mark first instruction to call.
; SECTION1
start
ADR R0, ThumbProg:OR:1 ; Generate branch target address
; and set bit 0, hence arrive
; at target in Thumb state.
BX R0 ; Branch exchange to ThumbProg.
; SECTION2
THUMB ; Subsequent instructions are Thumb code.
ThumbProg
MOVS R2, #2 ; Load R2 with value 2.
MOVS R3, #3 ; Load R3 with value 3.
ADDS R2, R2, R3 ; R2 = R2 + R3
ADR R0, ARMProg
BX R0 ; Branch exchange to ARMProg.
; SECTION3
ARM ; Subsequent instructions are ARM code.
ARMProg
MOV R4, #4
MOV R5, #5
ADD R4, R4, R5
; SECTION 4
stop MOV R0, #0x18 ; angel_SWIreason_ReportException
LDR R1, =0x20026 ; ADP_Stopped_ApplicationExit
SVC 0x123456 ; ARM semihosting
END ; Mark end of this file.
Follow these steps to build and link the modules:
To assemble the source file for interworking, type:
armasm --debug --apcs=/interwork addreg.s
To link the object files, type:
armlink addreg.o -o addreg.axf
Alternatively, to view the size of the interworking veneers, type:
armlink addreg.o -o addreg.axf --info=veneers
Run the image using a compatible debugger with an appropriate debug target.
Assembler Reference:
Linker Reference: