问题
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:
- a number in the default base
- a number in base ten even when the default is something else
- a character code, or
- 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