Computer with three 8-bit registers:
(See also Barry Stern's neat
simulation
of a similar computer.)
0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 2 0 0 0 1 1 3 0 0 1 0 0 4 0 0 1 0 1 5 ... 1 1 0 1 1 27 1 1 1 0 0 28 1 1 1 0 1 29 1 1 1 1 0 30 1 1 1 1 1 31
0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1
0 0 0 0 0 1 GET 0 1 0 PUT 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1
0 0 0 0 0 1 GET 0 1 0 PUT 0 1 1 ADD 1 0 0 NEGATE 1 0 1 1 1 0 1 1 1
0 0 0 0 0 1 GET 0 1 0 PUT 0 1 1 ADD 1 0 0 NEGATE 1 0 1 JUMP 1 1 0 JUMPEQ 1 1 1 JUMPGT
0 0 0 STOP 0 0 1 GET 0 1 0 PUT 0 1 1 ADD 1 0 0 NEGATE 1 0 1 JUMP 1 1 0 JUMPEQ 1 1 1 JUMPGT
Consider the following programme in a high-level language.
TOTAL = SCORE1 + SCORE2 IF(TOTAL.LE.50) THEN GRADE = 'F' ELSE GRADE = 'P' END IF STOP |
First we'll replace the elegant If/Then/Else
structure by a combination
of If
and Goto
which correspond more closely to the available
machine instructions.
TOTAL = SCORE1 + SCORE2 IF(TOTAL.LE.50) THEN GRADE = 'F' ELSE GRADE = 'P' END IF STOP | → |
TOTAL = SCORE1 + SCORE2 IF(TOTAL.GT.50) GOTO PASS GRADE = 'F' GOTO END PASS: GRADE = 'P' END: STOP |
Next we convert to a comparison with 0 rather than with 50.
TOTAL = SCORE1 + SCORE2 IF(TOTAL.GT.50) GOTO PASS GRADE = 'F' GOTO END PASS: GRADE = 'P' END: STOP | → |
TOTAL = SCORE1 + SCORE2 IF(TOTAL-50.GT.0) GOTO PASS GRADE = 'F' GOTO END PASS: GRADE = 'P' END: STOP |
Now we convert the first line to three simpler lines ...
TOTAL = SCORE1 + SCORE2 IF(TOTAL-50.GT.0) GOTO PASS GRADE = 'F' GOTO END PASS: GRADE = 'P' END: STOP | → |
GET SCORE1 ADD SCORE2 PUT TOTAL IF(TOTAL-50.GT.0) GOTO PASS GRADE = 'F' GOTO END PASS: GRADE = 'P' END: STOP |
The comparison statement becomes two simpler statements ...
GET SCORE1 ADD SCORE2 PUT TOTAL IF(TOTAL-50.GT.0) GOTO PASS GRADE = 'F' GOTO END PASS: GRADE = 'P' END: STOP | → |
GET SCORE1 ADD SCORE2 PUT TOTAL ADD (-50) JUMPGT PASS GRADE = 'F' GOTO END PASS: GRADE = 'P' END: STOP |
An assignment statement becomes a combination of Get
and Put
...
GET SCORE1 ADD SCORE2 PUT TOTAL ADD (-50) JUMPGT PASS GRADE = 'F' GOTO END PASS: GRADE = 'P' END: STOP | → |
GET SCORE1 ADD SCORE2 PUT TOTAL ADD (-50) JUMPGT PASS GET ('F') PUT GRADE GOTO END PASS: GRADE = 'P' END: STOP |
The Goto
becomes a Jump
...
GET SCORE1 ADD SCORE2 PUT TOTAL ADD (-50) JUMPGT PASS GET ('F') PUT GRADE GOTO END PASS: GRADE = 'P' END: STOP | → |
GET SCORE1 ADD SCORE2 PUT TOTAL ADD (-50) JUMPGT PASS GET ('F') PUT GRADE JUMP END PASS: GRADE = 'P' END: STOP |
Another assignment statement becomes a Get
and
Put
...
GET SCORE1 ADD SCORE2 PUT TOTAL ADD (-50) JUMPGT PASS GET ('F') PUT GRADE JUMP END PASS: GRADE = 'P' END: STOP | → |
GET SCORE1 ADD SCORE2 PUT TOTAL ADD (-50) JUMPGT PASS GET ('F') PUT GRADE JUMP END PASS: GET ('P') PUT GRADE END: STOP |
We can save one PUT GRADE
instruction by
rearranging. (Comment)
GET SCORE1 ADD SCORE2 PUT TOTAL ADD (-50) JUMPGT PASS GET ('F') PUT GRADE JUMP END PASS: GET ('P') PUT GRADE END: STOP | → |
GET SCORE1 ADD SCORE2 PUT TOTAL ADD (-50) JUMPGT PASS GET ('F') JUMP END PASS: GET ('P') END: PUT GRADE STOP |
This programme is now in assembly language, in which instructions are readable by humans but have a one-to-one correspondence with the machine instructions.
GET SCORE1 ADD SCORE2 PUT TOTAL ADD (-50) JUMPGT PASS GET ('F') JUMP END PASS: GET ('P') END: PUT GRADE STOP |
As the first step in converting the assembly language into machine instructions, we number the memory locations for the commands ...
00 GET SCORE1 01 ADD SCORE2 02 PUT TOTAL 03 ADD (-50) 04 JUMPGT PASS 05 GET ('F') 06 JUMP END 07 PASS: GET ('P') 08 END: PUT GRADE 09 STOP
Assigning memory locations for the data ...
00 GET SCORE1 01 ADD SCORE2 02 PUT TOTAL 03 ADD (-50) 04 JUMPGT PASS 05 GET ('F') 06 JUMP END 07 PASS: GET ('P') 08 END: PUT GRADE 09 STOP 10 SCORE1: ** 11 SCORE2: ** 12 TOTAL: ** 13 -50 14 'F' 15 'P' 16 GRADE: **
Expressing the addresses as binary numbers ...
00000 GET SCORE1 00001 ADD SCORE2 00010 PUT TOTAL 00011 ADD (-50) 00100 JUMPGT PASS 00101 GET ('F') 00110 JUMP END 00111 PASS: GET ('P') 01000 END: PUT GRADE 01001 STOP 01010 SCORE1: ** 01011 SCORE2: ** 01100 TOTAL: ** 01101 -50 01110 'F' 01111 'P' 10000 GRADE: **
Starting to encode the commands ...
00000 00101010 GET SCORE1 00001 ADD SCORE2 00010 PUT TOTAL 00011 ADD (-50) 00100 JUMPGT PASS 00101 GET ('F') 00110 JUMP END 00111 PASS: GET ('P') 01000 END: PUT GRADE 01001 STOP 01010 SCORE1: ** 01011 SCORE2: ** 01100 TOTAL: ** 01101 -50 01110 'F' 01111 'P' 10000 GRADE: **
00000 00101010 GET SCORE1 00001 01101011 ADD SCORE2 00010 PUT TOTAL 00011 ADD (-50) 00100 JUMPGT PASS 00101 GET ('F') 00110 JUMP END 00111 PASS: GET ('P') 01000 END: PUT GRADE 01001 STOP 01010 SCORE1: ** 01011 SCORE2: ** 01100 TOTAL: ** 01101 -50 01110 'F' 01111 'P' 10000 GRADE: **
00000 00101010 GET SCORE1 00001 01101011 ADD SCORE2 00010 01001100 PUT TOTAL 00011 01101101 ADD (-50) 00100 JUMPGT PASS 00101 GET ('F') 00110 JUMP END 00111 PASS: GET ('P') 01000 END: PUT GRADE 01001 STOP 01010 SCORE1: ** 01011 SCORE2: ** 01100 TOTAL: ** 01101 -50 01110 'F' 01111 'P' 10000 GRADE: **
00000 00101010 GET SCORE1 00001 01101011 ADD SCORE2 00010 01001100 PUT TOTAL 00011 01101101 ADD (-50) 00100 JUMPGT PASS 00101 GET ('F') 00110 JUMP END 00111 PASS: GET ('P') 01000 END: PUT GRADE 01001 STOP 01010 SCORE1: ** 01011 SCORE2: ** 01100 TOTAL: ** 01101 -00110010 -50 01110 'F' 01111 'P' 10000 GRADE: **
There are various ways in which negative numbers can be handled by the hardware. One way is to invert all of the bits, assuming that the first bit is 0 to start with.
00000 00101010 GET SCORE1 00001 01101011 ADD SCORE2 00010 01001100 PUT TOTAL 00011 01101101 ADD (-50) 00100 JUMPGT PASS 00101 GET ('F') 00110 JUMP END 00111 PASS: GET ('P') 01000 END: PUT GRADE 01001 STOP 01010 SCORE1: ** 01011 SCORE2: ** 01100 TOTAL: ** 01101 11001101 -50 01110 'F' 01111 'P' 10000 GRADE: **
Filling in the rest of the commands ...
00000 00101010 GET SCORE1 00001 01101011 ADD SCORE2 00010 01001100 PUT TOTAL 00011 01101101 ADD (-50) 00100 11100111 JUMPGT PASS 00101 00101110 GET ('F') 00110 10101000 JUMP END 00111 00101111 PASS: GET ('P') 01000 01010000 END: PUT GRADE 01001 00000000 STOP 01010 SCORE1: ** 01011 SCORE2: ** 01100 TOTAL: ** 01101 11001101 -50 01110 'F' 01111 'P' 10000 GRADE: **
Two memory locations will be filled with the scores ...
00000 00101010 GET SCORE1 00001 01101011 ADD SCORE2 00010 01001100 PUT TOTAL 00011 01101101 ADD (-50) 00100 11100111 JUMPGT PASS 00101 00101110 GET ('F') 00110 10101000 JUMP END 00111 00101111 PASS: GET ('P') 01000 01010000 END: PUT GRADE 01001 00000000 STOP 01010 xxxxxxxx SCORE1: ** 01011 xxxxxxxx SCORE2: ** 01100 ........ TOTAL: ** 01101 11001101 -50 01110 'F' 01111 'P' 10000 ........ GRADE: **
The letters ‘F’ and ‘P’ will be represented by their ASCII codes ...
00000 00101010 GET SCORE1 00001 01101011 ADD SCORE2 00010 01001100 PUT TOTAL 00011 01101101 ADD (-50) 00100 11100111 JUMPGT PASS 00101 00101110 GET ('F') 00110 10101000 JUMP END 00111 00101111 PASS: GET ('P') 01000 01010000 END: PUT GRADE 01001 00000000 STOP 01010 xxxxxxxx SCORE1: ** 01011 xxxxxxxx SCORE2: ** 01100 ........ TOTAL: ** 01101 11001101 -50 01110 01000110 'F' 01111 01010000 'P' 10000 ........ GRADE: **
The programme is now ready to run!
00000 00101010 GET SCORE1 00001 01101011 ADD SCORE2 00010 01001100 PUT TOTAL 00011 01101101 ADD (-50) 00100 11100111 JUMPGT PASS 00101 00101110 GET ('F') 00110 10101000 JUMP END 00111 00101111 PASS: GET ('P') 01000 01010000 END: PUT GRADE 01001 00000000 STOP 01010 xxxxxxxx SCORE1: ** 01011 xxxxxxxx SCORE2: ** 01100 ........ TOTAL: ** 01101 11001101 -50 01110 01000110 'F' 01111 01010000 'P' 10000 ........ GRADE: **
Say we wish to know the average weight of the adult women in this sample:
Number Age Weight Height Sex (yr) (kg) (cm) ------ ---- ------ ------ --- 5948 18 53 156 M 5760 48 46 97 M 8484 30 68 186 F 9475 06 34 78 M 4759 30 75 148 F 3903 84 50 109 F 4902 87 86 126 M 3039 58 56 116 F 6783 10 48 86 M 3585 92 54 146 M
? what is the average weight of the adult women in this sample?
Their average weight is 62.2 kg.
?
? What is the average weight of the adult women in this sample?
What does ‘ADULT’ mean? age greater than or equal to 18
Do you mean 18 ‘years’? yes
What does ‘WOMEN’ mean? sex is female
I think your question is ‘For all cases where AGE >= 18 and SEX = F, what is the average of WEIGHT?’
Is that correct? yes
The answer is 62.2 kg.
?
? what is the average weight of the adult women in this sample?
*** Invalid syntax. Try again ***
? for sex = 'f' and age >= 18, what is average weight?
*** Invalid syntax. Try again ***
? for sex = 'f' and age >= 18, what is average of weight?
Average = 62.2.
?
What do you want to do?
Specify selection criteria
Specified selection criteria:
There are 4 hits.
Which analysis do you want to do?
For the 4 hits
the average weight is 62.2.
Which analysis do you want to do next?
This and the following are procedural (telling the computer how to do what you want), while the earlier examples were nonprocedural (telling the computer what you want).
select avg (Weight) from DataTable where Age >= 18. and Sex = 'F'
If a programme is written in a language which ‘knows about’ the record structure, it won't be necessary to modify the code when the record structure changes.
TOTAL_WEIGHT = 0; NUMBER = 0 REPEAT [ READ_NEXT_RECORD IF(END_OF_FILE) BREAK IF("AGE" >= 18. AND "SEX" = 'F') [ TOTAL_WEIGHT = TOTAL_WEIGHT + "WEIGHT" NUMBER = NUMBER + 1 ] ] AVERAGE_WEIGHT = TOTAL_WEIGHT / NUMBER PRINT 'Average weight = ', AVERAGE_WEIGHT END
REAL RECORD(5), AVERAGE, TOTAL, AGE, SEX, WEIGHT BYTE SEX INTEGER NUMBER TOTAL = 0. NUMBER = 0 OPEN(UNIT=UNIT1,NAME='DATAFILE',TYPE='OLD',READONLY) REPEAT [ READ(UNIT1,*,END=IEND) RECORD; (4F10.0,5X,A4) IF(IEND) BREAK AGE = RECORD(2) SEX = RECORD(5) WEIGHT = RECORD(3) IF(AGE >= 18 .AND. SEX == 'F') [ TOTAL = TOTAL + WEIGHT NUMBER = NUMBER + 1 ] ] AVERAGE = TOTAL / NUMBER PRINT *, AVERAGE; (' Average = ',F5.1) END
STORF #0.,TOTAL STORI #0.,NUMBER START: CALL $READ,RECORD,FLAG TEST FLAG BNE END COMPF RECORD(1),#18. BLT START COMPB RECORD(16.),'F' BNE START ADDF RECORD(2),TOTAL BR START END: CONVF NUMBER,NUMF STORF TOTAL,AVER DIVF AVER,NUMF CALL $PRINTS, STRING CALL $PRINTF, AVER CALL $EXIT RECORD: .WORD 9. TOTAL: .WORD 2 NUMBER: .WORD 1 ...
Fortran 1957-2007 |
50! |
Compilers and interpreters are programmes which translate high-level languages into machine language (or into an intermediate form suitable for conversion into machine language). Examples of high-level languages:
There are many other high-level languages.
Assemblers are programmes which translate assembly-language programmes into machine language. They are specific to a particular type of CPU, e.g., Pentium, Itanium, PowerPC or Alpha.
Operating systems are the managers. Examples:
Numbers of lines of code in operating systems:
Windows 95 | 11 million | |
Windows 98 | 18 million | |
Windows NT | 4 million | (1993) |
28 million | (1998) | |
Windows 2000 | 35 million | |
Windows XP | 40 million |
Numbers of lines of code in operating-system kernels:
Linux | >2.5 million |
Windows XP | >5 million |
Windows 98 is said to have about 18 million lines of code (see transcript from Microsoft trial, 1999 Feb 2), up from about 11 million in Windows 95 (from posting by M.B. Trausch on linux-kernel list, 1999 Jun 21).
Windows NT is estimated to have grown from about 4 million lines of code in 1993 to about 28 million in 1998 (ref. graph in Windows NT 5.0 A Brief Look at the Future of NT by W.F. Slater, 1998).
Windows 2000 is said to have ‘29 million lines of new code’ (TCP, 2000 Apr, Exploring Windows 2000), with a total of maybe 35 million (ref. Windows 2000 beta bothers by Scott Berinato, 1999 Feb 5), depending on how they're counted.
Windows XP is said to have about 40 million lines of code (IEEE Spectrum, 2005 Sep, p. 41).
Linux kernel has "more than 2.5 million" and Windows XP kernel is "more than twice as large" (Computer, 2006 May, p. 44).
Windows 95 & 98 were very ‘fragile’.
Reliability increased progressively in Windows NT, 2000 and XP.
A Microsoft-funded study (2000 Feb) found mean times to unplanned reboots of 5, 23 and 72 weeks for Windows 98, NT and 2000, respectively. Most or all of the machines were actually rebooted every day.
Another Microsoft-funded study (2001 Oct) found a mean time to OS crash of 13 days for Windows 98SE. The apparent goal of the study was to show how much better Windows 2000 and XP were than Windows 98.
ZDNet measured mean times between reboots of
A Unix system will typically go weeks or months between reboots.
An operating system should not crash because of problems with application software.
1991 Feb: 28 killed, 97 injured when Patriot missile-defence system failed.
Cause: software bug.
M Grottke & KS Trivedi,
‘Fighting bugs: Remove, retry, replicate, and rejuvenate’,
Computer 2007, 40(2): 107-109)
‘Given that all software is inherently defective, how can
medical device manufacturers identify and manage risk?’
(SR Rakitin,
‘Coping with defective software in medical devices’,
Computer 2006, 39(4): 40-45, in special issue on
‘Software engineering for future healthcare
and clinical systems’)