What does the assembly instruction trap do?

拟墨画扇 提交于 2019-12-23 01:54:34

问题


"RTFM"

A program typically issues a software trap when the program requires servicing by the operating system. The general exception handler for the operating system determines the reason for the trap and responds appropriately.

Is the assembly instruction trap alike the instruction TRAP in BASIC? The answer seems to be yes. Can you accept or reject my conclusion?

Code for "no interruption" is according to my instructions:

noint:
    PUSH r8
    movia r8,0x003b683a # machine code for TRAP
    ldw et,-4(ea) # read instr closest to return
    cmpeq et,et,r8 # compare
    POP r8
    bne et,r0,TrapHandler # if equal, jump to traphandler

Update

AFAIK in BASIC you can write e.g.

10 TRAP 20

to make row 20 the row for handling an error.


回答1:


Not sure what TRAP does in BASIC, but the TRAP instruction in the assembler manual that you linked generates a hardware exception that can be handled by the operating system.

There is rarely need for a programmer to use this instruction in their code. The typical use of it is to be inserted by a debugger into the code being debugged at the point where a stop is desired (breakpoint), then running/continuing the program, and regaining control once the TRAP instruction is reached.




回答2:


User processes can transition into the operating system kernel voluntarily, to request that the kernel do some operation on the user’s behalf. A system call is any procedure provided by the kernel that can be called from user-level. Most processors implement system calls using a special trap instruction.



来源:https://stackoverflow.com/questions/13557371/what-does-the-assembly-instruction-trap-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!