<div dir="ltr"><div dir="ltr">On Sun, Mar 27, 2022 at 9:38 PM John Stout <<a href="mailto:cuspcomputers@gmail.com">cuspcomputers@gmail.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hello everyone</div><div dir="ltr"><br></div><div dir="ltr">I'm working on a compiler and emulation of the RISC processor detailed in the latest (?) edition of Compiler Construction by Professor Wirth from <a href="http://www.projectoberon.net/wirth/CompilerConstruction/CompilerConstruction.pdf" target="_blank">CompilerConstruction1.pdf (projectoberon.net)</a>.</div><div dir="ltr"><br></div><div dir="ltr">I can't follow the Oberon code for the emulator in section 9.5 in the section handling memory instructions, which differs from Peter De Wachter's Oberon RISC emulator at <a href="https://github.com/pdewacht/oberon-risc-emu.git" target="_blank">https://github.com/pdewacht/oberon-risc-emu.git</a> </div><div dir="ltr"><br></div><div>In Compiler Construction, once an instruction has been decoded as a memory instruction the address is calculated using</div><div><br></div><div><font face="monospace">adr := (R[b] + IR MOD 100000H) DIV 4;</font></div><div><br></div><div dir="ltr">which (apart from the DIV 4) agrees with the code in <font face="monospace">oberon-risc-emu</font> (which also sign extends the offset before adding it).</div><div dir="ltr"><br></div><div dir="ltr">If <font face="monospace">adr >= 0</font><font face="arial, sans-serif"> then a load is carried out, and the N and Z flags set depending on the value loaded.</font></div><div dir="ltr"><font face="arial, sans-serif">However (and this is the bit I don't understand) if </font><font face="monospace">adr < 0</font><font face="arial, sans-serif"> then a store is carried out, whereas in oberon-risc-emu u bit of the instruction is checked and if 0 a load is carried out and if 1 a store is carried out.</font></div><div dir="ltr"><font face="arial, sans-serif"><br></font></div><div dir="ltr"><font face="arial, sans-serif">Since I know </font><font face="monospace">oberon-risc-emu</font><font face="arial, sans-serif"> works, and that agrees with the settings for the u and v bits in Compiler Construction then I assume that must be the correct implementation, but is there an error in Compiler Construction or am I missing something very simple?</font></div><div dir="ltr"><font face="arial, sans-serif"><br clear="all"></font><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>All the best.</div><div><br></div><div>John Stout</div></div></div></div></div></div></div></div></div></div></div></div></div></blockquote><div><br></div><div>Have a closer look. In Compiler Construction the test for load / store is NOT based on the sign of adr, it is based on one of the following equivalent tests:</div><div><br></div><div>IF ~ODD(IR DIV 20000000H)  (* in the book *)<br></div><div><br></div><div>or</div><div><br></div><div>IF ~ODD(ASH(IR, -29)) (* in the accompanying source code *)<br></div><div><br></div><div>--</div><div>Regards,</div><div>Chris Burrows</div><div>CFB Software</div><div><a href="https://www.astrobe.com/RISC5">https://www.astrobe.com/RISC5</a></div><div><br></div></div></div>