Thread View: comp.lang.misc
1 messages
1 total messages
Started by Erland Sommarskog
Wed, 17 Dec 1986 21:52
Assembler vs. high-level languages
Author: 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.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads