<HTML><HEAD>
<META content="text/html charset=utf-8" http-equiv=Content-Type></HEAD>
<BODY
style="WORD-WRAP: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space"
dir=ltr>
<DIV dir=ltr>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: 'Arial'; COLOR: #000000">
<DIV>Sure, but then, since the amount of shift is a variable, it will oblige
one</DIV>
<DIV>to index into a table of such constants, which is rather clumsy, and</DIV>
<DIV>possibly (?) poorly optimised by the compiler.</DIV>
<DIV> </DIV>
<DIV><FONT face=Consolas>PROCEDURE ReadInt (VAR x: INTEGER) =</FONT></DIV>
<DIV><FONT face=Consolas> VAR ch: CHAR; n, y := 0;</FONT></DIV>
<DIV><FONT face=Consolas> BEGIN</FONT></DIV>
<DIV><FONT face=Consolas> Read (ch);</FONT></DIV>
<DIV><FONT face=Consolas> WHILE ch >= 128 DO</FONT></DIV>
<DIV><FONT face=Consolas> INC (y, Word.LeftShift
(ORD (ch) - 128, n));</FONT></DIV>
<DIV><FONT face=Consolas> INC (n, 7);</FONT></DIV>
<DIV><FONT face=Consolas> Read (ch)</FONT></DIV>
<DIV><FONT face=Consolas> END;</FONT></DIV>
<DIV><FONT face=Consolas> x := <EM>arithmetic-shift</EM>
(Word.LeftShift (ORD (ch), 25), n - 25) + y</FONT></DIV>
<DIV><FONT face=Consolas> END ReadInt;</FONT></DIV>
<DIV
style='FONT-SIZE: small; TEXT-DECORATION: none; FONT-FAMILY: "Calibri"; FONT-WEIGHT: normal; COLOR: #000000; FONT-STYLE: normal; DISPLAY: inline'>
<DIV style="FONT: 10pt tahoma">
<DIV><FONT size=3 face=Arial></FONT> </DIV>
<DIV style="BACKGROUND: #f5f5f5">
<DIV style="font-color: black"><B>From:</B> <A title=hosking@purdue.edu
href="mailto:hosking@purdue.edu">Antony Hosking</A> </DIV>
<DIV><B>Sent:</B> Saturday, July 04, 2015 12:11 PM</DIV>
<DIV><B>To:</B> <A title=dmuysers@hotmail.com
href="mailto:dmuysers@hotmail.com">dirk muysers</A> </DIV>
<DIV><B>Cc:</B> <A title=m3devel@elegosoft.com
href="mailto:m3devel@elegosoft.com">m3devel@elegosoft.com</A> </DIV>
<DIV><B>Subject:</B> Re: [M3devel] Arithmetic Shift</DIV></DIV></DIV>
<DIV> </DIV></DIV>
<DIV
style='FONT-SIZE: small; TEXT-DECORATION: none; FONT-FAMILY: "Calibri"; FONT-WEIGHT: normal; COLOR: #000000; FONT-STYLE: normal; DISPLAY: inline'>In
this code you use DIV by a constant power of two. That will turn into an
arithmetic right shift.
<DIV>
<DIV> </DIV>
<DIV>
<BLOCKQUOTE type="cite">
<DIV>On Jul 4, 2015, at 7:48 PM, dirk muysers <<A
href="mailto:dmuysers@hotmail.com">dmuysers@hotmail.com</A>> wrote:</DIV>
<DIV> </DIV>
<DIV>
<DIV dir=ltr>
<DIV dir=ltr>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: arial">
<DIV><SPAN class=_Tgc>Why is there no arithmetic right shift operation in
Modula-3 ?</SPAN></DIV>
<DIV><SPAN class=_Tgc></SPAN> </DIV>
<DIV><SPAN class=_Tgc>Oberon software has a clever way to minimally
encode</SPAN></DIV>
<DIV><SPAN class=_Tgc>signed integers independently of their
size.</SPAN></DIV>
<DIV><SPAN class=_Tgc></SPAN> </DIV>
<DIV><SPAN class=_Tgc><FONT face=Consolas>PROCEDURE WriteInt (i: INTEGER)
=</FONT></SPAN></DIV>
<DIV><SPAN class=_Tgc><FONT face=Consolas> BEGIN</FONT></SPAN></DIV>
<DIV><SPAN class=_Tgc><FONT face=Consolas> WHILE x < –64
OR x > 63 DO</FONT></SPAN></DIV>
<DIV><SPAN class=_Tgc><FONT face=Consolas> Write
(VAL (i MOD 128 + 128, CHAR));</FONT></SPAN></DIV>
<DIV><SPAN class=_Tgc><FONT face=Consolas> i :=
i DIV 128;</FONT></SPAN></DIV>
<DIV><SPAN class=_Tgc><FONT face=Consolas>
END;</FONT></SPAN></DIV>
<DIV><SPAN class=_Tgc><FONT face=Consolas> Write (VAL (i MOD
128), CHAR));</FONT></SPAN></DIV>
<DIV><SPAN class=_Tgc><FONT face=Consolas> END
Write;</FONT></SPAN></DIV>
<DIV><SPAN class=_Tgc><FONT face=Arial></FONT></SPAN> </DIV>
<DIV><SPAN class=_Tgc>Unfortunately it is impossible to implement the
corresponding</SPAN></DIV>
<DIV><SPAN class=_Tgc>decoder in M3, because it requires an arithmetic right
shift</SPAN></DIV>
<DIV><SPAN class=_Tgc>where the sign bit is replicated into the left
end.</SPAN></DIV></DIV></DIV></DIV>_______________________________________________<BR>M3devel
mailing list<BR><A
href="mailto:M3devel@elegosoft.com">M3devel@elegosoft.com</A><BR>https://mail.elegosoft.com/cgi-bin/mailman/listinfo/m3devel<BR></DIV></BLOCKQUOTE></DIV>
<DIV> </DIV></DIV></DIV></DIV></DIV></BODY></HTML>