What's the difference between `add al, 0` and `add al, '0'`?

孤街浪徒 提交于 2021-02-05 10:40:39

问题


So I've been reading some assembly code for learning purposes and have come across these two instructions:

add    register, value
add    register, 'value'     ; Where the value is now in single quotes

What's the difference between the two?

Before I get flamed if this happens to be a duplicate. I've asked here as I don't know exactly what to Google to answer this question.


回答1:


Depending upon the assembler, enclosing a character in single quotes may request that the compiler use the ASCII code of that character, which for the digit zero would be 48 in decimal or 0x30 in hex. I would guess that's the intention here. Other assemblers use single quotes as part of the syntax for specifying values in different bases (e.g. h'A5' for the value 0xA5 in hex); I'm not sure whether assemblers that use such notation would interpret a value in quotes without a prefix would be interpreted as:

  1. a number in the default base
  2. a number in base ten even when the default is something else
  3. a character code, or
  4. a syntax error

Any of those interpretations would seem plausible, and I would not be terribly surprised if there's some assembler somewhere that would process it in each such fashion.

I would guess the intention of the code is most likely to take the ASCII value of the digit zero, and surrounding instructions would probably make that clear, but without seeing the context I can't really be sure.



来源:https://stackoverflow.com/questions/48102609/whats-the-difference-between-add-al-0-and-add-al-0

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