Article View: comp.lang.misc
Article #4527Assembler vs. high-level languages
From: Erland Sommarskog
Date: Wed, 17 Dec 1986 21:52
Date: Wed, 17 Dec 1986 21:52
35 lines
2084 bytes
2084 bytes
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.
Technical Details
Message-ID:
<1567@enea.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!seismo!mcvax!enea!sommarShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!mcvax!enea!sommar From: sommar@enea.UUCP (Erland Sommarskog) Newsgroups: comp.lang.misc Subject: Assembler vs. high-level languages Message-ID: <1567@enea.UUCP> Date: Wed, 17-Dec-86 16:52:08 EST Article-I.D.: enea.1567 Posted: Wed Dec 17 16:52:08 1986 Date-Received: Thu, 18-Dec-86 20:36:57 EST Reply-To: sommar@enea.UUCP (Erland Sommarskog) Organization: ENEA DATA Svenska AB, Sweden Lines: 34