MIPS输入字符串“ 2147483648”“如何返回”错误:输入号是两个大。
检查MIPS算法溢出 错误:.ASSCIIZ“错误:输入号是两个大。” 缓冲区:。空间256
Checking MIPS algorithm overflow
error: .assciiz "error: the input number is two big."
buffer: .space 256
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于QTSPIM,使用SYSCALL#5,输入整数,似乎无法检测到何时用户输入超过32位签名的整数范围。 没有成功/失败错误代码,鉴于用户输入的任何内容,SYSCALL返回的值仅被截断为32位 1 。
如果您想进行溢出检查,则您将从控制台接受字符串数据(而不是整数数据),然后将字符串解析为整数检查该分析期间的溢出。
这样的解析涉及将乘法乘以10,并为每个数字增加一个添加,因此使用一种方法,这些算术操作都需要涉及溢出检查。
重要的是,与SYSCALL#5不同,对分析的输入将是字符串,并且输出既可以 a a catut a state a state a state a state an Cate and a Status a a Status and a State a a State和数字值,因此您的程序可以自定义行为。状态可能表明成功或各种失败,例如非数字字符和溢出。
可以在整数上确定溢出过程中确定溢出的其他方法,因为我们知道有关小数位数的某些事实,例如,每个数字最多都会添加9个数字;由于我们知道总数有11个数字(或更多)会溢出(如果存在的话,则不计入领先的零)。
例如,另一种方法是计算中间分析结果64位,然后仅在转换为32位时,检查与原始64位值的32位值的匹配是溢出)。 由于64位仍可能溢出,因此还应使用这种方法来使用总非零数字的计数,其中11以上的任何东西都表明溢出。
其他受欢迎的MIP模拟器火星在Syscall#5上溢出了一个不同的挑战/机会 - 它在溢出上例外,但这并不像Java或C#异常,很容易被捕获和处理,而是这是一个错误,这是一个错误。在主管模式下将控制转移到内核异常处理程序。
对此有用的事情将是高级操作系统课程的主题。 首先,一旦您编写了自己的内核异常处理程序,就必须准备处理所有可能的处理器异常,而不仅仅是溢出;对于另一个,您必须区分溢出条件和其他条件,以便您可以单独处理它们;最后,没有用于使用Syscall#5告诉溢出的用户模式程序的预定义界面,这已经发生了,以及用户模式程序想要做的事情,因此您必须提供此类机制。
1  这些模拟器有效地实现了有用但一组不规则的系统调用 - 似乎没有尝试制作完整或圆形的SYSCALL操作集。 例如,您可以从/到该控制台读取或打印整数或字符串,但只能从文件中读取或打印字符串 - 如果您想使用文件而不是与整数一起使用文件,则必须将自己的int编写为字符串,反之亦然。
For QtSpim, using syscall #5, input integer, there appears to be no way to detect when user input exceeds the 32-bit signed integer range. No success/failure error code is returned, and the value returned by the syscall, given whatever the user entered, is simply truncated to 32 bits1.
If you want to do overflow checking, you'll have accept string data (instead of integer data) from the console and parse the string to integer checking for overflow during that parse.
Such a parse involves doing a multiplication by 10 and an addition for each digit, so with one approach both of those arithmetic operations would need to involve overflow checking.
Importantly, the input to the parse would be a string, and the output would both a status and a numeric value, unlike syscall #5, so your program can customize behavior. The status could indicate success, or failures of various kinds, such as non-digit characters, and overflow.
Other approaches to determining the overflow during parse of string to integer are possible, since we know certain facts about decimal digits, such as at most 9 will be added each digit; since we know that 11 total digits (or more) it will overflow (not counting leading zeros, if present).
For example, an alternative approach is to compute the intermediate parse result in 64-bits, then only when converting to 32 bits, check for match of the 32-bit value with the original 64-bit value (match is ok, non-match is overflow). Since 64 bits can still overflow, counting of total non-zero digits should also be employed with this approach, where anything over 11 would indicate overflow.
The other popular MIPS simulator MARS presents a different challenge/opportunity on overflow with syscall #5 — it takes an exception on overflow, but this is not like a Java or C# exception that is easily caught and handled, but instead this is a fault that transfers control to the kernel exception handler in supervisor mode.
Doing something useful with that would be a topic of advanced operation system coursework. For one, once you write your own kernel exception handler, you have to be prepared to handle all possible processor exceptions, not just overflow; for another you have to differentiate between the overflow condition and the others so you can handle them separately; and lastly, there's no predefined interface for telling the overflowing user-mode program using syscall #5, that this has occurred, and what the user-mode program wants to do about it, so you'd have to provide such mechanism.
1 These simulators implement effectively useful but an irregular set of system calls — there appears no attempt made to make a complete or well rounded set of syscall operations. For example, you can read or print an integer or string from/to the console, but can only read or print strings from files — if you want to use files instead of the console with integers, now you have to write your own int to string and vice versa.