Reputation: 9940
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.
Upvotes: 2
Views: 145
Reputation: 9940
so the gist is:
The content of a field mean whatever you intend them to mean. The upshot of all this is that you must have a good idea as to the magnitude of the numbers that your program will process, and you must define field sizes accordinly.
Peter Abel's "IBM PC assembly language and programming".
Also from the same author"ADD and SUB instructions do not distinguish between unsigned and signed data and, indeed, simply add and subtract bits"
Upvotes: 1
Reputation: 4966
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.
Upvotes: 3
Reputation: 400049
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.
Upvotes: 3