Peter Kirby wrote:Interesting point. You could also say that Algol, Fortran, Lisp, C, Prolog, ML, Basic, and all their descendants have let people see higher levels of abstraction in computer science and software engineering more easily. The amount of bookkeeping you need to do in machine code, without macros, means that it's a rare breed who can work with it fluently and do more than very basic things, and arduously at that.
Let's try something more complicated. There is an anecdote which states that when mathematician Karl Friedrich Gauss was a boy, he had a teacher who once tried to keep the class busy by adding up all the integers between 1 and 100 inclusive. According to the story, KFG worked out the answer very quickly: 5050. Here is my simplified assembly code for it:
next load sum # Add the number to the sum
. add num
. store sum
. load num # Increase the number by 1
. add one
. store num
. sub maxnum # Check to see if the CPU has added all the numbers to be added
. br neg, done
. br all, next
done write sum
num dcl 1 # The number's initial value
sum dcl 0 # The numbers' sum
one dcl 1 # What to increase the number by
maxnum dcl 100 # How many numbers to add
br is a branch instruction, with operands (condition), (location to transfer control to)
# is for inserting comments, something that a good programmer is supposed to do
My memory of Fortran is rather rusty, so I'll do a very similar-looking programming language, C:
int num = 1;
int sum = 0;
next: sum += num;
num += 1;
if (num > 100) goto done;
goto next;
done: printf("%d\n",sum);
A more compressed version:
int sum = 0;
for (int num = 1; num <= 100; num+=1) sum += num;
printf("%d\n",sum);