Re: [LONG, off-topic]] Interactive Programming

From: Brandon Crosby <bcrosby@mncs.k12.mn.us> Subject: Interactive Programming To: cypherpunks@toad.com Date: Tue, 7 Oct 1997 08:04:05 -0500 (CDT) Reply-to: Brandon Crosby <bcrosby@mncs.k12.mn.us>
I know that this isn't precisely on subject, but...
Most of the people on this list probally do some amount of programming, right? Does anyone have information about self-modifing programs/routines? Thanks for the help.
-Brandon Crosby
This probably *is* off-topic. Cypherpunks these days is mainly political discussion. Serious crypto programming has moved over to coderpunks, and this topic is not really crypto related, either. Your use of the term 'self-modifying' needs clarification. I used to write self-modifying code back when I was doing heavy assembler work, but only for performance reasons - on some processors it was faster to modify the address of an absolute memory reference by changing the instruction, than it was to use an indexed memory reference. Self-modifying code of this type is difficult to write, non-portable, non-reentrant, and usually to be avoided like the plague. I haven't done it in years, and use the story mainly to convince rookie programmers that I'm a scary dude. LISP programmers are much more into writing programs which build and execute routines on the fly. You might want to talk to someone into AI. But for a Real Programmer, and a true story of self-modifying code, heres: --------------------- The Story of Mel, a Real Programmer This was posted to USENET by its author, Ed Nather (utastro!nather), on May 21, 1983. A recent article devoted to the *macho* side of programming made the bald and unvarnished statement: Real Programmers write in FORTRAN. Maybe they do now, in this decadent era of Lite beer, hand calculators, and "user-friendly" software but back in the Good Old Days, when the term "software" sounded funny and Real Computers were made out of drums and vacuum tubes, Real Programmers wrote in machine code. Not FORTRAN. Not RATFOR. Not, even, assembly language. Machine Code. Raw, unadorned, inscrutable hexadecimal numbers. Directly. Lest a whole new generation of programmers grow up in ignorance of this glorious past, I feel duty-bound to describe, as best I can through the generation gap, how a Real Programmer wrote code. I'll call him Mel, because that was his name. I first met Mel when I went to work for Royal McBee Computer Corp., a now-defunct subsidiary of the typewriter company. The firm manufactured the LGP-30, a small, cheap (by the standards of the day) drum-memory computer, and had just started to manufacture the RPC-4000, a much-improved, bigger, better, faster -- drum-memory computer. Cores cost too much, and weren't here to stay, anyway. (That's why you haven't heard of the company, or the computer.) I had been hired to write a FORTRAN compiler for this new marvel and Mel was my guide to its wonders. Mel didn't approve of compilers. "If a program can't rewrite its own code", he asked, "what good is it?" Mel had written, in hexadecimal, the most popular computer program the company owned. It ran on the LGP-30 and played blackjack with potential customers at computer shows. Its effect was always dramatic. The LGP-30 booth was packed at every show, and the IBM salesmen stood around talking to each other. Whether or not this actually sold computers was a question we never discussed. Mel's job was to re-write the blackjack program for the RPC-4000. (Port? What does that mean?) The new computer had a one-plus-one addressing scheme, in which each machine instruction, in addition to the operation code and the address of the needed operand, had a second address that indicated where, on the revolving drum, the next instruction was located. In modern parlance, every single instruction was followed by a GO TO! Put *that* in Pascal's pipe and smoke it. Mel loved the RPC-4000 because he could optimize his code: that is, locate instructions on the drum so that just as one finished its job, the next would be just arriving at the "read head" and available for immediate execution. There was a program to do that job, an "optimizing assembler", but Mel refused to use it. "You never know where it's going to put things", he explained, "so you'd have to use separate constants". It was a long time before I understood that remark. Since Mel knew the numerical value of every operation code, and assigned his own drum addresses, every instruction he wrote could also be considered a numerical constant. He could pick up an earlier "add" instruction, say, and multiply by it, if it had the right numeric value. His code was not easy for someone else to modify. I compared Mel's hand-optimized programs with the same code massaged by the optimizing assembler program, and Mel's always ran faster. That was because the "top-down" method of program design hadn't been invented yet, and Mel wouldn't have used it anyway. He wrote the innermost parts of his program loops first, so they would get first choice of the optimum address locations on the drum. The optimizing assembler wasn't smart enough to do it that way. Mel never wrote time-delay loops, either, even when the balky Flexowriter required a delay between output characters to work right. He just located instructions on the drum so each successive one was just *past* the read head when it was needed; the drum had to execute another complete revolution to find the next instruction. He coined an unforgettable term for this procedure. Although "optimum" is an absolute term, like "unique", it became common verbal practice to make it relative: "not quite optimum" or "less optimum" or "not very optimum". Mel called the maximum time-delay locations the "most pessimum". After he finished the blackjack program and got it to run ("Even the initializer is optimized", he said proudly), he got a Change Request from the sales department. The program used an elegant (optimized) random number generator to shuffle the "cards" and deal from the "deck", and some of the salesmen felt it was too fair, since sometimes the customers lost. They wanted Mel to modify the program so, at the setting of a sense switch on the console, they could change the odds and let the customer win. Mel balked. He felt this was patently dishonest, which it was, and that it impinged on his personal integrity as a programmer, which it did, so he refused to do it. The Head Salesman talked to Mel, as did the Big Boss and, at the boss's urging, a few Fellow Programmers. Mel finally gave in and wrote the code, but he got the test backwards, and, when the sense switch was turned on, the program would cheat, winning every time. Mel was delighted with this, claiming his subconscious was uncontrollably ethical, and adamantly refused to fix it. After Mel had left the company for greener pa$ture$, the Big Boss asked me to look at the code and see if I could find the test and reverse it. Somewhat reluctantly, I agreed to look. Tracking Mel's code was a real adventure. I have often felt that programming is an art form, whose real value can only be appreciated by another versed in the same arcane art; there are lovely gems and brilliant coups hidden from human view and admiration, sometimes forever, by the very nature of the process. You can learn a lot about an individual just by reading through his code, even in hexadecimal. Mel was, I think, an unsung genius. Perhaps my greatest shock came when I found an innocent loop that had no test in it. No test. *None*. Common sense said it had to be a closed loop, where the program would circle, forever, endlessly. Program control passed right through it, however, and safely out the other side. It took me two weeks to figure it out. The RPC-4000 computer had a really modern facility called an index register. It allowed the programmer to write a program loop that used an indexed instruction inside; each time through, the number in the index register was added to the address of that instruction, so it would refer to the next datum in a series. He had only to increment the index register each time through. Mel never used it. Instead, he would pull the instruction into a machine register, add one to its address, and store it back. He would then execute the modified instruction right from the register. The loop was written so this additional execution time was taken into account --- just as this instruction finished, the next one was right under the drum's read head, ready to go. But the loop had no test in it. The vital clue came when I noticed the index register bit, the bit that lay between the address and the operation code in the instruction word, was turned on --- yet Mel never used the index register, leaving it zero all the time. When the light went on it nearly blinded me. He had located the data he was working on near the top of memory -- the largest locations the instructions could address --- so, after the last datum was handled, incrementing the instruction address would make it overflow. The carry would add one to the operation code, changing it to the next one in the instruction set: a jump instruction. Sure enough, the next program instruction was in address location zero, and the program went happily on its way. I haven't kept in touch with Mel, so I don't know if he ever gave in to the flood of change that has washed over programming techniques since those long-gone days. I like to think he didn't. In any event, I was impressed enough that I quit looking for the offending test, telling the Big Boss I couldn't find it. He didn't seem surprised. When I left the company, the blackjack program would still cheat if you turned on the right sense switch, and I think that's how it should be. I didn't feel comfortable hacking up the code of a Real Programmer. ----------------- Peter Trei trei@process.com

