Is it a lost cause?

Agreed, but it got into early COBOL as the ALTER ... TO PROCEED TO ... statement. IMO its the worst misfeature that ever got into a high level language. I've seen it used in the past about once, in the worst-written system I've ever had the misfortune to see. Apart from ALTER statements it had:

- meaningless data names (all records and fields over 4 tape files called MTnn where nn incremented in each successive line) and so on for CFnn (cards), LPnn (line printer) and WSnn (working storage).

- no sections in PROCEDURE DIVISION, only paragraphs which all had 5 digit numeric names, but not in any detectable sequence or meaningful order.

The outfit I worked for had unfortunately bought it. It was immediately scrapped when we saw the code and we wrote an equivalent but much better system from scratch, but I digress....

ALTER was declared obsolete in COBOL 1985 and removed from the specification in 2002 but apparently is still supported by some compilers.

--
martin@   | Martin Gregorie 
gregorie. | Essex, UK 
 Click to see the full signature
Reply to
Martin Gregorie
Loading thread data ...

Sounds fun.

Do you mean you could permanently alter a goto statement as it were?

--
Future generations will wonder in bemused amazement that the early  
twenty-first century?s developed world went into hysterical panic over a  
 Click to see the full signature
Reply to
The Natural Philosopher

It was pretty fun on the PDP-10 and 360, but it was more of a band-aid for holes in the instruction set. On the 360 I think the vast majority of EX instructions were to get the effect of a MVC or other storage to storage instruction with a variable length operand. That was certainly what they had in mind when they made it modify the second byte of the instruction.

Oh, I'm sure that if we think hard we can come up with something worse.

Yup. Fortran provided the same bad idea with assigned GOTOs:

222 ASSIGN 666 TO HELL 666 GO TO HELL,(666,222) END

(In most flavors of Fortran the list of statement numbers in the assigned goto was optional.)

The original Fortran system didn't have subroutines, so you faked them with assigned gotos.

Reply to
John Levine

I'm not sure if I mentioned it is *this* group recently, but BCPL had that. Only worse.

--
Using UNIX since v6 (1975)... 

Use the BIG mirror service in the UK: 
 Click to see the full signature
Reply to
Bob Eager

I don't see how EX is self modifying code. No code is modified at all.

Huh?

Don't know about X86, but EX is not used for I/O.

Even better than EX is EXRL (Execute using a relative address instead of base displacement. The EXRL solves the clutter that comes from using a label in column 1. If you are using structured programming macros and indentation, a label messes up everything.

Here's one way to use EXRL:

SR R1,R1 clear R1 IC R1,LEN len of data to move IF (AHI,R1,-1,NZ) calc len - 1 for MVC and test for no move needed MVC TARGET(0),SOURCE move first byte EXRL R1,*-6 move all the bytes ENDIF , The reference to *-6 is the start of the MVC instruction so, no label needed.

The trick is that you can safely move the first byte (TARGET(0) overrides any length attribute TARGET might have). There is no significant performance hit because you're just really getting the SOURCE and TARGET fields into cache for the real move. Another benefit is that the MVC and EXRL are right next to each other making the code easier to read.

--
Dan Espen
Reply to
Dan Espen

FWIW, in APL you can generate an arbitrary string, store it in a variable, and try to execute the variable. If the string is valid APL then it will execute. APL being APL a line of code can do a tremendous lot, including editing the function in which it is contained.

Reply to
J. Clarke

I don't remember you doing so.

My only brush with BCPL was when I found a article including a source listing of the GPM. As it was something I wanted to play with and I didn't have a BCPL compiler, I hand translated it into Algol 60 on a

1900. BCPL, or the subset used to write the GPM, was evidently not that hard to read since the Algol version ran almost straight away and successfully generated 'One Man Went to Mow', which I used as a test piece.
--
martin@   | Martin Gregorie 
gregorie. | Essex, UK 
 Click to see the full signature
Reply to
Martin Gregorie

If you were interested in GPM, try ML/I. See:

formatting link

OK, in BCPL you could modify the *label* (using past tense although it's still around). Labels were first class objects; every label declared a storage cell (BCPL was typeless), and the cell was initialised to contain the address of the code being labelled. A GOTO retrieved the contents of that cell and placed it in the PC (e.g. by using a compiled indirect jump).

But *you could assign another value to the label*. And make that GOTO go somewhere else!

--
Using UNIX since v6 (1975)... 

Use the BIG mirror service in the UK: 
 Click to see the full signature
Reply to
Bob Eager

Yep. A common use was, if a program could accept input from cards, paper tape or magnetic tape, you would write it to use one of them, say cards, and use either console switches or a parameter card to tell it which to use for the next run, which would make the program patch itself before starting to process its input.

Of course its inventors thought was that this would be wonderful on small slow machines whose performance would be improved by removing conditional jumps from the main loop but was still somehow big and fast enough to run a COBOL program.

IOW, rather than doing something obvious like:

MAIN_LOOP SECTION. ML-1. GO TO READ-CARDS, READ-PAPER-TAPE, READ-MAG-TAPE DEPENDING ON SELECTED-INPUT. ML-2 .... at the start of the main loop, it was obviously better to write:

MAIN_LOOP SECTION. ML-1. GO TO READ-CARDS. ML-2. ....

and somewhere else, before the main loop was entered you'd have hidden code to do this:

SET_INPUT SECTION. SI-1. IF PAPER-TAPE-SELECTED ALTER ML-1 TO PROCEED TO READ-PAPER TAPE. IF MAG-TALE SELECTED ALTER ML-1 TO PROCEED TO READ-MAG-TAPE. .... MORE INITIALISATION ....

And before you ask, COBOL had computed GO TO from the beginning but AFAICT still doesn't have anything like a PERFORM...DEPENDING statement.

--
martin@   | Martin Gregorie 
gregorie. | Essex, UK 
 Click to see the full signature
Reply to
Martin Gregorie

My computer career was jump-started in high school. I learned many languages (BASIC, Fortran, PL/1, BAL) on several systems (PDP8/e EDU-25 BASIC, JCL for IBM 360/370) and dabbled with others (such as the LGP-21 in the storage room). Code and skill portability is still a virtue!

It think it's wonderful for folks to learn that there's more to computers that Windows on Intel processors.

When I was in high school, none of us had access to a computer where interfacing was encouraged!

-- jeffj

Reply to
Jeff Jonas

This sounds like a different solution to the problem that IBM addressed with DD cards.

Reply to
J. Clarke
[snip]

It is good that you recognise that; now, please get started.

Sincerely,

Gene Wirchenko

Reply to
Gene Wirchenko

Yeah, but it's just an example.

So I tried to imagine a DD card for Paper Tape, and I was coming up blank. So I took a quick look:

formatting link

(The system no longer supports paper tape readers...)

I think those were BTAM devices so, you would still need separate logic for the paper tape.

--
Dan Espen
Reply to
Dan Espen

FORTRAN has several test and GOTO variations as the language evolved

1) arithmetic if

citing

formatting link
IF (expression) negative,zero,positive

example: if (foo - bar) 100,200,300

2) The "computed goto" is FORTRAN's idea of a 'switch' statement, complete with drop-thru from case to case!

