[comp.lang.misc] Assembler vs. high-level languages

sommar@enea.UUCP (Erland Sommarskog) (12/18/86)

Since this subject happens to be current I'd like to introduce you to a piece
of assembler code I got my eyes on the other day:

AD ,RLP, K-2, UAR   < Add -2 to LP (stack pointer on this machine) and place
                    < the result in the address register (AR)
TR ,K3,  UDM        < Place 3 at the address pointed at by AR (@AR)
TR , EDM, R2        < Move from @AR to R2
TD D, EDM, R3       < This and the next two lines are a range check. The "D"
SU D, R3, K3        < decrements AR
TR D, KL5, JCS      < Jump to KL5 if carry set => range error.
TR  , R2, UDM       < Move R2 to @AR

In Pascal this expressed as (with the range check omitted):
PROCEDURE SomeName;
VAR Nisse : integer;   N1 : 1..5;   N2 : 1..5;     N3 : 1..5;
    N4    : 1..5;      N5 : 1..5;
BEGIN
   Nisse := 3;
   N3    := Nisse;
   
Notice that if we had assigned N4 instead of N3 we would have to reload
the address register. Now we don't need to, since we can decrement while 
checking the range and thus save an instruction. (The "D" does not cost, 
this is a kind of micro-code assembler and every instruction takes one 
clock cycle.)

I must admit that this optimization in a way is quite beautiful and I doubt
I should have found it myself. Now, was this written by a true assembler
hacker? No the Pascal complier generated it. (Of course what else is the 
range check doing there?)

PS: People who writes in assembler daily or works with compiler writing 
    might find this trivial. My excuses for you.
PS2: Don't ask me how that range check works really. I don't know.