You are a stupid programmer, you can't have that

claptrap clap at trap.com
Mon Aug 9 22:57:22 UTC 2021


On Monday, 9 August 2021 at 22:01:33 UTC, Adam D Ruppe wrote:
> On Monday, 9 August 2021 at 21:05:05 UTC, H. S. Teoh wrote:
>> Indeed!  If you look at the assembly level, unsigned 
>> arithmetic is the one with straightforward instructions 
>> mapping 1-to-1 with arithmetic operations, whereas signed 
>> arithmetic is the one that involves carry bits and other such 
>> additional complications.
>
> They're literally identical for most operations; you can use 
> the very same instructions and the only difference is how you 
> interpret the data. In x86 they set both carry and overflow 
> flags so you can decide which one you care about.

Since there's only ADD,SUB,MUL(IMUL),DIV(IDIV), it's about 50/50. 
Half the ops have only unsigned versions, half have signed and 
unsigned.

IIRC the overflow flag is actually just for catching the error, 
not for actual arithmetic, since if you're doing signed multiword 
arithmetic you only use a signed word at the top.

That's why there's ADC, SBB, but no equivalents for the overflow 
flag.


More information about the Digitalmars-d mailing list