mov ax, 0ffffh
inc ax
inc ax
Was watching a video on basic Intel X86 Assembly.
I thought 0FFFFH was 65535 but in the video they got -1 instead (before the inc
instructions run). Just wondering how and why?
mov ax, 0ffffh
inc ax
inc ax
Was watching a video on basic Intel X86 Assembly.
I thought 0FFFFH was 65535 but in the video they got -1 instead (before the inc
instructions run). Just wondering how and why?
0xFFFF, 65535, and -1 are all the same bit pattern: sixteen one's, no zeros — so it is a matter of interpretation as to which we choose to print or say.
It is an important aspect of programming to consistently view your values the same way, and in assembly/machine code it is very easy to mix up unlike things.
In high level languages we have logical variables, and give types to variables, so whenever the variable is used, the program knows whether the variable is signed or unsigned or other. Debuggers for high-level languages also know the type of declared variables, so will never print -1 for an unsigned integer, for example.
However, in assembly we have physical storage, and this storage is untyped — just some bits being stored. So, we can interpret those bits in a variety of ways, as signed numbers, as unsigned numbers, as characters (e.g. unicode or other character set), etc..
Machine code debuggers & instruction set simulators generally don't know what type the programmer intended, as assembly language is lacking in this type information, plus what little is available is lost in machine code. It is up to the program to consistently treat storage as to what type it is, and so then up to the programmer to view physical storage with the proper type in mind.