Search code examples
assemblyintegersigned

why the assembler does not report error on this?


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.


Solution

  • 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.