citing

formatting link

GO TO ( 10, 20, 30, 40 ), N C drop thru for N 4 ...

10 CONTINUE ... 20 CONTINUE ... 30 CONTINUE ... 40 CONTINUE

3) assigned goto (precursor to setjmp/longjump?)

citing

formatting link
Fortran also had an assigned goto variant that transfers control to a statement label (line number) which is stored in (assigned to) an integer variable.

assign 200 to i ... goto i

4) and at long last, the logical IF if (i .gt. 5) i=5

-- jeffj

Reply to
Jeff Jonas

I've never run a paper tape on a 370 but a bit of googling suggests that somewhere in there there's a "DSORG=CX,BTAM".

I suspect that if I do some digging I'll find somewhere in my files the JCL to send output to a 2741.

Reply to
J. Clarke

Right, but it's off-topic for Fortran II. The additional forms started with Fortran IV.

--

-TV
Reply to
Tauno Voipio

It is - you do construct an instruction, and then run it.

That's right. In 360, it was to fill in the missing possibility to change the fixed length code in the instruction. The needed use in 8080 derivatives was the same, but the cast-in-concrete instructions are for I/O there.

In my vocabulary, any way of building an instruction and then running it is self-modifying code.

The computed GOTO (indirect branch/jump) is a different can of worms. There are perfectly legitimate uses for it, but it is also a way to wreak havoc.

--

-TV
Reply to
Tauno Voipio

I think the 68000 lab was an undergraduate course. I was forced to take it as a pre-requisite because my bachelor's degree was so many years ago, from a different university.

Reply to
Jeff Jonas

Amen to that! Assembler is the only tool for "do EXACTLY WHAT I SAY, do not second-guess-me!", even if it requires reinforcement like EIEIO (do NOT dynamically optimize me!)

I remember the culture shock around 1990 when learning how to transition from CISC to RISC as a programmer and engineer. I had to "trust the compiler" even for assembler to handle things like filling delay branches and other pipeline issues. I fear it is also used to hide errata like instructions that don't really work by silently substituting workarounds.

Semi related: a clever fellow repairing an old Univac built an Arduino nano inside the metal connector to generate test patterns for the console's parallel interface. That's a leap of several generations of technology: a System-on-chip talking to a 2nd generation discrete transistor machine!

An inline .asm is rather close to a language or compiler extension, allowing use of things like instructions for which there is no C syntax.

I remember being given a magic inline .asm for a serial device driver on the Sun Sparc 4m to force the buffer to flush to the interface chip.

Dynamic exploitation of parallelism is a strange and wondrous thing :-)

Reply to
Jeff Jonas

MMm. well lets say you construct a CALL TABLE or JUMP TABLE ...and modify the contents.

or even have the power to write to the PC stack ...

you don't need explicit machine instructions to effect self modifiable code.

And indeed as multitasking scheduler is in a sense self modifying code.

Effect an interruption, save the context, switch the stack pointer, restore new context and IRET.

Anything that is useful is also hazardous

--
Future generations will wonder in bemused amazement that the early  
twenty-first century?s developed world went into hysterical panic over a  
 Click to see the full signature
Reply to
The Natural Philosopher

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.