Peter - Thanks for a trip down nostalgia road. At 2:55 AM -0700 10/7/97, Peter Trei wrote:
I first met Mel when I went to work for Royal McBee Computer Corp., a now-defunct subsidiary of the typewriter company. The firm manufactured the LGP-30, a small, cheap (by the standards of the day) drum-memory computer, and had just started to manufacture the RPC-4000, a much-improved, bigger, better, faster -- drum-memory computer. Cores cost too much, and weren't here to stay, anyway. (That's why you haven't heard of the company, or the computer.)
Ah, the third machine I programmed in machine language was a LGP-30. It brings back fond memories of the not so good old days.
Mel's job was to re-write the blackjack program for the RPC-4000. (Port? What does that mean?) The new computer had a one-plus-one addressing scheme, in which each machine instruction, in addition to the operation code and the address of the needed operand, had a second address that indicated where, on the revolving drum, the next instruction was located.
My first machine, the IBM 650 had this feature. The last one I saw was in a technical museum in Vienna. ------------------------------------------------------------------------- Bill Frantz | Internal surveillance | Periwinkle -- Consulting (408)356-8506 | helped make the USSR the | 16345 Englewood Ave. frantz@netcom.com | nation it is today. | Los Gatos, CA 95032, USA

-----BEGIN PGP SIGNED MESSAGE----- reference to Peter Trei's posting of Mel's super blackjack game. Mel was living in a Warner Center condo off Topanga Canyon Blvd in Woodland Hills CA the last time I had contact with him which is at least 10 years, before the earthquake which did significant damage to that area. I checked my old databases for his number, but it did not pop out, but I can not scan all... I can only presume Mel is still among the living as he must be about 10 years older than I which makes him 67+, and he had put some hard milage on by the time I first met him in '77: I took over, as a corporate hatchet, in a recently purchased division (nee: small company), a deeply troubled bleeding edge DC to daylight bandwidth test instrument program -- and inherited Mel. at the time, when the weather was good, Mel would arrive in a bright red Mercedes 450SL; and, Mel is not small. it seems Mel had traded his wife in on the car --said it was "...cheaper." Mel's regular mode was a 20 year old collection of baling wire. the project had DGs so the drums were gone -just 5Mb removable packs. personally, I never saw a Royal-McBee, but I remember IBM drums: 250K bytes on the 31 gal barrel size! I thought I was a pretty mean assembly hack --until I met Mel. I hired him in on other projects I was salvaging for other companies later. his coding style had not changed over the ensuing years: it worked, but it was virtually incomprehensible to the new generation of hot shots --only to us old farts who had survived by our wits and the "cheating" --sort of like turning assembly language into Forth. most of us lived in a different world of hacker "social" ethics: "Go not unto Usenet for advice, for the inhabitants will say yes, and no, and maybe, and I don't know, and fuck off, and...." --attila well, I *am* old enough to be father to most of you, and for the really wet behind the ears crowd, probably even your grandfather. and I have the nicks and cuts to go with it. ...when unix was a pdp11/45 with three stack registers, bocu bucks/month maintenance to DEC for only 64K instruction and 64K data space, and RP4 (if you were lucky) washing machine drives... there was a time when "hacker" was a BADGE OF HONOUR, until some asshole sensationalist from Time Magazine or the NY Times had to apply "hacker" to Morris and his runaway worm, which started Morris down the road to crucifixion for the public good. so, despite the behaviour of a few bad apples: a hacker is a professional in his own world a hacker's only language is AFL a cracker is a criminal. *****at least fifteen years ago, this was making the rounds: 1> What do 'hackers' and 'real programmers' look like? No-one knows, they're like graffitists. 2> What do hackers eat? ... Diet Pepsi, Corndogs, etc. 3> What kind of things do hackers do with computers? Hackers patch and tweak, Programmers code and debug. 4> What kind of computers do hackers use? Anything that's available. (they don't always like them) 5> Where do hackers live, and what kind of place is it in which they reside? In or near 'The Valley' (pick one) Usually in a rented house, and in a mess of misc. hardware, listings, Mass media, and food wrappings. 6> Where do hackers come from? (High schools, colleges, etc.) Most are self taught while going to school for some other vocation. 7> What languages do hackers use? Hackers: whatever's available, including HEX and OCTAL, occasionally BINARY. Programmers: C, assemblers, Forth, Lisp, Apl 7a> What languages do they hackers use? Hackers: none Programmers: Basic, Cobol, Fortran, RPG, Algol, Logo 8> In what environment do they function best? Late at night with low light levels. (except for the CRTs) 9> what kind of computer is for *real* men? Real men don't waste valuable time on Intel 86 family assembly code. a> What makes you respond in such a way? The philosophy: 'Less is More', or if I might quote Albert Einstein: "Everything should be made as simple as possible, but not simpler" and that my friends, is the difference a code of honour makes.... ____________________________________________________________________________ "In nature, stupidity gets you killed. In the workplace, it gets you promoted. In politics, it gets you re-elected." --attila -----BEGIN PGP SIGNATURE----- Version: 2.6.3i Charset: latin1 Comment: No safety this side of the grave. Never was; never will be iQCVAwUBNDp3Yr04kQrCC2kFAQH6/QQAr9mWc9upwAcmcg+iMwVOjTbMvO9rgtxv dLOCaHiWkeXWhc+goFHGc87vsjCfb7W0TcRGE3cG6F5DnMRR8/nUwT4iVyIshjWC bv5Puf49zbfdL11Gu/0jKvl81Z2rna31P5o6AOEkEzLTxJsLKMnDyXHQtPsobfKj 9BNUDXAEoUI= =WoYN -----END PGP SIGNATURE-----

