Level9day3homework

1.保存现场指令是 stmfd sp!, {r4-r8, r14}对应的恢复现场的指令是?

ldmfd sp!,{r4-r8,pc}^

2.实现软中断号6 触发累加和运算(数据是 3,4,5,6),运算后的值保存在R8中(请上传演示视频及源码)

   .text
   @.global _start   
_start:
	b reset										@0x00
	ldr pc, _Undefined_Instruction				@0x04	
	ldr pc, _Software_Interrupt					@0x08
	ldr pc, _Prefetch_Abort						@0x0C
	ldr pc, _Data_Abort							@0x10
	ldr pc, _Rserved							@0x14
	ldr pc, _IRQ								@0x18
	ldr pc, _FIQ								@0x1C
	
_Undefined_Instruction:
	.long Undefined_Instruction
_Software_Interrupt:
	.long Software_Interrupt
_Prefetch_Abort:
	.long Prefetch_Abort
_Data_Abort:
	.long Data_Abort
_Rserved:
	.long Rserved
_IRQ:
	.long IRQ
_FIQ:
	.long FIQ
	
reset:
	mrs r5, CPSR
	ldr r6,=0xFFFFFFE0
	and r5,r6
	orr r5,#0x10
	msr CPSR, r5
	mov r0, #0x0C
	mov r1, #0x0C
	mov r2, #0x0C
	mov r3, #0x0C
	mov r4, #0x0C
	mov r5, #0x0C
	mov r6, #0x0C
	mov r7, #0x0C
	mov r8, #0x0C
	mov r9, #0x0C
	mov r10, #0x0C
	mov r11, #0x0C
	swi #0x06
	mov r3, #0x0c


Undefined_Instruction:
	mov r1,#2

Software_Interrupt:
	ldr sp,=stack_base
	stmfd sp!,{r0-r7,r9-r12,lr}
	mov r0,lr
	sub r0,#4
	ldr r1,[r0]
	bic r1,#0xFF000000
	cmp r1,#6
	bleq do_swi
	ldmfd sp!,{r0-r7,r9-r12,pc}^

do_swi:
	mov r0, #0x3
	mov r1, #0x4
	mov r2, #0x5
	mov r3, #0x6
	mov r8, #0x0
	add r8, r0
	add r8, r1
	add r8, r2
	add r8, r3
	mov pc, lr

Prefetch_Abort:
	mov r3,#4

Data_Abort:
	mov r4,#5

Rserved:
	mov r5,#6

IRQ:
	mov r6,#7
	
FIQ:
	mov r7,#8
	

.data
stack_end:	
.space 200
stack_base:	
.end

结果展示:

  1. usr模式,各个寄存器的状态:
  2. 软中断模式,保存现场:
  3. 软中断模式,计算r8值:
  4. 返回usr模式,r8值,及其他各个寄存器状态