[Oberon] BYTE to/from INTEGER conversion
Jörg
joerg.straube at iaeth.ch
Wed Jul 6 16:30:53 CEST 2016
Hi Srinivas
As you can see in
https://www.inf.ethz.ch/personal/wirth/Oberon/Oberon07.Report.pdf chapter
6.1
BYTE is unsigned (0..255), INTEGER is signed.
Now, ORB wants to read and store bytes as signed values (-128 and 127)
b has 8 bit, x has 32 bit.
When writing, the processor just takes the last 8 bit of x.
If you call ORB.Write(R, -1) it stores the value 0FFH to the file.
Shortening by cutting bits is automatic.
When reading Files.ReadByte will return b = 255, but ORB wants to see -1.
The problem with the assignment x := b is that the processor has to know how
to fill the upper 24 bit of x. As ORB wants to change from UNSIGNED (b) to
SIGNED (x) we have to tell the processor, how to fill the upper 24 bits of
x.
Jörg
-----Original Message-----
From: Oberon [mailto:oberon-bounces at lists.inf.ethz.ch] On Behalf Of Srinivas
Nayak
Sent: Mittwoch, 6. Juli 2016 15:32
To: ETH Oberon and related systems <oberon at lists.inf.ethz.ch>
Subject: [Oberon] BYTE to/from INTEGER conversion
In ORB.Mod.txt we see
PROCEDURE Read(VAR R: Files.Rider; VAR x: INTEGER);
VAR b: BYTE;
BEGIN Files.ReadByte(R, b);
IF b < 80H THEN x := b ELSE x := b - 100H END
END Read;
and
PROCEDURE Write(VAR R: Files.Rider; x: INTEGER);
BEGIN Files.WriteByte(R, x)
END Write;
Here, Read gets a BYTE from Files.ReadByte(R, b)
and converts that BYTE to INTEGER using IF .. END
But, Write passes the INTEGER directly to Files.WriteByte(R, x)
where prototype of WriteByte is PROCEDURE WriteByte*(VAR r: Rider; x: BYTE);
That means, compiler is able to convert a 4 byte INTEGER implicitly to a 1
byte BYTE,
But the reverse is not possible...
How can I understand this?
Please shed some light on this.
With thanks and best regards,
Yours sincerely,
Srinivas Nayak
Home: http://www.mathmeth.com/sn/
Blog: http://srinivas-nayak.blogspot.in/
--
Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
https://lists.inf.ethz.ch/mailman/listinfo/oberon
More information about the Oberon
mailing list