-----BEGIN PGP SIGNED MESSAGE----- On Tue, 7 Oct 1997, Peter Trei wrote:
Does anyone have information about self-modifing programs/routines?
Avoid them like the plage. There a true PIA to do anything with.
LISP programmers are much more into writing programs which build and execute routines on the fly.
As are some perl programmers. As both a perl programmer and a lisp programer I have never had the need to use self modifing code. In fact I would consider haveing to use s-m code as a sine that I have made a mistate in my desinge. - -- Please excuse my spelling as I suffer from agraphia see the url in my header. Never trust a country with more peaple then sheep. ex-net.scum and proud You Say To People "Throw Off Your Chains" And They Make New Chains For Themselves? --Terry Pratchett -----BEGIN PGP SIGNATURE----- Version: 2.6.3i Charset: noconv iQCVAwUBNDtGo6QK0ynCmdStAQGy+AP/bHIcXSSW5id/DAQm+IhUlaHTrS0wZxds KE0Y8dAkwNCoQ+/N5J8aaT4UWfKnR8HHb/7QOggHVTvjVXVF1Q/gIBfDh3TGrwpO 0VztWIEg9K9SjjJFxFgO3ig0bcwtbqEXuE5P4WVeOJhJgNjgm6UgPg38UuZ+EJZ6 G1k7D/IyeRI= =L5S2 -----END PGP SIGNATURE-----

