| |||
| Home > Interworking ARM and Thumb > Interworking using veneers | |||
This example shows interworking of source code in assembly
code to set registers R0 to R2 to
the values 1, 2, and 3 respectively. Registers R0 and R2 are
set by the ARM code. R1 is set by the Thumb code.
The linker automatically adds an interworking veneer. To use veneers:
you must assemble the code
with the --apcs=/interwork option
use a BX lr instruction to return,
instead of MOV pc,lr.
The following example shows assembly language interworking using veneers.
Example 33. Assembly language interworking using veneers
; *****
; arm.s
; *****
PRESERVE8
AREA Arm,CODE,READONLY ; Name this block of code.
IMPORT ThumbProg
ENTRY ; Mark 1st instruction to call.
ARMProg
MOV R0,#1 ; Set R0 to show in ARM code.
BL ThumbProg ; Call Thumb subroutine.
MOV R2,#3 ; Set R2 to show returned to ARM.
; Terminate execution.
MOV R0, #0x18 ; angel_SWIreason_ReportException
LDR R1, =0x20026 ; ADP_Stopped_ApplicationExit
SVC 0x123456 ; ARM semihosting (formerly SWI)
END
; *******
; thumb.s
; *******
AREA Thumb,CODE,READONLY ; Name this block of code.
THUMB ; Subsequent instructions are Thumb.
EXPORT ThumbProg
ThumbProg
MOVS R1, #2 ; Set R1 to show reached Thumb code.
BX lr ; Return to the ARM function.
END ; Mark end of this file.
Follow these steps to build and link the modules:
To assemble the ARM code for interworking, type:
armasm --debug --apcs=/interwork arm.s
To assemble the Thumb code for interworking, type:
armasm --thumb --debug --apcs=/interwork thumb.s
To link the object files, type:
armlink arm.o thumb.o -o count.axf
Alternatively, to view the size of the interworking veneers, type:
armlink arm.o thumb.o -o count.axf --info=veneers
Run the image using a compatible debugger with an appropriate debug target.
Assembler Reference:
Linker Reference: