[Oberon] Assembler Cast example.

Michael Schierl schierlm at gmx.de
Sat Oct 3 19:52:40 CEST 2020

Am 03.10.2020 um 15:27 schrieb peter at easthope.ca:

> Question "6. How do I cast a large number of variables very fast?"
> refers to procedure Cast.  My knowledge of assembler is almost zero.
> How does Loop terminate?

"Loop:" is just a label to name the next instruction.
It becomes a loop by this two commands later:

    CMP   ECX, 0
    JG    Loop

The first command will compare the ECX register to zero, which will set
the flag register according to the result. The second command will Jump
to the instruction labelled by the Loop label if the flag register
indicated that the first operand of the comparison is Greater than the
second one.

The code also shows that the knowledge of its author of x86 assembly
language is not the greatest. Since most Assembler programmers would
know that the DEC instruction a few instruction higher sets the Zero
flag when decrementing 1 to 0 and the Sign flag when decrementing 0 to
-1, so you could add a JS jump to exit the loop after the DEC
instruction (saving a useless CMP instruction and some CPU cycles).

And if they did not know that, they would probably know that "OR CX, CX"
has the same effect as "CMP CX, 0", while needing less bytes and being
slightly faster on 386 and older (and same speed on 486 and later).

But in the spirit of Oberon, the assembly code was simple and did the
job well enough.



More information about the Oberon mailing list