In any event, I was impressed enough that I quit looking for the offending test, telling the Big Boss I couldn't find it. He didn't seem surprised.
Reminds me of a time, years ago, where I was trying to modify a program written in 6502 assembler. In addition to pervasive self-modifing code, another extremely popular practice of the era was inlined function-call parameters. Unlike the C approach, which most of you are probably familiar with, where parameters are pushed onto the stack, then a subroutine is called which pops them, instead the subroutine would pop the return address, and use it as a pointer to the function parameters. At the end of the function, the return address pointer would be incremented and jumped to. You're probably thinking, this is nuts. Why would anyone do this? Consider the following line of C code: result = function(x,y,z); One could write this in 6502 assembler as: JSR function DATA x DATA y DATA z STA result where x,y,z,result are pointers to storage locations. This made coding in assembler just as easy as coding in C, and it took less memory because you didn't need all those push/pop instructions. Doing this on a modern processor would probably wreck havok on the decode pipeline. Apple's ProDOS used this type of calling sequence, and most disassemblers dealt with this special case by correctly identifying the parameters as such. But one of the worst I ran into was this: JSR printf ASC "Hello, world!",0 ... You can imagine what the disassembler did with that. Spit out all sorts of garbage as it tried to interpret the ASCII string "Hello, world!" as machine instructions. I encountered this in some BBS software, and had a real difficult time reading it. Finally I got the idea of taking the partially disassembled code, identifying all the branch target addresses, then redisassembling starting at those addresses. It worked. After a few iterations of this I had all the entry points, and everything that didn't disassemble cleanly was outputted as hex data. For fun, run objdump on a cleanly compiled unix binary... It makes it all look so easy... :)
participants (5)
-
? the Platypus {aka David Formosa}
-
Attila T. Hun
-
Bill Frantz
-
ghioï¼ temp0132.myriad.ml.org
-
Peter Trei