0

So I know that in assembly, each register just holds a series of bits. However, these series of bits can either be interpreted as signed or unsigned.

Is there a way to force assembly to interpret a series of bits in a register as unsigned/signed? After loading in a global unsigned C variable into an assembly register, all the registers end up being interpreted as unsigned quantities but I need things to be interpreted as signed quantities.

  • 2
    You haven't specified a CPU architecture. But often you would use separate instructions. For example, on x86 `JB` is "Jump if (unsigned) below" while `JL` is "Jump if (signed) less". – Michael Oct 22 '20 at 08:07
  • Another good duplicate: [distinguishes between signed and unsigned in machine code](https://stackoverflow.com/q/51943912). Most of the duplicates I found are x86. I threw in one Z80 one; there are MIPS ones I've seen but which didn't show up in the first page of google. – Peter Cordes Oct 22 '20 at 08:21
  • "all the registers end up being interpreted as unsigned quantities" -- by whom? The debugger printing them (in hex), perhaps, not necessarily by the program itself. The debugger is not an authority on how the program will interpret the values. The authority is the program and its upcoming instructions. – Erik Eidt Oct 22 '20 at 12:10
  • When does it matter signed vs. unsigned: when enlarging a value from smaller bit count to larger bit count (e.g. 16 bit -> 32 bit); when comparing values for inequality relationships (e.g. <, <=); when checking for overflow on addition. So, when the program does these things, it should use the right instructions. – Erik Eidt Oct 22 '20 at 12:13
  • I realized that the program I was writing was interpreting the bits as signed quantities even though they were being displayed as unsigned quantities in the gdb debugger. I was under the impression they were being interpreted as unsigned quantities because of how things were displayed when using layout regs. I was getting errors because I didn't use the appropriate set of cqto/cwtl type of instructions. – Alex Snyder Oct 23 '20 at 14:45

0 Answers0