为什么汇编器不报告错误?
考虑一个非常简单的汇编语言程序中的以下两条语句:
DATA1 DB +200
DATA2 DB -130
当我尝试汇编它时,汇编器在第 2 条语句上给出错误,因为字节可以容纳超过 -128 十进制的错误。但是为什么汇编器没有在 no 1 语句上给出错误呢?毕竟,一个字节最多可以容纳 127 个正符号整数。相反,将值 C8 放入该字节中。
Consider the following two statements out of a very simple assembly language program:
DATA1 DB +200
DATA2 DB -130
when I try to assemble it, assembler gives error on no 2 statement, as it should since a byte can hold beyond -128 decimal. But why assembler didn't give error on no 1 statement? afterall, a byte can hold max 127 positive signed integer.. instead assemlber put the value C8 in that byte.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
任何数字在汇编成可执行文件时都会转换为位数组。例如,-1 是 0xFF,-2 是 0xFE,等等。-1 和 255 之间的唯一区别在于它在代码中的使用方式。汇编器并不关心,它只是想存储数据供您使用。
Any number is converted to an array of bits when it is assembled into the executable. -1, for example, is 0xFF, -2 is 0xFE, etc. The only difference between -1 and 255 is how it is used in your code. The assembler doesn't care, it just wants to store the data for you to use.
也许它不知道文字是有符号的还是无符号的。对于汇编器来说,我并不觉得这太令人惊讶,两者都有用例。
-130 永远不适合一个字节,因为它必须有符号并且小于 -128。另一方面,200 非常适合无符号字节,这似乎确实是汇编器所采用的视图,如果将 0xC8 解释为无符号字节,则 0xC8 就是 200。
Perhaps it doesn't know whether or not the literal is signed or unsigned. For an assembler, I don't find that too surprising, there are use-cases for both.
-130 never fits into a byte, since it must be signed and is smaller than -128. 200, on the other hand, fits just fine into an unsigned byte, and that does seem to be the view the assembler takes, 0xC8 is 200 if interpreted as an unsigned byte.
所以要点是:
Peter Abel 的《IBM PC 汇编语言和编程》。
so the gist is:
Peter Abel's "IBM PC assembly language and programming".