s X-NEWS: spcvxb alt.folklore.computers: 3886Relay-Version: VMS News - V6.0 10/3/90 VAX/VMS V5.3; site spcvxb.spc.edu l Path: spcvxb.spc.edu!njin!rutgers!cs.utexas.edu!samsung!munnari.oz.au!murdu!ucsvc.ucs.unimelb.edu.au!lu!ccmk" Newsgroups: alt.folklore.computers1 Subject: Real programmers program in machine code & Message-ID: <4723@lure.latrobe.edu.au>M From: CCMK@lure.latrobe.edu.au (Mark Kosten - Computer Centre, La Trobe Uni.)  Date: 2 Oct 90 10:46:51 GMT ? Organization: VAX Cluster, Computer Centre, La Trobe University 
 Lines: 164  D I must apologise for two things:  first, I don't read this newsgroupA so if this has appeared before, sorry; second, I have no idea who D wrote this, as I found it on a bulletin board about 10 years ago andG only rediscovered it in my archives recently, so sorry to whoever wrote  it for no author credit.  F I think this is a lovely story that even outdoes "Real Programmers..." ------------------@ A recent article devoted to the macho side of programming ("Real< Programmers Don't Use Pascal") made the bald and unvarnished
 statement:+           Real programmers write in Fortran   F Maybe they do now, in this decadent era of Lite beer, hand calculatorsE and "user-friendly" software, but back in the Good Old Days, when the A 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 C code.  Raw, unadorned, inscrutable, hexadecimal numbers.  Directly.   B Lest a whole new generation of programmers grow up in ignorance ofH this glorious past, I feel duty bound to describe, as best I can throughD the generation gap, how a Real Programmer wrote code.  I'll call him Mel, because that was his name.   C I first met Mel when I went to work for Royal McBee Computer Corp., = a now-defunct subsidiary of the typewriter company.  The firm E manufactured the LGP-30, a small, cheap (by the standards of the day) B drum-memory computer, and had just started to manufacture the RPC-G 4000, a much improved, bigger, better, faster -- drum memory computer.  C Cores cost too much, and weren't here to stay, anyway.  (That's why 3 you haven't heard of the company, or the computer.)   D I had been hired to write a Fortran compiler for this new marvel andB Mel was my guide to its wonders.  Mel didn't approve of compilers.  F If a program can't rewrite its own code", he asked, "what good is it?"  E Mel had written in hexadecimal, the most popular computer program the > company owned.  It ran on the LGP-30 and played blackjack withH potential customers at computer shows.  Its effect was always dramatic. ? The LGP-30 booth was packed at every show, and the IBM salesmen F stood around talking to each other.  Whether or not this actually sold, computers was a question we never discussed.  B Mel's job was to re-write the blackjack program for the RPC-4000. B (Port?  What does that mean?)  The new computer had a one-plus-oneH addressing scheme, in which each machine instruction, in addition to theB operation code and the address of the needed operand, had a secondI address that indicated where, on the revolving drum, the next instruction G was located.  In modern parlance, every single instruction was followed 3 by a GOTO!  Put that in Pascal's pipe and smoke it.   C Mel loved the RPC-4000 because he could optimize his code: that is, I 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, an2 "optimizing assembler", but Mel refused to use it.  B "You never knew where it's going to put things," he explained, "so& you'd have to use separate constants."  G It was a long time before I understood that remark.  Since Mel knew the B numerical value of every operation code, and assigned his own drum@ addresses, every instruction he wrote could also be considered aH numerical constant.  He could pick up an earlier "add" instruction, say,H and multiply by it, if it had the right numeric value.  His code was not  easy for someone else to modify.  C I compared Mel's hand-optimized program with the same code massaged F by the optimizing assembly program, and Mel's always ran faster.  That? was because the "top-down" method of program design hadn't been A invented yet, and Mel wouldn't have used it anyway.  He wrote the J innermost parts of his program loops first, so they would get first choice= of the optimum address locations on the drum.  The optimizing 0 assembler wasn't smart enough to do it that way.  = Mel never wrote time-delay loops, either, even when the balky F Flexowriter required a delay between output characters to work right. G He just locate instructions on the drum so each successive one was just F 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 anF 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".  E After he finished the blackjack program and got it to run, ("Even the H initialiser is optimized", he said proudly) he got a Change Request fromE the sales department.  The program used an elegant (optimized) random E number generator to shuffle the "cards" and deal from the "deck", and H some of the salesmen felt it was too fair, since sometimes the customersD lost.  They wanted Mel to modify the program so, at the setting of aC sense switch on the console, they could change the odds and let the  customers win.  H Mel balked.  He felt this was patently dishonest, which it was, and thatG it impinged on his personal integrity as a programmer, which it did, so E he refused to do it.  The Head Salesman talked to Mel, as did the Big F Boss and, at the boss's urging, a few Fellow Programmers.  Mel finallyG gave in and wrote the code, but he got the test backwards and, when the B sense switch was turned on, the program would cheat, winning everyA time.  Mel was delighted with this, claiming his subconscious was 8 uncontrollably ethical, and adamantly refused to fix it.  A After Mel had left the company for greener pa$ture$, the Big Boss I asked me to look at the code and see if I could find the test and reverse E it.  Somewhat reluctantly, I agreed to look.  Tracking Mel's code was  a real adventure.   G I have often felt that programming is an art form, whose real value can G only be appreciated by another versed in the same arcane art; there are : lovely gems and brilliant coups hidden from human view andF admiration, sometimes forever, by the very nature of the process.  YouJ can learn a lot about an individual just be reading through his code, even4 in hexadecimal.  Mel was, I think, an unsung genius.  E Perhaps my greatest shock came when I found an innocent loop that had H no test in it.  No test.  None.  Common sense said it had to be a closedA loop, where the program would circle forever, endlessly.  Program I control passed right through it, however, and safely out the other side.  & It took me two weeks to figure it out.  B The RPC-4000 computer had a really modern facility called an indexF register.  It allowed the programmer to write a program loop that usedI an indexed instruction inside; each time through, the number in the index J register was added to the address of the instruction, so it would refer to/ the next datum in a series.  Mel never used it.   H Instead, he would pull the instruction in a machine register, add one toC its address, and store it back.  He would then execute the modified B instruction right from the register.  The loop was written so thisB additional instruction time was taken into account -- just as thisH instruction finished, the next one was right under the drum's read head,- ready to go.  But the loop had no test in it.   K The vital clue came when I noticed the index register bit, the bit that lay G between the address and the operation code in the instruction word, wasVK turned on -- yet Mel never used the index register, leaving it zero all theg3 time.  When the light went on it nearly blinded me.c  C He had located the data he was working on near the top of memory --RJ the largest locations the instructions could address -- so, after the lastE datum was handled, incrementing the instruction address would make it E overflow.  The carry would add one to the operation code, changing itCI to the next one in the instruction set: a jump instruction.  Sure enough,oB the next program instruction was in address location zero, and the  program went happily on its way.  G I haven't kept in touch with Mel, so I don't know if he ever gave in tooE the flood of change that has washed over programming techniques since F those long-gone days.  I like to think he didn't.  In any event, I wasH impressed enough that I quit looking for the offending test, telling theH Big Boss I couldn't find it.  He didn't seem surprised.  When I left theE company, the blackjack program would still cheat if you turned on theeG right sense switch, and I think that's how it should be.  I didn't feele5 comfortable hacking up the code of a Real Programmer.  ----- , Mark Kosten,           phone: +61 3 479-2767B Computer Centre,       AARNet (internet): ccmk@lure.latrobe.edu.au2 La Trobe University,   ACSnet: ccmk@lure.lat.oz.au3 Bundoora, 3083         X.25 (PSI): 2347300000::ccmk 	 Australiao