ZXTape! 2 !O-Level Computer Science - Side A GCE Tutoring1984English EducationalUnknownNoneOriginal;TZXed by Andrew Barker For Gary Poole Released August 1984ch1 Ȝ2aʜkh$(20,32 ):t$(7,7,16,32 ):w(25,8):5000:2000 ch 1  G C E Tutoring  Aug 1984 6:6:0:  r(10 ) t(5):9069m# Lscrhdr=9300T$:qsthdr=9350$:endsec=9400$:getans=9450$ fig2=8950":fig=9030F#:axes2=9000(#:eg=9040P#:axes=9100#:triangle=9150#:diagram=218:praise=9720% 5br=8100:squrec=8850":squpar=8900" 4:"COMPUTER STUDIES help ch1"::"DATA PROCESSING" :" GCE Tutoring Aug 1984" 2z:"Hello, what's your name ?":n$:n$:"OK, ";n$;",":"I'll begin by telling you how touse this computer studies tape." 4Y:"This program covers 4 subjects which all come under the headingof data processing." :>:"Press the key marked C so I can type the next screenfull" <a$=:a$="c"62> = 60< >:z=1100d:z AF:"Thanks. From now on when I want you to press the C key, I'll say" D:" Hit C to continue" F4:"Here's the list of subjects on this program": Hq"development of calculating aids data processing representation of data checking data" K2:"Which subject do you want to try ?":s$: Lc$=s$ N'(s$)>3s$=s$(13) Ps$="dev"200 Xs$="dat"1000 Zs$="rep"1200 ^s$="che"1400x _ 70F c     x=14 z=116 t$(1,x,z) z scrhdr x ,qsthdr 1+"The first mechanical calculator was :": 6_"1. the abacus 2. Pascal's calculator 3. pebbles in a clay tray ?" ;4egc=3:exp=3:return=320@:getans @4"Babbage's analytical engine consisted of :": EV"1. two main parts 2. three main parts 3. five main parts" J4egc=3:exp=2:return=335O:getans O3"Babbage's analytical engine conisted of :": T`"1. mill, control and store 2. control, store, data 3. mill, control, operator ?" Y4egc=3:exp=1:return=350^:getans 2start=200:return=398:n$=c$:endsec       x=17 z=116 t$(7,x,z) z scrhdr x U2start=400:return=598V:n$=c$:endsec V X Z ] ` gx=17 lz=116 qt$(3,x,z) vz {scrhdr x 2start=600X:return=798:n$=c$:endsec    " % ( /x=17 4z=116 9t$(4,x,z) >z Cscrhdr Hx 2start=800 :return=998:n$=c$:endsec      x=16 z=116 t$(5,x,z) z  scrhdr x Lqsthdr Q]"Which of these manually referenced ways of storing data is quickest to access :": VW"1. card index 2. office file 3. reference book ?" [5egc=3:exp=1:return=1120`:getans `^"Which of the following is likelyto conain information useful to more than one business ?": eW"1. card index 2. office file 3. reference book ?" j5egc=3:exp=3:return=1135o:getans o\"At present, which is least likely to have been replaced by a computer system ?": tW"1. card index 2. office file 3. reference book ?" y5egc=3:exp=3:return=1150~:getans 4start=1000:return=1198:n$=c$:endsec     x=15 z=116 t$(6,x,z) z scrhdr x qsthdr ""Encoding information makes :": u"1. processing it easier 2. storage requirements smaller in many cases 3. both 1 and 2": #5egc=3:exp=3:return=1320(:getans (0"A ruler gives a measurement which is :": -M"1. analogue 2. digital 3. either" 25egc=3:exp=1:return=13357:getans 76"Which form do clocks display information in ?": :n$=c$:endsec > @ B H Jh$(18): 4start=1600@:return=1798:n$=c$:endsec       h$(19): 4start=1800:return=1998:n$=c$:endsec   x$="": o=1̱x$ n=18 #w(o,n):x$(oo)+n-1,w(o,n) n o  H24,16,16,32 ,16,16,24,0 C24,8,8,4,8,8,24,0 F0,0,62>,64@,64@,64@,62>,0 E0,0,124|,2,2,2,124|,0 G0,66B,66B,66B,66B,66B,44,,0 G0,44,,66B,66B,66B,66B,66B,0  G0,0,60<,64@,124|,64@,60<,0 I240,8,120x,128,248,0,0,0 C0,0,0,4,126~,4,0,0 I248,136,136,136,0,0,0,0 C4,4,228,4,0,0,0,0 G240,8,240,8,240,0,0,0 G28,20,16,16,8,8,40(,568  E4,68D,228,68D,0,0,0,0 "G16,16,16,0,0,480,72H,480 %E12 ,18,18,12 ,0,0,0,0 (E7,4,4,8,8,144,80P,32 *G4,8,16,16,16,32 ,32 ,32 ,G32 ,32 ,32 ,16,16,16,8,4 /C32 ,16,8,8,8,4,4,4 2C4,4,4,8,8,8,16,32 4   save screen  ptr2=0 z=16384@22528X ptr=z-16383? data=(z) Jdata0ptr2=ptr2+1:j$(dgnum,ptr2)=(data):k(dgnum,ptr2)=z z    !fetch screen $ &z=16384@23296[ (ptr=z-16383? +data=(j$(dgnum,ptr)) 0z,data :z D N S fetch fast X 3200 Yx=16384@23296[ Z x,((addr)) ]addr=addr+1 `x b  fetch screen bits   z=1pxnum k(dgnum,z),(j$(dgnum,z)) z    save arrays  "dgdata"t$() r  z=31000 %v=((z^2-(z-1)^2)) u=v^0.5 C((u)-(u+0.5))<0.01z# =z;":";z-1;":";v^0.5 z    start  !7,10 ;"PLEASE WAIT"  ""t$()  41:7,9 ;"STOP THE TAPE":0  300,   p*********************** r* level index exp. * u*********************** x yret=6000p z "INPUT #" |:"mantissa ? ":man:man :"exponent ? ":exp:exp lni=man+exp*10  lev=1 lev=lev+1  lni=lni 4lni<0lni=lni:lev=lev-1:6050  6031 "[";lev;"/";lni;"]" ret6000p a$  ret  z=2255 * table * ***********************  ret=0  man=z  exp=0 z;6;" = ";  6020 z  z=237% exp=10 ^z "10^10^";z;9 ;" = ";  6020 z 6 8"INPUT LEVEL/INDEX": j"level ? ";:lev:lev t v"index ? ";:ind:ind w x for=ind y+lev>3ovl=lev-3:lev=3 zz=1lev { for=for |z }ovl>06280 ~"STANDARD FORM": for a$::62008 for=for/10 z=1ovl *lev>3"level too big":62008 "z=2for=for-.3622169t`$ "10^"; z for  6275 #( #2K27,41):110n,0:27,41):0,557 #:]17,3;"0":17,6;"2":17,9 ;"4":17,12 ;"6" #<17,15;"8" #>\16,2;"0":14,2;"2":12 ,2;"4":10 ,2;"6" #A #Fi579+x,513+y:20,20:-20,20:-20,-20:20,-20: #Hc72H+x,568+y:0,30:-30,0:0,-30:30,0: #P'"Here is an example of ";n$ #R #Z #\ #_noises #b #d-z=120:0.01z# =,-24:z #f #h #i&z=15:0.3,t(z):z #l #mz=15:t(z):z: #n*7,9 ,5,-7,0 # # # # axes(atype) # #_30,90Z:210,0:30,90Z:0,557:0,-110n #10 ,2;"0" #f11 ,9 ;"90":11 ,15;"180":11 ,22;"270":11 ,29;"360" #atype=09124# #atype=19130# #.4,2;"1":16,1;"-1" #07,1;".5":13 ,0;"-.5" # #.7,2;"1":13 ,1;"-1" #.4,2;"2":16,1;"-2" # # # #draw triangle(label) # #N30,60<:100d,0:0,60<:-100d,-60< #label=09175# #15,6;"adjacent" # 8,1;"hypoteneuse" #11 ,18;"opposite" #6123{,60<:0,7:7,0 #H41),60<:0,2:-3,2:-2,0 #14,2;"A" #14,17;"B" #6,17;"C" #::::::::: # # # # # replies() # #':9210#+((*6)+1): #"Berk ! What's ";c$;" ?": #'"Wally ! ";c$;" isn't on the tape.": ##"Moron ! Try spelling straight": #"sorry, ";n$;" ? ": #"Are you tired, ";n$;" ?": $"Don't wind me up, ";n$: $T $V scrhdr() $Y $\9900&:: $ $ qsthdr() $ $'9600%:9900&:egc=0: $ $ $endsec(start,c$) $ $5"That finishes ";c$:"Hit r to repeat this section" $ 9900& $a$="r"start $return $ $ $getans(loop,exp) $ $?dp=0:err=0:u$:u$:(u$)>10 err=1 $(u$)=09460$ $[j=1̱(u$):(u$(jj))<45-ů(u$(jj))>579ů(u$(jj))=47/err=1 $%9480%:j:u$="-."err=1 $Cerr=1dp>1"type the answer as a number":9460$ $=ans=(u$):(exp-ans)>0.005y# ="No, the answer is ";exp $$(ans-exp)0.005y# =9720% $return $ % %$(u$(jj))=46.dp=dp+1 % ,j>1Ư(u$(jj))=45-err=1 %  %k9800H&:d1=r(1)/10 +r(2)/100d+r(3)/1000:dec=d1:int=1000*dec %& %A"See if you understand this by trying the following examples" % 9800H& % %"True or false ?" %a$ %a$ %a$"t"a$"f"9650% % %n:n;"/";:d:d: % 9630% % % %praise % %%9720%+((*9 )+1): % "Good": % "Correct": %"Right again": %"OK": %"That's it": %"Brilliant !": %"Well done": &"Very good": &"Genius !": &HWz=110 :r(z)=(*9 )+1:z:r(1)r(2)9800H&: &R#r(1)r(2)9800H& &\ &z "trap": & &"Hit C to continue" &a$= &a$="c"9950& &a$="r"9950& & 9920& & &z=1502:z &  32&crhdT$sthd$ndse$etan$ig"iF#xes(#P#xe#riangl#iagrarais%qure"qupa"gxeturr$ntarȅ b THE DEVELOPMENT OF CALCULATING AND CLERICAL AIDS The earliest computing device was the five fingers of each hand. Since there are ten fingers available for counting it is natural that the decimal (10 digit) system developed. The first man made calculating machine was developed by the Egyptians, and consisted of a clay board with a number of grooves into which pebbles were placed. By sliding the pebbles along the grooves from one side to the other, counting became 'semiautomatic' The abacus is a variation on the above device, and was developed in the far east. The automatic 'carrying' of a digit from one column to the next was first achieved by a machine built by the mathematician Blaise Pascal. It used toothed wheels to pass the overflow from column to column. The first true computer was designed by Charles Babbage, a mathematics professor, in 1833 Babbage's machine consisted of 3 parts : 1. the STORE, which would hold the data for a problem 2. the MILL, which performed arithmetic operations 3. the CONTROL,which instructed the mill what to do. The important part of this design was the control. The control replaced the human operator normally required, and therefore allowed the machine to work at full speed. Although Babbage never finished his 'analytical engine', the ideas it was based on are still used today. PUmmmmm possible to use of punched cards to make a complete merchandise control procedure. There are essentially four inputs to such a system, receipts, sales, orders returned and adjustments, and transfers. Receipts, in this example, are marked on marked sense cards, are punched, and form one of the inputs. Sales begin with the removal of a ticket when merchandise is sold. The tickets are separated into several categories, and sales cards are produced which are then sorted. An accounting machine produces a sales report and a summary punch. The output from this summary punch becomes the third input to the sort-and-merge procedure. Transfers also involve tickets which are converted into punched cards for another of the inputs. The miscellaneous transactions again are converted into punched cards. After sorting and merging, these inputs go to an accounting machine which produces new balance cards and a balance file. At the same time the accounting machine produces a sales and inventory report. Output from the accounting machine is sorted by class and price and then goes back to the accounting machine to produce class/price-line summary cards, which are individual cards, dividing the merchandise by price and by class so that there is a summary file of cards for all of all of the merchandise. At the desired time these cards in proper sequence are sent to an accounting machine, where they are used to produce a class/price-line report. Almost all forms of related statistical data and formal numerical records can use punched cards to advantage. One application of data processing is in data retrieval or in the use of automated techniques for looking up library information. DATA PROCESSING Until recently, the data processing involved in office work was achieved by manual methods. Information was stored in a variety of manually accessed ways. For example: 1. card indices 2. office files 3. directories 4. reference books Card indices and office files differ from directories and reference books in that they store information specific to the company using them, whereas directories and reference books store information of more general use. The first step in the automation of data processing was the introduction of punched cards. Usually cards are punched with holes to store data, but in some cases pencil marks on a blank card are used instead. As well as being useful in conjunction with computers, punched cards allow manual access to data. Punched cards can be processed by entirely mechanical methods, and have therefore been used for far longer than computers. The first large scale use of punched cards for data processing was late last century, for American census information. The large and rapidly increasing population was too great for manual methods to cope with. THE ELECTRONIC OFFICE Many modern offices use word-processors and have replaced files and card indices with small computer systems. Both of these pieces of equipment perform data processing. Data processing equipment consist of two distinct parts: 1. a data store 2. processing capability The data store, which was once written information or punched cards, is now magnetic disks. The processing capability, previously provided by a large number of employees and/or mechanical machines, is now provided by a small business computer. REPRESENTATION OF DATA In every day life, information is encoded in many ways. The reason for encoding data is that it makes it easier to understand, or simpler to manipulate. An example of encoding information to make it quicker to understand is the use of traffic lights. Colour coding makes it far quicker to communicate the message 'STOP' or 'GO'. A form of numerical encoding which is so common it might not even be thought of as such is the use of telephone numbers. Another very common type of encoding is the growing use of postcodes. In computer science, encoding is most frequently used to speed up data processing. Numerical data can come in two forms: 1. Analogue 2. Digital Let's take these one by one. ANALOGUE DEVICES An analogue representation of a number is displayed by devices such as thermometers and car speedometers. The numerical value is presented proportionately, and can be read as accurately as your judgement allows. DIGITAL DEVICES A digital device presents data numerically, using digits as opposed to a continuously variable analogue representation. A digitally represented value can be read as accurately as it presented, i.e. 2 sig. figs if 2 digits are presented. Judgement is not involved. DATA CHECKING All data is worthless unless it is either correct, or its degree of accuracy known. Decisions made using incorrect data can be misleading. Wrong data is consequently worse than no data. Data validation can be carried out on input. For example, a date typed wrongly can be detected if the error results in either: 1. the date exceeds the number days in the month 2. the month exceeds 12 The accuracy of data obtained in, for example, scientific research, can be inadvertantly forgotten if the results of calculations are presented to the accuracy a computer allows eg. a square field is measured as having a side length of 125 metres, to the nearest metre. The surveyor's com- puter claims that the field has an area of : 2 125m x 125m = 15625m It would be a mistake to believe all the digits of the answer. Since the field was measured to the nearest metre, its actual side length could be between 124.5m and 125.5m. The area is therefore : not less than 124.5m x 124.5m =15500.25 sq.m. not more than 125.5m x 125.5m =15750.25 sq.m. ie. 15625+-125 sq.m. X5 >@CdataSdatU3NdataAc ch2 A0zkh$(20,32 ):t$(7,7,16,32 ):w(25,8):5000:2000 tuition template  G C E Tutoring  Aug 1984 6:6:0:  r(10 ) t(5):9069m# Lscrhdr=9300T$:qsthdr=9350$:endsec=9400$:getans=9450$ fig2=8950":fig=9030F#:axes2=9000(#:eg=9040P#:axes=9100#:triangle=9150#:diagram=218:praise=9720% 5br=8100:squrec=8850":squpar=8900" 8:"COMPUTER STUDIES help ch2"::"Inside the computer" :" GCE Tutoring Aug 1984" 2z:"Hello, what's your name ?":n$:n$:"OK, ";n$;",":"I'll begin by telling you how touse this computer studies tape." 4_:"This tape covers 6 subjects which all come under the headingof 'inside the computer'." :>:"Press the key marked C so I can type the next screenfull" <a$=:a$="c"62> = 60< >:z=1100d:z AF:"Thanks. From now on when I want you to press the C key, I'll say" D:" Hit C to continue" F1:"Here's the list of subjects on this tape": H"representations of characters numerical representation instruction representation boolean algebra functional aspects of hardware machine level operations" K2:"Which subject do you want to try ?":s$: Lc$=s$ N'(s$)>3s$=s$(13) Ps$="boo"200 Rs$="num"400 Ts$="ins"600X Vs$="rep"800  Xs$="fun"1000 Zs$="mac"1200 _ 70F c     x=17 z=116 t$(1,x,z) z scrhdr x ,qsthdr .nb1=2*(r(1)/2-(r(1)/2)):b2=2*(r(2)/2-(r(2)/2)) 1b1;"+";b2;"= ?" 6 "Don't forget that + means OR" ;egc=3:return=325E @exp=b1b2:getans Eb1;".";b2;"= ?" J!"Don't forget that . means AND" Oegc=3:return=345Y Texp=b1b2:getans Y"a.b+a.b'= ?" ^egc=1:return=360h cexp=1:getans 2start=200:return=398:n$=c$:endsec       x=17 z=116 t$(2,x,z) z scrhdr x qsthdr y"without using 2s complement, what is the maximum integer thatcan be represented using ";r(1);" bits ?" egc=3:return=515 (exp=2^r(1)-1:getans y"using 2s complement, what is the maximum integer thatcan be represented using ";r(2);" bits ?" Iexp=2^(r(2)-1):egc=3:return=525 :getans  9"How can numbers with a decimal part be represented ?" M"1. 2s complement 2. floating point 3. binary" 4exp=2:egc=3:return=540:getans U2start=400:return=598V:n$=c$:endsec V X Z ] ` gx=13 lz=116 qt$(3,x,z) vz {scrhdr x qsthdr @"Most ordinary home computers use instructions mad up of :" P"1. 4 bits 2. 8 bits 3. 16 bits ?" 4egc=3:exp=2:return=720:getans &"In an execution cycle, there are": R"1. 2 phases 2. 3 phases 3. 4 phases ?" 4egc=3:exp=1:return=735:getans 1"The two phases in an execution cycle are :": ^"1. instruction, execution 2. instruction, operation 3. operation, execution ?" 4egc=3:return=750:exp=1:getans 2start=600X:return=798:n$=c$:endsec    " % ( /x=13 4z=116 9t$(4,x,z) >z Cscrhdr Hx qsthdr C"A standard way of of representing characters is :": X"1. binary 2. ASCII 3. floating point ?" 4egc=3:exp=2:return=920:getans <"The ASCII characters with codes between 0 and 31 are :": ]"1. control characters 2. lower case 3. numbers and symbols ?" 4egc=3:exp=1:return=935:getans 2start=800 :return=998:n$=c$:endsec      ""FUNCTIONAL ASPECTS OF HARDWARE" :"The basic elements that comprisethe hardware of computers are called GATES. These are electronic circuits which simulate functions from Boolean algebra." x=13 z=116 !x=1z<61030 t$(5,x,z) z  scrhdr x $N"Any Boolean function can be constructed out of AND, OR and NOT gates." .scrhdr Lqsthdr Q4"The circuit elements of a computer have:": VU"1. one state 2. two states 3. four states ?" [5egc=3:exp=2:return=1120`:getans 4start=1000:return=1198:n$=c$:endsec     x=13 z=116 t$(6,x,z) z scrhdr x qsthdr <"The code that machine code is made up of is called :": #O"1. microcode 2. assembler 3. basic ?" (5egc=3:exp=1:return=1325-:getans u4start=1200:return=1398v:n$=c$:endsec v x z }  =4start=1400x:return=1598>:n$=c$:endsec @ B H Jh$(18): 4start=1600@:return=1798:n$=c$:endsec       h$(19): 4start=1800:return=1998:n$=c$:endsec   x$="": o=1̱x$ n=18 #w(o,n):x$(oo)+n-1,w(o,n) n o  H24,16,16,32 ,16,16,24,0 C24,8,8,4,8,8,24,0 F0,0,62>,64@,64@,64@,62>,0 E0,0,124|,2,2,2,124|,0 G0,66B,66B,66B,66B,66B,44,,0 G0,44,,66B,66B,66B,66B,66B,0  G0,0,60<,64@,124|,64@,60<,0 I240,8,120x,128,248,0,0,0 C0,0,0,4,126~,4,0,0 I248,136,136,136,0,0,0,0 C4,4,228,4,0,0,0,0 G240,8,240,8,240,0,0,0 G28,20,16,16,8,8,40(,568  E4,68D,228,68D,0,0,0,0 "G16,16,16,0,0,480,72H,480 %E12 ,18,18,12 ,0,0,0,0 (E7,4,4,8,8,144,80P,32 *G4,8,16,16,16,32 ,32 ,32 ,G32 ,32 ,32 ,16,16,16,8,4 /C32 ,16,8,8,8,4,4,4 2C4,4,4,8,8,8,16,32 4   save screen  ptr2=0 z=16384@22528X ptr=z-16383? data=(z) Jdata0ptr2=ptr2+1:j$(dgnum,ptr2)=(data):k(dgnum,ptr2)=z z    !fetch screen $ &z=16384@23296[ (ptr=z-16383? +data=(j$(dgnum,ptr)) 0z,data :z D N S fetch fast X 3200 Yx=16384@23296[ Z x,((addr)) ]addr=addr+1 `x b  fetch screen bits   z=1pxnum k(dgnum,z),(j$(dgnum,z)) z    save arrays   "text"t$() r  z=31000 %v=((z^2-(z-1)^2)) u=v^0.5 C((u)-(u+0.5))<0.01z# =z;":";z-1;":";v^0.5 z    start  !7,10 ;"PLEASE WAIT"  ""t$()  41:7,9 ;"STOP THE TAPE":0  300,   #( #2K27,41):110n,0:27,41):0,557 #:]17,3;"0":17,6;"2":17,9 ;"4":17,12 ;"6" #<17,15;"8" #>\16,2;"0":14,2;"2":12 ,2;"4":10 ,2;"6" #A #Fi579+x,513+y:20,20:-20,20:-20,-20:20,-20: #Hc72H+x,568+y:0,30:-30,0:0,-30:30,0: #P'"Here is an example of ";n$ #R #Z #\ #_noises #b #d-z=120:0.01z# =,-24:z #f #h #i&z=15:0.3,t(z):z #l #mz=15:t(z):z: #n*7,9 ,5,-7,0 # # # # axes(atype) # #_30,90Z:210,0:30,90Z:0,557:0,-110n #10 ,2;"0" #f11 ,9 ;"90":11 ,15;"180":11 ,22;"270":11 ,29;"360" #atype=09124# #atype=19130# #.4,2;"1":16,1;"-1" #07,1;".5":13 ,0;"-.5" # #.7,2;"1":13 ,1;"-1" #.4,2;"2":16,1;"-2" # # # #draw triangle(label) # #N30,60<:100d,0:0,60<:-100d,-60< #label=09175# #15,6;"adjacent" # 8,1;"hypoteneuse" #11 ,18;"opposite" #6123{,60<:0,7:7,0 #H41),60<:0,2:-3,2:-2,0 #14,2;"A" #14,17;"B" #6,17;"C" #::::::::: # # # # # replies() # #':9210#+((*6)+1): #"Berk ! What's ";c$;" ?": #'"Wally ! ";c$;" isn't on the tape.": ##"Moron ! Try spelling straight": #"sorry, ";n$;" ? ": #"Are you tired, ";n$;" ?": $"Don't wind me up, ";n$: $T $V scrhdr() $Y $\9900&:: $ $ qsthdr() $ $'9600%:9900&:egc=0: $ $ $endsec(start,c$) $ $5"That finishes ";c$:"Hit r to repeat this section" $ 9900& $a$="r"start $return $ $ $getans(loop,exp) $ $?dp=0:err=0:u$:u$:(u$)>10 err=1 $(u$)=09460$ $[j=1̱(u$):(u$(jj))<45-ů(u$(jj))>579ů(u$(jj))=47/err=1 $%9480%:j:u$="-."err=1 $Cerr=1dp>1"type the answer as a number":9460$ $=ans=(u$):(exp-ans)>0.005y# ="No, the answer is ";exp $$(ans-exp)0.005y# =9720% $return $ % %$(u$(jj))=46.dp=dp+1 % ,j>1Ư(u$(jj))=45-err=1 %  %k9800H&:d1=r(1)/10 +r(2)/100d+r(3)/1000:dec=d1:int=1000*dec %& %A"See if you understand this by trying the following examples" % 9800H& % %"True or false ?" %a$ %a$ %a$"t"a$"f"9650% % %n:n;"/";:d:d: % 9630% % % %praise % %%9720%+((*9 )+1): % "Good": % "Correct": %"Right again": %"OK": %"That's it": %"Brilliant !": %"Well done": &"Very good": &"Genius !": &HWz=110 :r(z)=(*9 )+1:z:r(1)r(2)9800H&: &R#r(1)r(2)9800H& &\ &z "trap": & &"Hit C to continue" &a$= &a$="c"9950& &a$="r"9950& & 9920& & &z=1502:z &  m#crhdT$sthd$ndse$etan$ig"iF#xes(#P#xe#riangl#iagrarais%qure"qupa"/gxeturr$ntarU2ȅ  >@@@>||BBBBB,,BBBBB<@|@<x~(8DD0H0  P    b BOOLEAN ALGEBRA As in ordinary algebra, numbers are referred to as x, y, z, etc. In this algebra, remember that such numbers can only take one of two values, i.e., 0 or 1. A symbol, such as x, y, z, represents a logical proposition which can be either true or false. The addition sign is defined as indicating the OR function. For example, the logical statement that proposition z is true if either proposition x or proposition y is true can be written in symbolic algebra as follows; z=x+y Since x and y can only take the values 0 and 1, it is quite easy to form a table showing the corresponding values of z=x+y in all possible cases, and the table is: x y z=x+y 0 0 0 1 0 1 0 1 1 1 1 1 The logical AND function states that proposition z is true provided that both propositions x and y are true. This is written as: z=x.y .A corresponding table for the product x.y is as follows: x y z=x.y 0 0 0 1 0 0 0 1 0 1 1 1 "not x" is written as x', so that if x=1, x'=0, and vice versa. It follows that x . x' = 0 and that x + x' = 1 As far as the operation or the manipulation of symbols goes, all the ordinary rules apply as well. It is possible to prove any rule in Boolean algebra by constructing a table on the lines above. A further logical function which is useful in computer circuitry is z = xy' + x'y This is the logical expression of the fact that x and y are not equivalent, so that z represents 1 if x and y are different and 0 if they are the same. It is written symbolically: x <> y This is illustrated by the following table: x y x' y' xy'+x'y 0 0 1 1 0 1 0 0 1 1 0 1 1 0 1 1 1 0 0 0 NUMBER SYSTEMS 1. DECIMAL The decimal system is no longer directly used by digital computers, but you should know how it operates so you can understand other number systems. The number 256 is really a form of shorthand. It means: 2x100 + 5x10 + 6x1 This can be written slightly differently: 256 = 2x10^2 + 5x10^1 + 6x10^0 where the symbol ^ means to the power of'. You can see that a decimal number is represented in ascending powers of 10. A number raised to a power is called a base, so decimal means base 10. Other numbers can be used as a base, and in computer science, the commonest base is 2. 2. BINARY Binary means base 2. In base 2 there are 2 different symbols, just as there are 10 in base 10 (i.e. 0,1,2,3,4,5,6,7,8,9). A binary number consists of only ones and noughts, which makes it easy for a computer to store, because the storage elements of a computer only have 2 states - on and off. Usually on means 1 and off means 0. BINARY DECIMAL 0 0 1 1 10 2 11 3 100 4 101 5 110 6 111 7 1000 8 The column value in binary increases by powers of two, so 101 = 1x2^2 + 0x2^1 + 1x2^0 HEXADECIMAL Binary numbers tend to be rather difficult to remember. 212 is easier than 11010100. Unfortunately, it is not very simple to convert binary to decimal. However, it is extremely easy to convert to base 16 (hexadecimal). Divide the binary number into groups of 4 bits, starting at the right. Each group corresponds to one hexadecimal digit. 0000 0 The digits in hexadec- 0001 1 imal include A to F to 0010 2 represent the decimal 0011 3 numbers 10 to 15. Tak- 0100 4 ing the previous exam- 0101 5 ple: 0110 6 0111 7 11010100 = 1101 0100 1000 8 = D 4 1001 9 1010 A Conversion from hex to 1011 B binary is simply the 1100 C same process in 1101 D reverse. 1110 E 1111 F TWOS COMPLEMENT Negative numbers can be represented using twos complement notation. If the first bit of a binary number is one, then the number is defined as being negative. All the other bits are then complemented to determine the number's value. eg. 1011 is -ve so complement 1011 becomes 0100 0100 means 4 so 1011 means -4 INSTRUCTION REPRESENTATION An instruction in machine code has a pattern called the instruction format. A typical 8 bit instruction might look like this: 0 1 1 0 0 1 0 1 op-code reg1 reg2 reg1 and reg2 are both 3 bit numbers specifying which register is to be used as the source of data, or location where the result is to go. The op-code specifies what operation is to be carried out eg. 00 for load, 01 for add, 10 for jump and 11 for I/O. The instruction 01 100 101 means 'add registers 4 and 5, and place the result in register 4.' Notice that the result is placed in first register. A computer is constantly changing from the INSTRUCTION PHASE to the EXECUTION PHASE. During the instruction phase, the computer analyses the machine code instruction, then during the execution phase, the instruction is obeyed. REPRESENTATION OF CHARACTERS Characters are represented by a unique 8 bit code assigned to them. The most common code is called ASCII. The values assigned to each character are shown below: TABLE OF ASCII CH. & VALUES CHARACTER VALUE (in hex.) 0 to 9 30 to 39 A to Z 41 to 5A a to z 61 to 6A symbols 20 to 2F, 3A to 40, 5B to 60, 7B to 7F The characters from 0 to 1Fhex are "control characters". They perform input/output functions, and are not printable. eg. backspace, linefeed etc. The electronic device referred to as a gate has already been covered. The two basic types of gate are AND gates and OR gates. In an AND gate a signal appears on the output line z if, and only if, signals are present on both the input lines x and y. In terms of Boolean algebra, we can write z=xy. This type of gate can be generalised by having more than two input signals, and in such cases is symbolised; z=x.y.w Gates of any number of inputs can be constructed. An OR gate, is constructed so that a signal appears on the output line if there is a signal on either of the input lines. This is indicated by the number 1 in the symbol, and the algebraic expression for the operation of this gate is z=x+y. In the same way as for AND gates there can be more than two inputs. A three-input OR gate represents the algebraic expression z=x+y+w MACHINE LEVEL OPERATIONS Although machine code is the lowest level of instruction available to the programmer, within the computer a lower level still occurs. This is called MICROCODE. As an example of microcode, an add instruction of a typical 8 bit computer is shown on the next page. The add instruction consists of 4 microcode instructions: 1. increment the program counter 2. load the contents of the memory location whose ad- dress is given by the pr- ogram counter into the instruction register 3. add the contents of the second register to the first register 4. place the result in the first register Beginners often get confused by trying to understand a computer at a machine level. It is only necessary to do this if you are designing the central processor of a computer. A simplified view does make it easier to understand the purpose of the various hardware units within a computer. Microcode is where hardware and software meet. XNCrepreSrepA5 w ch3 *}kh$(20,32 ):t$(7,7,16,32 ):w(25,8):5000:2000 ch3  G C E Tutoring  Aug 1984 6:6:0:  r(10 ) t(5):9069m# Lscrhdr=9300T$:qsthdr=9350$:endsec=9400$:getans=9450$ fig2=8950":fig=9030F#:axes2=9000(#:eg=9040P#:axes=9100#:triangle=9150#:diagram=218:praise=9720% 5br=8100:squrec=8850":squpar=8900" =:"COMPUTER STUDIES help ch3"::"PERIPHERALS & PROCESSING" :" GCE Tutoring Aug 1984" 2z:"Hello, what's your name ?":n$:n$:"OK, ";n$;",":"I'll begin by telling you how touse this computer studies tape." 4d:"This tape covers 4 subjects which all come under the headingof peripherals and processing." :>:"Press the key marked C so I can type the next screenfull" <a$=:a$="c"62> = 60< >:z=1100d:z AF:"Thanks. From now on when I want you to press the C key, I'll say" D:" Hit C to continue" F1:"Here's the list of subjects on this tape": H|"computer configuration I/O devices access and backing store peripheral communication" K2:"Which subject do you want to try ?":s$: Lc$=s$ N'(s$)>3s$=s$(13) Ps$="com"200 Rs$="I/O"400 Ts$="acc"600X Vs$="per"800  _ 70F c     x=17 z=116 t$(1,x,z) z scrhdr x ,qsthdr 1&"Arithmetic is carried out by the": 6J"1. control unit 2. ALU 3. RAM" ;4egc=3:exp=2:return=320@:getans 2start=200:return=398:n$=c$:endsec       x=13 z=116 t$(2,x,z) z scrhdr x qsthdr ,"I/O devices are all linked to the : ": X"1. CPU 2. peripherals 3. computer terminal" 4egc=3:exp=1:return=520:getans &"Another term for I/O devices is:":  S"1. procesors 2. peripherals 3. terminals ?" 4egc=3:exp=2:return=535:getans U2start=400:return=598V:n$=c$:endsec V X Z ] ` gx=16 lz=116 qt$(3,x,z) vz {scrhdr x qsthdr "RAM is :": Z"1. immediate access memory 2. backing store 3. neither of these ?" 4egc=3:exp=1:return=720:getans "Magnetic tape is :": Z"1. immediate access memory 2. backing store 3. neither of these ?" 4egc=3:exp=2:return=735:getans $"RAM can be accessed in about :": ["1. 250 nanoseconds 2. 250 microseconds 3. 250 milliseconds ?" 4egc=3:exp=1:return=750:getans 2start=600X:return=798:n$=c$:endsec    " % ( /x=14 4z=116 9t$(4,x,z) >z Cscrhdr Hx qsthdr 2"Communicating with peripherals is roughly :": \"1. as fast as processing 2. 50 times slower 3. 1000 times slower ?" 4egc=3:exp=3:return=920:getans scrhdr 6"Most peripherals communicate at a data rate of :": d"1. 30 to 960 bits per second 2. 300 to 9600 bits per second 3. 3000 to 96000 bits per second" 4egc=3:exp=2:return=940:getans 2start=800 :return=998:n$=c$:endsec      x=17 z=116 t$(5,x,z) z  scrhdr z 4start=1000:return=1198:n$=c$:endsec     x=17 z=116 t$(6,x,z) z scrhdr  u3start=400:return=1398v:n$=c$:endsec v x z }  =4start=1400x:return=1598>:n$=c$:endsec @ B H Jh$(18): 4start=1600@:return=1798:n$=c$:endsec       h$(19): 4start=1800:return=1998:n$=c$:endsec   x$="": o=1̱x$ n=18 #w(o,n):x$(oo)+n-1,w(o,n) n o  H24,16,16,32 ,16,16,24,0 C24,8,8,4,8,8,24,0 F0,0,62>,64@,64@,64@,62>,0 E0,0,124|,2,2,2,124|,0 G0,66B,66B,66B,66B,66B,44,,0 G0,44,,66B,66B,66B,66B,66B,0  G0,0,60<,64@,124|,64@,60<,0 I240,8,120x,128,248,0,0,0 C0,0,0,4,126~,4,0,0 I248,136,136,136,0,0,0,0 C4,4,228,4,0,0,0,0 G240,8,240,8,240,0,0,0 G28,20,16,16,8,8,40(,568  E4,68D,228,68D,0,0,0,0 "G16,16,16,0,0,480,72H,480 %E12 ,18,18,12 ,0,0,0,0 (E7,4,4,8,8,144,80P,32 *G4,8,16,16,16,32 ,32 ,32 ,G32 ,32 ,32 ,16,16,16,8,4 /C32 ,16,8,8,8,4,4,4 2C4,4,4,8,8,8,16,32 4   save screen  ptr2=0 z=16384@22528X ptr=z-16383? data=(z) Jdata0ptr2=ptr2+1:j$(dgnum,ptr2)=(data):k(dgnum,ptr2)=z z    !fetch screen $ &z=16384@23296[ (ptr=z-16383? +data=(j$(dgnum,ptr)) 0z,data :z D N S fetch fast X 3200 Yx=16384@23296[ Z x,((addr)) ]addr=addr+1 `x b  fetch screen bits   z=1pxnum k(dgnum,z),(j$(dgnum,z)) z    save arrays   "text"t$() r  z=31000 %v=((z^2-(z-1)^2)) u=v^0.5 C((u)-(u+0.5))<0.01z# =z;":";z-1;":";v^0.5 z    start  !7,10 ;"PLEASE WAIT"  ""t$()  41:7,9 ;"STOP THE TAPE":0  300,   #( #2K27,41):110n,0:27,41):0,557 #:]17,3;"0":17,6;"2":17,9 ;"4":17,12 ;"6" #<17,15;"8" #>\16,2;"0":14,2;"2":12 ,2;"4":10 ,2;"6" #A #Fi579+x,513+y:20,20:-20,20:-20,-20:20,-20: #Hc72H+x,568+y:0,30:-30,0:0,-30:30,0: #P'"Here is an example of ";n$ #R #Z #\ #_noises #b #d-z=120:0.01z# =,-24:z #f #h #i&z=15:0.3,t(z):z #l #mz=15:t(z):z: #n*7,9 ,5,-7,0 # # # # axes(atype) # #_30,90Z:210,0:30,90Z:0,557:0,-110n #10 ,2;"0" #f11 ,9 ;"90":11 ,15;"180":11 ,22;"270":11 ,29;"360" #atype=09124# #atype=19130# #.4,2;"1":16,1;"-1" #07,1;".5":13 ,0;"-.5" # #.7,2;"1":13 ,1;"-1" #.4,2;"2":16,1;"-2" # # # #draw triangle(label) # #N30,60<:100d,0:0,60<:-100d,-60< #label=09175# #15,6;"adjacent" # 8,1;"hypoteneuse" #11 ,18;"opposite" #6123{,60<:0,7:7,0 #H41),60<:0,2:-3,2:-2,0 #14,2;"A" #14,17;"B" #6,17;"C" #::::::::: # # # # # replies() # #':9210#+((*6)+1): #"Berk ! What's ";c$;" ?": #'"Wally ! ";c$;" isn't on the tape.": ##"Moron ! Try spelling straight": #"sorry, ";n$;" ? ": #"Are you tired, ";n$;" ?": $"Don't wind me up, ";n$: $T $V scrhdr() $Y $\9900&:: $ $ qsthdr() $ $'9600%:9900&:egc=0: $ $ $endsec(start,c$) $ $5"That finishes ";c$:"Hit r to repeat this section" $ 9900& $a$="r"start $return $ $ $getans(loop,exp) $ $?dp=0:err=0:u$:u$:(u$)>10 err=1 $(u$)=09460$ $[j=1̱(u$):(u$(jj))<45-ů(u$(jj))>579ů(u$(jj))=47/err=1 $%9480%:j:u$="-."err=1 $Cerr=1dp>1"type the answer as a number":9460$ $=ans=(u$):(exp-ans)>0.005y# ="No, the answer is ";exp $$(ans-exp)0.005y# =9720% $return $ % %$(u$(jj))=46.dp=dp+1 % ,j>1Ư(u$(jj))=45-err=1 %  %k9800H&:d1=r(1)/10 +r(2)/100d+r(3)/1000:dec=d1:int=1000*dec %& %A"See if you understand this by trying the following examples" % 9800H& % %"True or false ?" %a$ %a$ %a$"t"a$"f"9650% % %n:n;"/";:d:d: % 9630% % % %praise % %%9720%+((*9 )+1): % "Good": % "Correct": %"Right again": %"OK": %"That's it": %"Brilliant !": %"Well done": &"Very good": &"Genius !": &HWz=110 :r(z)=(*9 )+1:z:r(1)r(2)9800H&: &R#r(1)r(2)9800H& &\ &z "trap": & &"Hit C to continue" &a$= &a$="c"9950& &a$="r"9950& & 9920& & &z=1502:z &  32&crhdT$sthd$ndse$etan$ig"iF#xes(#P#xe#riangl#iagrarais%qure"qupa"gxeturr$ntarȅ  >@@@>||BBBBB,,BBBBB<@|@<x~(8DD0H0  P    b SYSTEM OPERATION Present-day digital computers have essentially five functional elements, these elements being: 1.the input devices 2.the storage or memory unit 3.the arithmetic unit 4.the control unit 5.the output equipment Those input and output devices that are not part of the computer proper but are used for auxiliary functions, are called 'peripherals'. DATA Processing of the data is carried out by the arithmetic and memory units under the supervision of the control unit, while communication with the outside world takes place through the input and output devices. The information to be processed is usually presented to the computer in terms of binary digits. INPUT Information from the outside world originates from a number of media and can be conveyed to the input section of the computer in various forms. Data may originate from a notebook, business file, telephone network, radio transmitter, teletypewriter, or perhaps a radar set. This information must first be converted into binary machine language acceptable to the input unit. In addition to the data to be processed, a program of operating instructions is prepared that prescribes the manner in which operations are to be carried out. Both data and instruction are transferred to the computer input section, which selects the information in the order needed and feeds the resulting selection into the internal store (memory). STORE OR MEMORY The internal store, or memory, unit consists of a large number of locations (RAM) where data and instructions are stored. Each location has a unique address where the information can be found. Instructions and data are written into or read out from internal storage without discriminating between them. ARITHMETIC UNIT The arithmetic unit is the calculator of the computer. Calculations are broken down into the simplest processes, e.g. addition or looking up in a table. Subtraction may be carried out by adding complements, multiplication by repeated addition and shifts, division by repeated subtractions and shifts. The arithmetic units also make various logical decisions, such as AND, OR, NOT, and other operations. If the decisions are in terms of numbers this is simply an extension of addition and subtraction. CONTROL UNIT. The control unit directs the flow of data throughout the system and controls the sequence of operations. To do this it interprets the coded instructions contained in the program and makes the appropriate command to the various computer sections. These commands in the form of control signals, flow along control lines, opening or closing switches (gates that connect registers to the bus) and so control the data flow according to the program. INPUT AND OUTPUT Like most work, a computer's has this simple overall pattern : input -> processing -> output You might think, quite sensibly, that only the processing part is the actual computer. In fact, the I/O devices are considered to be part of the computer system. This means that the overall view of a computer system looks like this: input -> central -> output device processor device Computers generally have a variety of I/O devices, all connected to the central processor. They are commonly called peripherals. Computers process data, and input devices are the various means of feeding in data. Output devices present results Input and output media belong to two main catagories: 1. High speed media 2. Low speed media High speed media can be created and read only by a computer, whereas slow speed media can be created and read manually. THE STORAGE OF INFORMATION IN THE COMPUTER MEMORY Types of Store In the order of increasingstorage capacity, we candistinguish the followingtypes: 1.Storage of a Single Digit. All bistable devices can storeat least one binary digit, orbit. Devices include flip-flopcircuits. 2. STORAGE OF SEVERAL BITS Devices that can hold acharacter or a complete word,consisting of data or aninstruction, are calledregisters. Registers can bemade up of a number offlip-flops. 3. MAIN INTERNAL STORE The internal memory of thecomputer, with which we areprimarily concerned in thissection, stores many thousandsof complete words. 4. BUFFER STORE Intermediate in size betweenthe main internal memory andregisters, the buffer orback-up memories are designedto compensate for differencesin speed in various parts ofthe computer; data transferredto buffer storage from ahigh-speed portion of thecomputer are storedtemporarily until they can beused by a lower-speed portion, such as a print-out device.Any of the bistable elementsused elements for registersand internal storage can alsobe employed for buffer, orback-up, stores. 5. EXTERNAL STORAGE The computer program,subroutines, and other inputand output information areheld in external stores, as ina filing cabinet. This type ofstore usually has a capacityof millions of words and isrepresented by magnetic tape reels, puched paper tape, orpunched cards. STORE CAPACITY SPEED ACCESS mg.core Low High Para. (4-12k) (5us) mg.drum Medium Med. (8-50k) (10ms) mg.tape Unltd. Low Serial punched Unltd. Low Serial cards punched Unltd. Low Serial tape MOS RAM medium High Para. <1000k (250ns) Magnetic core and drum memories are shown for historical interest only. COMMUNICATION WITH PERIPHERALS The devices which put datainto the computer and thosewhich record the results. The speed at which thesedevices work is very important. The processing ofdata; the calculations, etc.take place very quickly(microseconds) and usuallyhave to waste time waiting forthe next input data. This why the speed of inputand output devices are soimportant; to make the most ofthe computer's speed. Communication with peripherals can take place either serially or in parallel. Serial communication consists of a stream of bits sent one after another. To distinguish words from one another, start bits and stop bits are used Parallel communication takes place one word at a time (in practice this means 8 bits) Most peripherals work at a data rate of between 300 and 9600 bits per second. Old-fashioned teletypes worked at 110 bits per second. X5  U2NcomAcC&Svvvvvvvvvvvvvvvvvv ch4 C4wEkh$(20,32 ):t$(7,7,16,32 ):w(25,8):5000:2000 tuition template  G C E Tutoring  Aug 1984 6:6:0  r(10 ) t(5):9069m# Lscrhdr=9300T$:qsthdr=9350$:endsec=9400$:getans=9450$ fig2=8950":fig=9030F#:axes2=9000(#:eg=9040P#:axes=9100#:triangle=9150#:diagram=218:praise=9720% 5br=8100:squrec=8850":squpar=8900" <:"COMPUTER STUDIES help ch4"::"LEVELS OF COMMUNICATION" :" GCE Tutoring Aug 1984" 2z:"Hello, what's your name ?":n$:n$:"OK, ";n$;",":"I'll begin by telling you how touse this computer studies tape." 4a:"This tape covers 5 subjects which all come under the headingof levels of communication." :>:"Press the key marked C so I can type the next screenfull" <a$=:a$="c"62> = 60< >:z=1100d:z AF:"Thanks. From now on when I want you to press the C key, I'll say" D:" Hit C to continue" F1:"Here's the list of subjects on this tape": H"machine code assemblers compilers and interpreters high level languages errors in programming" K2:"Which subject do you want to try ?":s$: Lc$=s$ N'(s$)>3s$=s$(13) Ps$="mac"200 Rs$="ass"400 Ts$="com"600X Vs$="hig"800  Xs$="err"1000 _ 70F c     x=15 z=116 t$(1,x,z) z scrhdr x ,qsthdr 1,"Compared to BASIC, machine code runs :": 6^"1. slower 2. about 50 times faster 3. about 1000 times faster" ;4egc=3:exp=3:return=320@:getans 2start=200:return=398:n$=c$:endsec       x=14 z=116 t$(2,x,z) z scrhdr x qsthdr C"An assembler converts instruction mnemonics into : ": P"1. machine code 2. high level language 3. microcode" 4egc=3:exp=1:return=520:getans #"Assemblers allow the use of :":  X"1. relative addresses 2. symbolic addresses 3. both of these ?" 4egc=3:exp=3:return=535:getans ?"Without an assembler, programmers had to use :": W"1. absolute addresses 2. symbolic addresses 3. both of these ?" !4egc=3:exp=1:return=550&:getans U2start=400:return=598V:n$=c$:endsec V X Z ] ` gx=14 lz=116 qt$(3,x,z) vz {scrhdr x qsthdr "A compiler :": "1. converts a program in high level language into machine code 2. translates a program into machine code each time the program is run 3. converts instruction mnemonics into machine code ?" 4egc=3:exp=1:return=720:getans "An interpreter :": "1. converts a program in high level language into machine code 2. translates a program into machine code each time the program is run 3. converts instruction mnemonics into machine code ?" 4egc=3:exp=2:return=735:getans 0"Compared to an interpreter, a compiler :": _"1. runs faster 2. runs slower 3. runs at the same speed ?" 4egc=3:exp=1:return=750:getans 2start=600X:return=798:n$=c$:endsec    " % ( *"HIGH LEVEL LANGUAGES": /x=14 4z=116 9t$(4,x,z) >z Cscrhdr Hx qsthdr "Basic is :": \"1. a high level language 2. a low level languge 3. a type of assembler ?" 4egc=3:exp=1:return=920:getans 9"High level languages are implemented using :": V"1. compilers 2. interpreters 3. either of these" 4egc=3:exp=3:return=935:getans 7"Which of these is not a high level language ? ": P"1. Pascal 2. Algol 3. Assembler" 4egc=3:exp=3:return=950:getans 2start=800 :return=998:n$=c$:endsec      x=14 z=116 t$(5,x,z) z :x=311 ,18;";":17,0;" "  scrhdr x "3. SEMANTIC ERRORS": "A semantic error cannot normallybe found by a compiler, and is consequently not detected until execution. It is an error in meaning, and is therefore much harder to correct than a syntactic or semantic error. An example is :": $"LET x=-b^2+(b-4*a*c)^0.5 which is perfectly legal, but not very useful if what you really meant was : LET x=-b+(b^2-4*a*c)^0.5" )scrhdr ."Some semantic errors can be found by the compiler : e.g. LET z=(x+y)/(x-x) Division by x-x is division by zero, which will cause an error.": 0scrhdr 3v"The equivalent in English is a grammatically correct sentence with no spelling errors, which doesn't mean what was intended. e.g. ""Would you like tea and coffee ?"" instead of : ""Would you like tea or coffee ?""" 8scrhdr Bqsthdr L'"A spelling error corresponds to a": QU"1. lexical error 2. syntax error 3. semantic error" V5egc=3:exp=1:return=1115[:getans [,"A grammatical error corresponds to a :": `U"1. lexical error 2. syntax error 3. semantic error" e5egc=3:exp=2:return=1130j:getans j*"An untrue statement corresponds to :": oU"1. lexical error 2. syntax error 3. semantic error" t5egc=3:exp=3:return=1145y:getans 4start=1000:return=1198:n$=c$:endsec     x=17 z=116 t$(6,x,z) z scrhdr  u3start=400:return=1398v:n$=c$:endsec v x z }  =4start=1400x:return=1598>:n$=c$:endsec @ B H Jh$(18): 4start=1600@:return=1798:n$=c$:endsec       h$(19): 4start=1800:return=1998:n$=c$:endsec   x$="": o=1̱x$ n=18 #w(o,n):x$(oo)+n-1,w(o,n) n o  H24,16,16,32 ,16,16,24,0 C24,8,8,4,8,8,24,0 F0,0,62>,64@,64@,64@,62>,0 E0,0,124|,2,2,2,124|,0 G0,66B,66B,66B,66B,66B,44,,0 G0,44,,66B,66B,66B,66B,66B,0  G0,0,60<,64@,124|,64@,60<,0 I240,8,120x,128,248,0,0,0 C0,0,0,4,126~,4,0,0 I248,136,136,136,0,0,0,0 C4,4,228,4,0,0,0,0 G240,8,240,8,240,0,0,0 G28,20,16,16,8,8,40(,568  E4,68D,228,68D,0,0,0,0 "G16,16,16,0,0,480,72H,480 %E12 ,18,18,12 ,0,0,0,0 (E7,4,4,8,8,144,80P,32 *G4,8,16,16,16,32 ,32 ,32 ,G32 ,32 ,32 ,16,16,16,8,4 /C32 ,16,8,8,8,4,4,4 2C4,4,4,8,8,8,16,32 4   save screen  ptr2=0 z=16384@22528X ptr=z-16383? data=(z) Jdata0ptr2=ptr2+1:j$(dgnum,ptr2)=(data):k(dgnum,ptr2)=z z    !fetch screen $ &z=16384@23296[ (ptr=z-16383? +data=(j$(dgnum,ptr)) 0z,data :z D N S fetch fast X 3200 Yx=16384@23296[ Z x,((addr)) ]addr=addr+1 `x b  fetch screen bits   z=1pxnum k(dgnum,z),(j$(dgnum,z)) z    save arrays   "text"t$() r  z=31000 %v=((z^2-(z-1)^2)) u=v^0.5 C((u)-(u+0.5))<0.01z# =z;":";z-1;":";v^0.5 z    start  !7,10 ;"PLEASE WAIT"  ""t$()  41:7,9 ;"STOP THE TAPE":0  300,   #( #2K27,41):110n,0:27,41):0,557 #:]17,3;"0":17,6;"2":17,9 ;"4":17,12 ;"6" #<17,15;"8" #>\16,2;"0":14,2;"2":12 ,2;"4":10 ,2;"6" #A #Fi579+x,513+y:20,20:-20,20:-20,-20:20,-20: #Hc72H+x,568+y:0,30:-30,0:0,-30:30,0: #P'"Here is an example of ";n$ #R #Z #\ #_noises #b #d-z=120:0.01z# =,-24:z #f #h #i&z=15:0.3,t(z):z #l #mz=15:t(z):z: #n*7,9 ,5,-7,0 # # # # axes(atype) # #_30,90Z:210,0:30,90Z:0,557:0,-110n #10 ,2;"0" #f11 ,9 ;"90":11 ,15;"180":11 ,22;"270":11 ,29;"360" #atype=09124# #atype=19130# #.4,2;"1":16,1;"-1" #07,1;".5":13 ,0;"-.5" # #.7,2;"1":13 ,1;"-1" #.4,2;"2":16,1;"-2" # # # #draw triangle(label) # #N30,60<:100d,0:0,60<:-100d,-60< #label=09175# #15,6;"adjacent" # 8,1;"hypoteneuse" #11 ,18;"opposite" #6123{,60<:0,7:7,0 #H41),60<:0,2:-3,2:-2,0 #14,2;"A" #14,17;"B" #6,17;"C" #::::::::: # # # # # replies() # #':9210#+((*6)+1): #"Berk ! What's ";c$;" ?": #'"Wally ! ";c$;" isn't on the tape.": ##"Moron ! Try spelling straight": #"sorry, ";n$;" ? ": #"Are you tired, ";n$;" ?": $"Don't wind me up, ";n$: $T $V scrhdr() $Y $\9900&:: $ $ qsthdr() $ $'9600%:9900&:egc=0: $ $ $endsec(start,c$) $ $5"That finishes ";c$:"Hit r to repeat this section" $ 9900& $a$="r"start $return $ $ $getans(loop,exp) $ $?dp=0:err=0:u$:u$:(u$)>10 err=1 $(u$)=09460$ $[j=1̱(u$):(u$(jj))<45-ů(u$(jj))>579ů(u$(jj))=47/err=1 $%9480%:j:u$="-."err=1 $Cerr=1dp>1"type the answer as a number":9460$ $=ans=(u$):(exp-ans)>0.005y# ="No, the answer is ";exp $$(ans-exp)0.005y# =9720% $return $ % %$(u$(jj))=46.dp=dp+1 % ,j>1Ư(u$(jj))=45-err=1 %  %k9800H&:d1=r(1)/10 +r(2)/100d+r(3)/1000:dec=d1:int=1000*dec %& %A"See if you understand this by trying the following examples" % 9800H& % %"True or false ?" %a$ %a$ %a$"t"a$"f"9650% % %n:n;"/";:d:d: % 9630% % % %praise % %%9720%+((*9 )+1): % "Good": % "Correct": %"Right again": %"OK": %"That's it": %"Brilliant !": %"Well done": &"Very good": &"Genius !": &HWz=110 :r(z)=(*9 )+1:z:r(1)r(2)9800H&: &R#r(1)r(2)9800H& &\ &z "trap": & &"Hit C to continue" &a$= &a$="c"9950& &a$="r"9950& & 9920& & &z=1502:z & X 32&crhdT$sthd$ndse$etan$ig"iF#xes(#P#xe#riangl#iagrarais%qure"qupa"gxeturr$ntarȅ  b MACHINE CODE Once a program has been written, it has to be translated into a code so that the computer can understand it. This is "MACHINE CODE". Generally, an instruction is coded into a number. This number, when placed in a special register called the "CONTROL REGISTER" will cause the machine to obey the instruction. This is simply because the number in a register consists, in effect, of the setting of a number of electrical switches which are either open or shut, depending on the particular number which they represent. These switches cause various electronic gates to be open or shut as appropriate. The driving pulses are then allowed to perform the function that is required. Once the instruction has been performed, it is necessary for the computer to proceed with the next instruction. An instruction really has two distinct halves : 1) Perform the instruction 2) Move on to the next the instruction This last half of the instruction will cause the next step to be immediately carried out. This, in its turn, contains the address of the next instruction, and so execution continues until the final instruction "STOP" is reached. Many machine code instructions are needed to perform even simple operations. For example the only arithmetic functions available in most machine code are add and subtract. Other essential operations such as multiplication, division and scientific functions have to be made up out of many simpler instructions. Another difficulty in using machine code directly is that the numerical representation of an instruction is arbitrary. eg. 131 means (in Z80 code) "add the contents of registers A and E" Until the mid 1950s, all programming was done using machine code direcly. ASSEMBLERS An assembler is a computer program which operates on symbolic input data to produce instructions in machine language. An assembler generally translates symbolic operation codes and converts relative addresses to absolute addresses, with the result that the same number of instructions are obtained in machine code as were written in symbolic form. Until the mid-1950s, the programmer's list of instructions, each with the storage address at which it was to be stored, would be punched into cards. A program loading routine would then store the instructions, each at its specified address. The symbolic program omits any sort of address for so many instructions because they're not needed. When it encounters a symbolic address for an instruction, the special assembler program allocates an actual machine address. Whenever it encounters the same symbolic address within an instruction, it substitutes the same actual address. Where it encounters no address for an instruction it knows that it must store the instruction in the in the next sequential memory location. In the section on machine code an instruction is shown using its numerical representation. Below are the numeric and symbolic forms of the same instruction : numeric : 131 symbolic : ADD A,E Both of the above mean "add register A to register E, and leave the result in register A" COMPILERS AND INTERPRETERS A compiler, or compiling system, has an input language made up of abstract terms and a stored machine program (a translator) for changing or translating the input language into an output language. This output language may be in machine language which can be used directly on a specific computer, or it can be a language requiring translation. Interpreters perform the same function as compilers, but instead of translating a program into machine code, they interpret each statement directly. Interpreters are slower than compilers. Compiled languages include Pascal, C, ALGOL and Ada. PROGRAMMING LANGUAGES The first electronic data-processing systems could be used only by experts, because instructions to the computer had to be given in special codes or 'machine language'. This led to the development of programming languages which are simpler to use than machine language or direct coding. Languages are problem oriented rather than machine oriented, which means only that they are designed for easy and direct use with a specific class of problems. They are more suited to the problem and the programmer than is a machine language. ALGOL is a typical high-level language. Details are in the next section. ALGOL is a typical high-level language and will be taken as an example. ALGOL ALGOL is an acronym for ALGOrithmic Language and it is accepted as a common international language for use with algebraic problems. A typical use of ALGOL would be to evaluate an expression such as: 3x^3+5x^2-16x+29 the range of x may be a series of values, such as 4, 8, 14, -2, 9. Each value is for x, and the expression is calculated; the results are printed out; ALGOL permits a direct method of writing out the required program. CHARACTERS The basic letters or symbols are characters of different types. There are seven types of character in ALGOL; these are letters, digits, logical values, arithmetic operation, relational operators, logical operators, and delimiters. The letters are upper-case A through Z, lower-case a through z, and digits 0 through 9. The logical values are T for true, and F for false; these are the same as letters T and F used in a series of letter but are distinguishable by their use. STATEMENTS When an ALGOL program is changed into machine code, each variable,eg. a or b, will be assigned a storage or memory location. Identifiers are sequences of letters, such as A, C, Q, or alpha, representing variables. They can be assigned to variables and retain their identification throughout the program. ERRORS IN PROGRAMMING Errors in programming fall into 3 main catagories: 1. lexical errors 2. syntactic errors 3. semantic errors They are listed in increasing order of severity. Let's take them one by one. 1. LEXICAL ERRORS A lexical error occurs when a reserved word or token within a language eg. IF, THEN, WHILE is misspelt. It is the equivalent of a spelling error in English. If the compiler being used has limited error recovery, the lexical error may in turn cause other errors. Lexical errors are often simply typographical mistakes. 2. SYNTAX ERRORS A syntax error is a grammatical mistake. Here is an example of a program written in Pascal which contains a syntax error. PROGRAM ADD(INPUT,OUTPUT); VAR X,Y,Z :INTEGER BEGIN READ (X,Y); Z:=X+Y WRITELN(Z) END. Statements in Pascal must be separated by semicolons, so a syntax error will be detected when the compiler meets WRITELN after the expression x+y. The equivalent in English to the above mistake is the omission of a full stop. 3. SEMANTIC ERRORS A semantic error cannot normally be detected by a compiler, and is consequently not discovered until execution It is an 97464302:42272622<1922:40242062479:04297$22402062709:4297&""/ !$482326<62! 1:77;2<::4<6:&""/ ! 2062709:42974"34403046<1929:21;470<926432979;4276;0<4:2225  CerrorsSerrU3NerrorsAc