Here's a historical program reading exercise. The three programs in question all do the same thing, written in different generation programming languages. Your assignment, should you choose to accept it, is to determine what the programs do. ---- First, here's the machine code for the Bendix G-15, a mid-size first-generation production computer. Even with annotation, the code isn't very revealing. L N T C S D 59 00.20.1.07.28 skeleton command: (07:00) --> AR 00 03.03.0.23.31 clear MQ,ID,PN 03 05.06.0.25.20 ID --> (20:01) 06 07.09.0.21.24 (21:03) --> MD 09 40.50.0.26.31 shift MQ 20 bits left 50 51.52.0.24.21 MQ(odd) --> (21:03) 52 55.56.1.21.28 (21:03) --> AR 56 59.60.1.00.29 AR + (00:59) --> AR 60 62.62.0.31.31 execute command in AR 20 21.24.1.20.29 AR + (20:01) --> AR 24 25.26.1.28.22 AR --> (22:01) 26 29.30.0.22.25 (22:01) --> ID 30 31.33.0.22.25 (22:03) --> MQ 33 56.90.0.24.31 multiply 90 93.94.0.26.20 PN --> (20:01) 94 95.96.1.21.28 (21:03) --> AR 96 98.99.3.22.29 AR - (22:02) --> AR 99 u0.55.0.28.27 Test AR zero 55 00.01.1.07.28 (07:00) --> AR 01 05.07.1.20.29 AR + (20:01) --> AR 07 09.10.1.28.20 AR --> (20:01) 56 program exit The only other hints you get: * storage locations (07:00), (07:01), etc along with (22:03) are the input data, (20:01) holds the result. * The memory of the machine in question consists of a magnetic drum with 24 tracks. The N field of each instruction denotes the location (L) of the next instruction to be executed. The S and D field indicate source and destination tracks, the T field of most instructions indicates the location of operands on the selected tracks. * AR, ID, MQ, and PN are registers. ''Great. I always wondered what the code looked like that was mentioned in the StoryOfMel. Must be like this. Thanks for this insightful historical example. -- GunnarZarncke'' ---- OK. Here's the same program in Pegasus Autocode, which might be considered a "second-generation" language. v3 <- 0.0 1) v3 <- v3+v(10+n1) v3 <- v3 × v2 n1 <- n1-1 ->1, n1 > 0 v3 <- v3+v10 Hints: * Pegasus Autocode provides real variables named v0, v1, ..., v8191, and integer variables named n0, n1..., n27. * -> represents a branch instruction. ---- Here's the same snippet in CeeLanguage, proud heir to the Algol/Fortran tradition: y = 0.0; for (; n > 0; n--) y = (y + a[n]) * x; y += a[0]; ---- Discussion to follow. ''Well, the answer is:'' Gur shapgvba rinyhngrf n cbylabzvny (n[a] k^a) va gur cbvag k. ------ I assume that the C example is a program fragment? Otherwise you've got the small problem of setting the values for a[] and n. One takeaway: the lower level the language, the more important it is to have inline commentary. The best handwritten assembly language programs I've read are mostly commentary. ''Maybe I'm warped or something, but once I became familiar with certain conventions of the Bendix code, I realized right away that it was a kind of vector operation. No commentary was needed for that, in the specific. Beyond that, attempting to derive some invariants would have resulted in a clearer picture of what was happening. Since the answer is already on this page, I decided I was content knowing that I could understand the gist of the ancient code, if not the specifics.'' ---- CategoryHistory