NASM程序集中的异常/错误处理 [英] Exception/Error handling in NASM assembly

查看:89
本文介绍了NASM程序集中的异常/错误处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何处理NASM组装中的错误? 例如,我有以下代码来读取用户输入:

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?

谢谢

推荐答案

在内核调用之后,EAX将具有两个可能性;

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.

这篇关于NASM程序集中的异常/错误处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