[Oberon] FPGA - Little Endian & Bit numbering
Jörg
joerg.straube at iaeth.ch
Fri Sep 22 15:46:27 CEST 2017
Hi
Unfortunately, it is not explicitly defined whether Oberon uses "MSB 0" and
"LSB 0".
So, there are two questions
- How could we find out?
- Why do we need to know?
The only type where bits have numbers is SET.
With a variable "s" of type SET you can write: INCL(s, 0) (* put bit 0 into
the set s *).
As long as you don't convert SETs to INTEGERs, you don't have to bother
where this bit 0 is stored in memory. Whether bit 0 is MSB or LSB is
irrelevant as this code
INCL(s, 0);
IF 0 IN s THEN Out.String("TRUE") ELSE Out.String("FALSE") END;
will always write out TRUE.
In Oberon-07, with the standard function ORD(s) you can convert a SET to an
INTEGER.
And here the dilemma starts: ORD() is very vaguely defined!!
With the following code you can find out, whether the Oberon compiler and
the CPU uses "LSB 0" or "MSB 0".
IF ORD({0}) = 1 THEN Out.String("LSB 0") ELSE Out.String("MSB 0") END;
The bad thing is, this code MIGHT generate different results on different
machines, as ORD is not well defined. Principally "ORD" should be in MODULE
SYSTEM as it's implementation specific, e.g. ORD("A") is not defined at all.
Almost everybody assumes it's the ASCII value 65 but it could also return
EBCDIC value 193, but this is off-topic.
It might be to your surprise, but it will turn out that most Oberon
implementations use "LSB 0"
Why do you need to know?
Most probably you played with bitmaps and found out that the bit 0 is the
left most bit on the screen.
Or even worse: if you want to move a pixel to the RIGHT on the screen, you
have to use LSL() (logical shift LEFT).
This phenomenon has nothing to do with "LSB 0" or "MSB 0" but is a pure
definition of how the display driver maps the memory bits to the screen. Or
in short: Playing with pixels on the screen is VERY implementation dependent
:-)
br
Jörg
-----Original Message-----
From: Oberon [mailto:oberon-bounces at lists.inf.ethz.ch] On Behalf Of Tomas
Kral
Sent: Friday, September 22, 2017 11:31 AM
To: Oberon@ <lists.inf.ethz.ch.Oberon at lists.inf.ethz.ch>
Subject: [Oberon] FPGA - Little Endian & Bit numbering
Hi,
I learnt earlier OberonV5 is little endian.
Toying with bit reversal, and printing in binary, I further discovered
that bit numbering is MSB 0, correct?
Example, printing 128 in binary gives,
0000001
Also when shifting bits in display buffer,
shifting bits left = moves screen bits visually to right
shifting bits right = moves screen bits visually to left, correct?
This may explain why bit reversal, and endian conversion is needed in
`Screen.Mod' to produce bitmaps for the outside world.
Little endian + MSB 0 simplifies h/w design, correct?
--
Tomas Kral <thomas.kral at email.cz>
--
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