TIP: Click on subject to list as thread! ANSI
echo: locsysop
to: Bob Lawrence
from: Paul Edwards
date: 1996-09-29 16:05:20
subject: Public Domain Pascal

BL> Whaaat? How does the machine know it's a signed integer? It's
BL> just 32-bits in a register. Are you telling me that computer
BL> hardware has a list of ints, longints, char, words, arrays, and
BL> all that crap?

PE> No, what it actually has (potentially, anyway) is a list of
PE> instructions that assume the 32-bits represent a signed
PE> integer, or an unsigned integer. E.g. the C64, from memory, had
PE> an ASR (arithmetic shift right) and a SHR (shift right), the
PE> latter treating the register as unsigned. MVS had the same, and
PE> I presume intel has the same (look it up). The compiler knows
PE> whether the value is signed or unsigned, and generates the
PE> correct instruction. BFN. Paul. 

BL> I was not talking about the compiler. That can do *anything*.

I answered the question.  No the machine doesn't know whether the 32-bits
are signed or unsigned.  It does however have different instructions.

BL> I've just been through the 80386 instrution set summary (Christ only
BL> knows why I get sucked into these insanities) and I think I see where
BL> you got confused. It does a multiply and divide as a signed or
BL> unsigned integer, 

This has basically answered the question.

BL> but we were talking about logical bitwise shifts.
BL> Your code doesn't do any divides or multiplies, which is what I said
BL> in the first place.

In the first place, I told you why I used unsigned variables when doing shifting.

BL> But in any case, wouldn't the compiler use the correct instruction
BL> to the CPU? VB for instance does not do shifts or unsigned integers,
BL> so it must use the IDIV instruction.

In a signed-magnitude computer, where -2 is represented (16-bit) as

1000 0000 0000 0000 0010

if you did a right shift of 1 bit, what would you expect?

0100 0000 0000 0000 0001  (ie -2 turns into 16385)

or

1000 0000 0000 0000 0001 (ie -2 turns into -1)

???  In either case, both forms have logic behind them, and the machine may
only have instructions to do one of those forms.  So ISO said, if you do
that, you get what you deserve.  Make it unsigned, and you get nice
shifting.  Pascal said "who knows, let's just make it ambiguous, stuff
that, let's just not include shifting in the language at all".

BFN.  Paul.
@EOT:

---
* Origin: X (3:711/934.9)

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.