Exception/Error handling in NASM assembly

时光毁灭记忆、已成空白 提交于 2020-01-05 04:47:06

问题


How do I handle errors in NASM assembly? For example I have this code to read user Input:

mov eax,3
mov ebx,0
mov ecx,Buffer
mov edx,BUFFERLENGTH
int 80H

If for some reason this system call cannot be executed, I'd like to have the program jump to a label that prints "An error has occured" or something like that. How do I do that?

Also, is it possible to get the name of the exception or error code?

Thanks


回答1:


After the kernel call, EAX is going to have two possibilites;

  • Number of characters entered.
  • Negated error code.

                int     80H
                or      eax, eax
                jns     OK        ; Tests sign flag
    
                neg     eax       ; Converts error code to positive value
        ;   Error trapping here
    
           OK:  dec     eax       ; Bump by one cause length includes CR
                jnz     Good
        ; Do something special if operator only entered CR
    
         Good:  nop
    

    This is an example how you could evaluate if there is an error and if operator even entered anything.



来源:https://stackoverflow.com/questions/39713883/exception-error-handling-in-nasm-assembly

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