[A83] Re: returning to OS in call routines


[Prev][Next][Index][Thread]

[A83] Re: returning to OS in call routines



> IMHO, assembly programming was not meant for the "perfect academic
> model".  Assembly languages always contain some form of "jp", and it is
> always needed.  Higher level languages were designed to break away from
> this (hence "goto" is frowned upon on c, and non-existent in java and
> other languages).  But even in higher level languages, how do you think
> if-then statements get compiled?  (warning: simplification ahead)  They
> use a simple comparison followed by a jump.  No matter what you do, you
> are eventually going to use the equivalent of goto.  Higher level
> languages mask this, assembly cannot.
> 
> With that said, it IS usually better (read: easier, not necessarily
> faster) to structure your program in such a way that code is broken up
> into modular routines that are called, not jumped to.
> 
> - - Joe Pemberton
> 

While I see your point, I don't think it fair to consider JPs a synonym to
GOTOs. Look at the following:

for i := 1 to 10 do
begin
  // do something
  if not(cond) then goto EndOfLoop;
  // do something else
EndOfLoop:
end;

for i := 1 to 10 do
begin
  // do something
  if cond then
  begin
    // do something else
  end;
end;

These pieces of code should compile to the same ASM code. This is
completely okay according to the academic model (at least, if you
use the second form). Here, while you are using a GOTO ("implicitly"
in the second case), you can verify correctness. The corresponding
JPs are not of the "evil" kind. On the other hand, you can also write
code like this:

// do something
goto SomeLabel;
for i := 1 to 10 do
begin
  // do something
SomeLabel:
  // do something else
end;

I don't know if there's a language that would compile that, but it's
definitely illegal according to any academic model I know. The JP
the compiler would use to translate this GOTO is definitely evil.
Note that this kind of construction cannot be easily changed to
eliminate the GOTO as was the case in the first example.

My explanation is not as clear as I'd like it to be. You could take
a look at the work of E. W. Dijkstra, especially "Goto statements
consider harmful" (or was it "Goto's considered harmful"?), for
more (and definitely better) information.

Grtz,
Rob van Wijk


-- 
COMPUTERBILD 15/03: Premium-e-mail-Dienste im Test
--------------------------------------------------
1. GMX TopMail - Platz 1 und Testsieger!
2. GMX ProMail - Platz 2 und Preis-Qualitätssieger!
3. Arcor - 4. web.de - 5. T-Online - 6. freenet.de - 7. daybyday - 8. e-Post




References: