📄 tinyworldex.s
字号:
AREA TinyWorld, CODE, READONLY ; name this block of code
ENTRY ; Define entry point
CODE32 ; assemble as ARM instructions
; The code labelled 'reset' will be loaded at 0x0
; and so contains a simple vector table for
; handling execptions. The reset vector at 0x0
; branches to the main body of the code.
; The SWI vector branches to a minimal SWI handler.
; Any other exceptions will simply branch to the reset
; vector.
; ************** Reset Handler ********************
reset
B main ; reset - set up system
B reset ; undefined instruction
B SWI_handler ; software interrupt (SWI)
B reset ; prefetch abort
B reset ; data abort
NOP ; reserved
B reset ; IRQ
B reset ; FIQ
; ************** Swi Handler **********************
; minimal SWI handler
SWI_handler
STMFD sp!, {r0-r3, lr} ; stack working registers
;actual swi handler goes here
LDMFD sp!, {r0-r3, pc}^ ; return to user mode, note ^
; ************ System Setup **********************
; perform some basic system setup
; create stacks for both user and supervisor modes
main
; Set up a register to act as a stack pointer
; Core resets in supervisor mode
MOV sp, #0x1000 ; sp is r13
MRS r0, CPSR ; load CPSR into r0
BIC r0, r0, #0xff ; mask the bottom byte
ORR r0, r0, #0x10 ; set for user mode
MSR CPSR_c, r0 ; perform switch to user mode
MOV sp, #0x2000 ; setup stack for user mode
B user_application
; ************ User App **********************
user_application
; Do some simple arithmetic.
MOV r0, #3 ; Set up registers
MOV r1, #2
ADD r2, r0, r1 ; r2 = r0 + r1
MUL r3, r0, r1 ; r3 = r0 * r1
; Now call a subroutine
BL memory
; Continue data processing operations.
SUB r4, r0, r1 ; r4 = r0 - r1
; more user application code can be added here...
; end of code - loop forever
stop
B stop
memory
; This subroutine copies four words of memory from [source] to [dest]
; using LDR/STR and then another four words using LDM/STM
STMFD sp!, {r0-r7} ; Push working registers onto stack
LDR r0, =source ; Load r0 with address of 'source'
LDR r1, =dest ; Load r1 with address of 'dest'
; Copy 4 words using LDR/STR instructions in a loop
MOV r3, #4
loop
LDR r2, [r0], #4
STR r2, [r1], #4
SUBS r3, r3, #1
BNE loop
; Now copy 4 words using block copy LDM/STM instructions
LDMIA r0!, {r4-r7}
STMIA r1!, {r4-r7}
LDMFD sp!, {r0-r7} ; Restore working registers
BX lr ; Return from subroutine
AREA Exdata, DATA, READWRITE ; name this block of data
source DCD 1, 2, 3, 4, 5, 6, 7, 8
dest DCD 0, 0, 0, 0, 0, 0, 0, 0
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -