QtSPIM: Explanation for code shown without loading program

假装没事ソ 提交于 2020-03-05 04:07:09

问题


The QtSPIM MIPS assembler already shows some lines of code even though there is no program loaded, like can be seen on https://ecs-network.serv.pacific.edu/ecpe-170/tutorials/qtspim-tutorial.

I assume this is required for loading programs, but I would be very interested in an exact explanation to understand all details.


回答1:


A QtSPIM program consists of two parts: an exception handler, and a user program.

The default exception handler includes both a short user-mode startup code sequence (loaded at 0x00400000 as well as the actual exception handler located in kernel memory .ktext, which starts at 0x80000180,

When you load your user program, it is appended to the user-mode code (from the exception handler) at about location 0x00400024.  You can also see that until you load your program with your main, that the address of main (in that startup code) is taken as 0, aka undefined.

You can replace the default exception handler with your own.  Use Simulator menu, Settings submenu, MIPS tab, Load Exception Handler (or Use default exception handler).

In your exception handler file, you would put your actual handler after a .ktext directive, and, you would put your start sequence after a .text directive — which is optional. If you don't supply one then main has nowhere to return to, so to terminate the simulator normally, you would have to exit via syscall instead of simply returning.

The other popular simulator, MARS, does not include this default user mode startup code sequence so MARS programs always have to exit from main using a syscall.

The default exception handler prints the reason for the exception and doesn't do much else.

If you want to do interrupt driven console I/O, you would write your own exception handler, for example.  QtSPIM also supports a timer, which also uses the interrupt mechanism.  You can also implement trap handler (teq, tne, teqi, tnei instructions), but the syscall instruction is always handled by QtSPIM outside of the MIPS exception handling mechanism.



来源:https://stackoverflow.com/questions/59823995/qtspim-explanation-for-code-shown-without-loading-program

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