TRAP程序与子程序

本文主要介绍了TRAP程序与子程序的基本组成和应用。首先学习了系统调用的基本概念,然后学习了LC-3TRAP程序的基本内容和操作说明。通过图解学习TRAP和RET两种程序并做了比较。举例说明TRAP程序架构在实际操作中的应用。
展开查看详情

1.Chapter 9 TRAP Routines and Subroutines

2.System Calls

3.System Call

4.LC-3 TRAP Mechanism

5.TRAP Instruction

6.TRAP

7.RET (JMP R7)

8.TRAP Mechanism Operation

9.TRAP Routines and their Assembler Names

10.Example: Using the TRAP Instruction

11.

12.9- 12 Example: Output Service Routine TRAP_PUTS ST R0,OS_SAVE_R0 ; save R0, R1, and R7 ST R1,OS_SAVE_R1 ST R7,OS_SAVE_R7 ADD R1,R0,#0 ; move string pointer (R0) into R1 TRAP_PUTS_LOOP LDR R0,R1,#0 ; write characters in string using OUT BRz TRAP_PUTS_DONE OUT ADD R1,R1,#1 BRnzp TRAP_PUTS_LOOP TRAP_PUTS_DONE LD R0,OS_SAVE_R0 ; restore R0, R1, and R7 LD R1,OS_SAVE_R1 LD R7,OS_SAVE_R7 RET stored in table, location x22

13.9- 12 Example: Output Service Routine TRAP_PUTS ST R0,OS_SAVE_R0 ; save R0, R1, and R7 ST R1,OS_SAVE_R1 ST R7,OS_SAVE_R7 ADD R1,R0,#0 ; move string pointer (R0) into R1 TRAP_PUTS_LOOP LDR R0,R1,#0 ; write characters in string using OUT BRz TRAP_PUTS_DONE OUT ADD R1,R1,#1 BRnzp TRAP_PUTS_LOOP TRAP_PUTS_DONE LD R0,OS_SAVE_R0 ; restore R0, R1, and R7 LD R1,OS_SAVE_R1 LD R7,OS_SAVE_R7 RET stored in table, location x22

14.9- 12 Example: Output Service Routine TRAP_PUTS ST R0,OS_SAVE_R0 ; save R0, R1, and R7 ST R1,OS_SAVE_R1 ST R7,OS_SAVE_R7 ADD R1,R0,#0 ; move string pointer (R0) into R1 TRAP_PUTS_LOOP LDR R0,R1,#0 ; write characters in string using OUT BRz TRAP_PUTS_DONE OUT ADD R1,R1,#1 BRnzp TRAP_PUTS_LOOP TRAP_PUTS_DONE LD R0,OS_SAVE_R0 ; restore R0, R1, and R7 LD R1,OS_SAVE_R1 LD R7,OS_SAVE_R7 RET stored in table, location x22

15.9- 12 Example: Output Service Routine TRAP_PUTS ST R0,OS_SAVE_R0 ; save R0, R1, and R7 ST R1,OS_SAVE_R1 ST R7,OS_SAVE_R7 ADD R1,R0,#0 ; move string pointer (R0) into R1 TRAP_PUTS_LOOP LDR R0,R1,#0 ; write characters in string using OUT BRz TRAP_PUTS_DONE OUT ADD R1,R1,#1 BRnzp TRAP_PUTS_LOOP TRAP_PUTS_DONE LD R0,OS_SAVE_R0 ; restore R0, R1, and R7 LD R1,OS_SAVE_R1 LD R7,OS_SAVE_R7 RET stored in table, location x22

16.9- 12 Example: Output Service Routine TRAP_PUTS ST R0,OS_SAVE_R0 ; save R0, R1, and R7 ST R1,OS_SAVE_R1 ST R7,OS_SAVE_R7 ADD R1,R0,#0 ; move string pointer (R0) into R1 TRAP_PUTS_LOOP LDR R0,R1,#0 ; write characters in string using OUT BRz TRAP_PUTS_DONE OUT ADD R1,R1,#1 BRnzp TRAP_PUTS_LOOP TRAP_PUTS_DONE LD R0,OS_SAVE_R0 ; restore R0, R1, and R7 LD R1,OS_SAVE_R1 LD R7,OS_SAVE_R7 RET stored in table, location x22

17.9- 12 Example: Output Service Routine TRAP_PUTS ST R0,OS_SAVE_R0 ; save R0, R1, and R7 ST R1,OS_SAVE_R1 ST R7,OS_SAVE_R7 ADD R1,R0,#0 ; move string pointer (R0) into R1 TRAP_PUTS_LOOP LDR R0,R1,#0 ; write characters in string using OUT BRz TRAP_PUTS_DONE OUT ADD R1,R1,#1 BRnzp TRAP_PUTS_LOOP TRAP_PUTS_DONE LD R0,OS_SAVE_R0 ; restore R0, R1, and R7 LD R1,OS_SAVE_R1 LD R7,OS_SAVE_R7 RET stored in table, location x22

18.9- 12 Example: Output Service Routine TRAP_PUTS ST R0,OS_SAVE_R0 ; save R0, R1, and R7 ST R1,OS_SAVE_R1 ST R7,OS_SAVE_R7 ADD R1,R0,#0 ; move string pointer (R0) into R1 TRAP_PUTS_LOOP LDR R0,R1,#0 ; write characters in string using OUT BRz TRAP_PUTS_DONE OUT ADD R1,R1,#1 BRnzp TRAP_PUTS_LOOP TRAP_PUTS_DONE LD R0,OS_SAVE_R0 ; restore R0, R1, and R7 LD R1,OS_SAVE_R1 LD R7,OS_SAVE_R7 RET stored in table, location x22