Iconic Machines

Manual / Guide · 1971

KENBAK-1 Laboratory Exercises (1971)

Read the PDF ↗

The graded programming exercises supplied with the KENBAK-1.

Author
Kenbak Corporation
Year
1971
Type
Manual / Guide
Credit
Kenbak Corporation; copy from adwaterandstir.com

← Back to the Reference Library

KENBAK-1 Laboratory Exercises (1971)

Laboratory Exercises KENBAK-l Computer KENBAK CORPORATION P.o. BOX 49324 LOS ANGELES, CA. 90049 C KENBAK CORPORATION 1971 ALL RIGHTS RESERVED Preface These Laboratory Exercises I in a workbook format I are intended for independent work. Ideas and concepts are introduced in small increments and are interspersed with actual experience on the computer. Emphasis is placed on the principles of self-discovery immediate feedback, I a nd rewards. Other books or material might be used as companion volumes for a more formal and theoretical presentation. However, the Exercises are independent and may be used as the only reference material. Questions and comments are welcome. Kenbak Corporation P. O. Box 49324 Los Angeles California 90049 U. S. A. I EX - i Rev A Exercise 1 Every computer has a memory in which numbers are stored.. Some of the numbers are instructions which tell the computer what to do.. Other numbers are data which the computer operates on to obtain the answers to problems.. Before long we will expect you to be telling the computer what to do . The memory in our computer is divided into 256 memory locations. At this time we can understand these best as 256 boxes or drawers I see Figure 1. 1 0 Each box is one memory location and contains one number. A number may be changed in any location by using the pushbuttons on the front panel of the computer When a number is stored or placed in a s memory location, the number which was there before is destroyed or lost e Or a number in any location may be examined and displayed in the lights on the front panel of the computer 0 Examining or reading a number in a memory location does not change it or remove it. Every memory location has an address which is the name of the location e This address is a number itself. number in a memory location I If we wish to read or store a we must first say what the address is. Because the word Unumber" can mean two different things to us I we are likely to get confused. You may not know whether we mean an address of a memory location or whetherw"e mean the contents of the memory location 0 Let s agree that when we say: I Number: We mean a number in general. It could be an address I or the contents of a memory location I or something else. Address: We mean a number which is used as the name of a memory location. Data: We mean a number which is stored or is going to be stored in a memory location. All addresses are numbers. All data are numbers. Not all numbers are addresses or data. EX 1-1 Each box or memory location contains one number. We can see the number in this box because it happens to be on top. The other memory locations contain numbers too. The numbers may be changed. This box represents one memory location. There " - - are 256 memory locations ~ in the computer. 11001001 00000000 00000001 00000010 00000011 00000100 00000101 00000110 00000111 00001000 00001001 00001010 00001 011 00001100 00001101 00001110 /~--- The number on the outside of the box is the address of the memory location. It never changes. ............ I The dashed lines indicate boxes which we did not draw. Figure 1. 1 ---¢ I 101011011 11111111 The Memory In The Computer May Be Thought Of As A Group Of Boxes EX 1-2 Our addresses and data are made of eight digits where each digit is a 0 or a 1. This kind of number is called IIbinary" because there are only two choices in each position, 0 or 1. In our more familiar decimal numbers there are ten possibilities in each position. numbers are best. For us J For the computer, binary binary numbers seem strange. We wi 11 see that they are very easy to learn though. We will let a 0 in a binary number mean that no button is to be pushed. We will let a 1 mean that a button is to be pushed. We will read a light that is off as a O. A light that is on will be a 1. o = Button Not Pushed = D or Light Off = 0 1 = Button Pushed =. or Light On = • That1s easy enough, isn1t it? Let S use what we have learned with the computer. I Figure 1.2 shows the location of the lights and switches on the front panel. We won It tell you about all of the switches and lights now. If power is off when you begin, turn the Power switch to the On position. Push the Start button and then push the Stop button. If power is already on I push Stop. Then you are readYe The small toggle switch between the Address and the Memory lights should be placed in the UNL position. When this switch is in the LOCK position, data cannot be entered from the front panel. In the UNL (for Unlock) position, entry from the control panel is possible. EX 1-3 8 OUTPUT LIGHTS .0 .0 ••0.. 0 0 0 ~ DDDDDDDD D DO 0 ODD I I 8 INPUT PUSHBUTTONS I I 4 ~ I I I I I I I I ~4 I ' ~ I POWER POTS_~ ______ START I I I I I I I I 10101101 I I AN EXAMPLE I I STORE READ MEMORY ...-. w...- _ SET DISPLAY ADDRESS ____________-.CLEAR Figure 1.2 The Front Panel of the Computer Let ISS ee how we ca n enter data into a memory location. We must do two things. First I we must tell the computer the address of the memory location to be used. be stored is. Second I we must tell the computer what our data to Let1s suppose we want to store the data 00111000 into the location whose address is 10 10 110 1 0 First push Clear I then use the eight input pushbuttons to enter the address. The picture shows this number being entered. As each 1 is entered, the output light above it will turn on. If you make a mistake, use Clear to erase all of the lis and try again • . When the output lights show that you have entered the number correctly I you can go on. To tell the computer that this is an address I push the Set Address pushbutton. Now we can enter the data to be stored. To do this This erases the number which was our address. I push Clear. (When we pushed the Set Address button, the computer made a copy of this number in another place.) Now enter the data I pushing the input buttons which correspond to lis. In our example, (data = 00111000) I these are the 3rd, 4th, and 5th positions from the left. When these are correctly entered, we can store the data. To do that, push Store Memory. EX 1-4 How do we know it was done right? we had told it to do? Did the computer really do what Letls read what is in location 10101101. To read the data in a location, the address of the location is entered first It Push Clear and then the input buttons which correspond to the 11 s in the address. When the number is correctly entered, use the Set Address pushbutton to tell the computer that this is an address. After doing this I push Read Memory. The data in the memory location whose addres s you just entered will be shown in the output lights. In our example this should be 00111000. START READ STORE ENTER ADDRESS ENTER ADDRESS SET ADDRESS SET ADDRESS READ MEMORY ENTER DATA DATA APPEARS IN LIGHTS STORE MEMORY Figure 1.3 Can You Find Your Vvay Around The Boxes? What Does It Tell You? EX 1-5 Try entering the following numbers: In the location whose address is Store the data 10000001 11001100 01010011 11010001 00000000 00001111 00001111 10101010 11111110 00000000 00101100 00000001 00001010 00000011 00001011 00000100 After you have entered the information, read these same locations and see if the numbers are there \I T'hey should be. see if they are still there. Read them a second time and Reading or copying is non-destructive. The number remains I it is not destroyed. Try this experiment. your entry. Turn Power off Store the data below. Read the data to check \I Turn Power on. Push Start. Push Stop. Now read the contents of these locations and fill in the blanks. After Power is Off and On Location 00000000 1100 110.0 11110000 00110011 00001111 11001100 Has the data changed? --------Do you know why? -----_._----------- Try this also. Put the data 00000000 into location 11111111. Nov! read the contents of location 11111111. What did you read? - - = - - = - - ~ - , - - - - - - - - - - - - - - This is a special location and we will learn more about it later. Put the small toggle switch in the LOCK position and try to enter data. Can you enter data? Can you read data? EX 1-6 Exercise 2 In Exercise I, we learned how to read and to store one number in one memory location. We used different addresses, but the memory locations were not adjacent. They did not follow one after the other. Usually I we will read or store numbers in locations that follow one after the other. Their addresses are in a continuous sequence like 2, 3, 4, 5, etc. The computer contains a feature which makes it easier to read or store in locations that follow after each START other. Whenever the Read or Store pushbutton is depressed, the address ENTER ADDRESS counts by one inside the computer. The address is a binary number. We haven't discussed how binary numbers count though we will shortly. For the time being we don It need to know what a consecutive sequence of binary numbers looks like. DATA APPEARS IN LIGHTS To read the contents of a number of locations whose address are consecutive (like 17,18,19,20,21), the address of the smallest one is entered (including Set Address) . Depressing the Read pushbutton once causes the data in that location to be displayed. Pushing the Read pushbutton again causes the data in the next location to be displayed. We can repeat this for as many times as there are locations to be read, Figure 2.1 Figure 2. 1 Reading EX 2-1 To store numbers in consecutive START locations I again the address of the smallest one is entered. Then the data to be stored in the first location ENT·ER ADDRESS is entered with the input buttons and the Store pushbutton is used once. The address is automatically advanced to the next location by the computer. The data to be stored in this second ENTER DATA location is entered in the input buttons (after clearing) and Store is STORE MEMORY depressed again. The process is repeated until all of the data has .been stored, Figure 2.2. Let IS try it 011 the computer, but first let s review whether you I remembered how to store data in one location and to read it back. Into location 01000 III put the data 10111000. Read the contents of location 01000 Ill. Does it contain 10111000, the data which you had put there? If you were unsuccessful or didn It remember how I you should go back and review Exercise 1 before continuing. Figure 2.2 Storing Have you noticed that it is hard to keep track of your place when }TOll are reading our binary numbers? It is easier to read the numbers if the eight a Isand 11 s are placed in groups. Instead of 11100100 the grouping 11 100 100 is easier to read. You III make fewer mistakes if you do it this way. EX 2-2 Starting with location 00 000 oII, store the following data: In Location Store 00 000 all 00 000 100 the next location 00 000 all the next after that 00 000 001 and the next 00 011 100 and so on 10 000 000 11 100 100 Stop after this one 00 000 100 Check yourself by reading the contents of the seven locations which start with location 00 000 011. do not agree, try again. Do they agree with the data above? If they Try to find out why you went wrong. When you are able to store the numbers above and to read them correctly I and while the data is in the computer, then try this experiment. Push Start and release it. What happens to the display lights ? _ Do you think there is a pattern? Push Stop. What happens? After you have stopped the computer I try this experiment. address to 11 000 000. Set the Enter the number 11 III III in the input buttons and push Store five times. Then push Clear which will make the entry number 00 000 000. Push Store five more times. Now set the address to 11 000 000 (the same as before) and read the contents of the ten locations that start with this address. Did you find that 11 III III was stored in the first five locations and that 00 000 000 was stored in the next five locations? If you are storing the same data into consecutive addres s es I must you re-enter the number with the input buttons after the first entry? - - - - EX 2-3 Exercise 3 In the first two exercises we learned how to store numbers in the memory and how to read them. The numbers \l\Tere binary I not our familiar decimal. Binary numbers use only the digits 0 and 1. A binary digit has been gi ven the special name I "bit n. A bit may be a 0 or 1 but it is never a 2 I 3 I 4 I 5 I 6 I 7 I 8 I or 9 . In Exercise 2 I you were asked to store a series of numbers and I after checking the entry by reading these same numbers I you were asked to push Start. The output lights should have started blinking. The numbers you stored in the memory were instructions or commands to the computer to do some simple operations. This set of instructions was a program. The computer was using this program over and over. As soon as it finished doing the operations once I the computer went back to the beginning of the program and did the operations again. In this exercise we will load another program which is very similar to the program in Exercise 2. In this program the computer halts after it does the operations once. It will do them once again when you push Start. As often a s you push Start I it will .do the required operations once and then halt. Let1s load the program and see what is does. Starting with location 00 000 all, store the following numbers in the memory: Location Store 00 000 all 00 000 100 next 00 010 011 next 00 000 000 next 00 all 100 next 10 000 000 next 00 000 000 next 00 000 all next 00 000 001 next 11 100 100 next 00 000 110 EX 3-1 Read the numbers you entered. Every bit must be right. If there are any errors I correct them by entering all of the numbers. Push Start once. get this result I The output lights should all be out. or if the Run light did not go out I If you did not you have probably entered the numbers wrong. Try again I re-enter all of the numbers. Push Start once. The lights should now be 00 000 00. Push Start once again. • The lights should now be 00 000 oeo . Push Start a few more times I observing how the lights change. Can you tell in advance which lights will turn on and which lights will turn off? Try to make up rules which tell you how the lights will change. Push Start and see if the lights do change in the way that your rule says they will. Try this several times. You may have to change your rules but keep trying until you can always tell what the next pattern in the lights will be. If you want to start at the beginning again I put the number 00 000 100 into location 00 000 011. You have been asked to find a rule about how the lights change. If you did find a rule which told you what the next pattern in the lights would be I you have discovered for yourself how to count in binary. EX 3-2 The rule which tells how the lights cha nge might read: Find the first light at or from the right hand end that is Off. This light will change to On. All of the lights from the right hand end up to this light but not including this light will change to Off. None of the other lights will change. I I a11. This will Put the number 00 000 100 into location 00 000 start you at the beginning again. Try using the rule above to predict what the next pattern in the lights will be as you push Start e The rule above also tells us how to count in binary. All that we have to do is to change the words "light Then, given a binary number I ll to II bit II I nOn u to I, "Off ll to O. the next binary number is determined by the rule: Find the first bit at or from the right hand end that is O. This bit will change to 1. All of the bits from the right hand end up to this bit but not including this bit will change to O. None of the other bits will change. I I Let I S apply this to some binary numbers. , This number This is the first 0 bit from the right end. Change it to 1. All of these change from 1 to O. 00 000 III A.A counts to 00 001 000 This number 00 001 000 , A counts to 00 001 001 This number 00 001 001 t • counts to This is the first 0 bit from the right end. Change it to 1. There are no bits to change from 1 to O. This is the first 0 bit from the right end. Change it to 1. All (in this case ,one) of these change from 1 to o. 00 001 010 EX 3-3 Put the number 00 000 100 into location 00 000 once. a11. Push Start The lights should show you 00 000 000. We have written this number down already in the Table below. Before you push Start again, write down what the next number will be. Push Start and check yourself. Then write down the next number and use Start to check your answer. Repeat these steps until you have filled in the table. 0 0 0 0 0 0 0 0 o 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 0 0 1 0 0 0 1 The correct results are given on the next page. 17 Check your numbers against these. EX 3-4 00 000 000 00 000 001 00 000 010 00 000 all 00 000 100 00 000 101 00 000 110 00 000 III 00 001 000 00 001 001 00 001 010 00 001 011 00 001 100 0 1 2 3 4 5 6 7 8 9 10 11 12 00 001 101 13 00 001 110 00 001 III 00 010 000 00 010 001 00 010 010 00 010 all 00 010 100 14 15 16 00 010 101 00 010 110 00 010 III 00 011 000 00 all 001 00 all 010 00 all 011 00 all 100 00 all 101 00 all 110 00 all III Table 3. 1 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 First Few Binary Numbers EX 3-5 Exercise 4 Using Table 3. 1 from the last Exercise I answer these questions .. What decimal number is beside the binary number 00 000 001? What decimal number is beside the binary number 00 000 010 ? What decimal number is beside the binary number 00 000 lOa? What decimal number is beside the binary number 00 001 OOO? What decimal number is beside the binary number 00 010 OOO? Write the sequence of decimal numbers which are the answers to these five questions (start with 1) • What do you think the next decimal number would be? ------ What binary number is the same as this number? ---------What do all of these binary numbers have in common? The decimal sequence is I, 2 sequence is 32 e I 4, 8 I ------ 16 and the next number in this This is the binary number 00 100 000. All of these binary numbers have one and only one bit that is a 1. Now look in the Table at the binary number beside 3. that it has two bits which are lis? Can you see Can you find the two binary numbers that have single lis in these positions? 00 000 001 00 000 010 00 000 011 Here they are: 1 2 3 What is the relationship between the number 3 and the other two decimal numbers? + = Let S try another binary number. Take the binary number opposite 6. I Which bits are 11 s in it? Find the binary numbers that have single 11 s in the same positions as these bits. What are the decimal numbers? - - - - - and ----- How are these numbers related to 6? - - - - - - - - - - - - - - EX 4-1 Do the same with the binary number 00 001 101. Find the three binary numbers with single ones in these positions. What decimal numbers are opposite these? What is the sum of these three numbers? _ ----------- What decimal number is beside 00 001 101? -------- Use this same process and find what decimal numbers are equal to the binary numbers: 1001 III 1011 We know in a decimal number such as 2, 736 that this does not mean 2 + 7 + 3 + 6. We understand that the 2 is to be multiplied by a 1000 I the 7 by 100, the 3 by 10 and the 6 by 1. We call I, 10, 100, and 1,000 lfpl ace values rr • Binary numbers have place values also. They are the sequence 1,2,4,8,16,32,64,128,256, and so on. A binary number may be converted to decimal by adding up the place values where the binary number has I s l Place Values Binary Number Binary Number Binary Number Cl Let1s do it for a few binary numbers. 1. .f.. 1 ~ 1 1 0 0 1 111 0 1 1 8 + 1= 9 4+2+1=7 8+2+1=11 Earlier we asked you to convert these same numbers to decimal. get the answers shown here? Did you In the second bi.nary number above I we didn It put any bit under the 8 I s place value. If we put a bit there, what would we put there? EX 4-2 Below is a small program which is a game you can play against the clock. What you must do is to give the decimal number for a binary number which the computer first displays to you. If you are right will gi ve you another different binary number. I the computer If you are wrong I the computer will give you the same binary number again. Load the following program. Notice that the addresses are consecutive so you wonlt have to keep re-entering addresses. entries by reading. of the numbers. Double check your If you have a mistake I you don't need to re-enter all Use the address gi ven and correct the data which is in error. Location Data 00 000 000 00 000 001 00 000 010 00 000 011 00 000 100 00 000 101 00 000 110 00 000 III 00 001 000 00 001 001 00 001 010 00 001 011 00 001 100 00 000 000 00 000 000 00 000 000 00 000 110 00 000 000 11 III III 01 000 011 00 101 101 00 010 all 00 III 000 11 010 100 00 000 001 11 011 001 00 001 101 00 001 110 00 001 III 00 010 000 00 010 001 00 010 010 00 010 all 00 010 100 00 010 101 00 010 110 00 010 III 00 all 000 00 011 001 Push Start. The computer should display lights.. This is the binary number for 5 0 00 000 11 010 001 00 all 100 10 000 000 10 011 100 11 III III 00 000 000 11 011 001 00 000 all 10 000 010 00 all 100 00 000 100 11 100 100 00 000 100 eoe in the output You should push switch number 5 I DO .00 DOD. When you do this I the binary number will disappear and the light above the switch will come on. Now push Start. If the entry is correct I the computer will display another I different I binary number. If your entry was wrong I the computer will display the same binary number again. Again make your entry and push Start. The largest binary number the computer will show you is seven. smallest is o. The The first time you see the number 0 given by the computer you may think something has gone wrong. It hasn It. Try a few numbers to see how it goes I then get a friend to time you against the clock. How many correct ones can you do in a minute? EX 4-3 Exercise 5 At the end of the last exercise we were converting binary numbers to decimal. In the first part of this exercise we will do the opposite. The computer will gi ve you a decimal number from a to 7. You are to enter the binary number which is equal to this decimal number. The program to use is: Location Data Location Data 00 000 000 00 000 001 00 000 010 00 000 all 00 000 100 00 000 101 00 000 110 00 000 III 00 001 000 00 001 001 00 001 010 00 001 all 00 001 100 00 001 101 00 001 110 00 001 III 00 000 000 00 000 000 00 000 000 00 000 100 01 000 all 00 101 10 1 00 010 all 00 III 000 11 010 100 00 000 001 00 all all 00 000 000 00 000 all 01 000 010 00 all 100 00 010 100 00 010 000 00 010 001 00 010 010 00 010 all 00 010 100 00 010 101 00 010 110 00 010 III 00 011 000 00 all 001 00 all 010 00 all all 00 all 100 00 all 10 1 00 all 110 00 all 111 10 all 100 10 000 000 10 all 100 11 III III 00 000 000 10 000 000 00 000 000 00 010 100 11 III III 11 all 001 00 001 100 00 001 all 00 100 100 00 000 100 11 100 100 00 000 110 Did you check your entries? Push Start. The computer will display 00 .00 000 • number DO DOD .0. Since light number 5 is on, you should enter the binary in the switches. Push Start again. If your input was correct I the computer will display another I different decimal number. If you were wrong, the computer will display the same decimal number again. Try a few times to see how it goes and then have a race against the clock. With practice you can learn to use two and three fingers at the same time to enter the binary number. There are other number systems besides binary and decimal. One of these is called hexadecimal. There are sixteen digits in hexadecimal numbers. These are the ten digits of decimal numbers and the six letters A, B, C, D, E, and F. In hexadecimal, F + F = IE. The hexadecimal system is closely related to binary, but we won It use the hexadecimal system. EX 5-1 I Another number system is called octal. The octal system has eight digits: a I, 2 I I 3 I 4 I 5 I 6 I 7. You have been working with the octal system already. are the same. For numbers from 0 to 7 I the decimal and octal numbers The conversion problems we have been doing are true for both decimal and octal. We will use the octal system a lot. It is very similar to binary and it will make our work much easier. Though you may not be aware of it I you already know how to convert a binary number to an octal number and vice versa. To convert a binary number to octal, divide the binary number into groups of 3 bits starting at the right I for example I 001 101 110 010 Now write down the a to 7 octal digit that is equal to each 3 bit binary group above. In this case we would have 1 6 5 2 To convert an octal number to binary I do this in reverse 3 740 all III 100 000 We won It learn any arithmetic rules for octal. We can convert them to binary and do the arithmetic in binary. However I if there are no carries or borrows I then octal arithmetic is the same as decimal arithmetic. For example I all of these additions and subtractions are true for both octal and decimal numbers: + __ 5 267 146 357 _3 255 264 + ..-ll.. 177 - 113 250 244 An octal number such as 250 doesn1t represent the same quantity of things as the decimal number 250 does. Octal 10 is this many things: Decimal 10 is this many things: For example, •••••••• •••••••••• EX 5-2 There is one arithmetic operation with octal numbers that we use a lot. That is counting. The easiest way of counting in octal is to count in decimal, but to omit all of the decimal numbers which have an 8 or 9 . Complete the counts below. 5 14 (Note that the counts go down the page.) 75 46 112 035 207 6 7 10 11 12 13 With so many different kinds of numbers, how can one tell what number system is being used? For example, if you see III are you to think of seven (in binary) or seventy-three (in octal) or one hundred eleven (in decimal)? We may depend upon the context or the setting in which we see it. As a price in a store I we know it is decimal. In the computer we are working with, the number is usually octal. Sometimes when we could be confused we will do one of the following: or 111 two 111 8 or III elg · ht 111 10 or Illten binary III or 111 octal III or decimal III or 2 FOR INTERESTED STUDENTS (OTHERS NOT ALLOWED) Bi- means two. Binary numbers use two symbols. Oct- means eight. Deci- means ten or tenth. Hex- means six. Octal numbers use eight symbols. Decimal numbers use ten symbols. Hexadecimal (6 + 10) numbers use sixteen symbols. Can you give some other words that use bi-, oct-, deci-, or or hex- ? ---_._----- What is odd about October and December? EX 5-3 How many sides does a triangle have? _ What might you call the number system with three symbols? Of all the number systems that are possible I why do you think we use decimal numbers? - - - - - - - - - - - - - - - - - - - - - - - Could there be a number system with only one symbol? How many symbols does the tally system ---- (1m JIll )use? _ Does the tally system have place values ? _ In decimal, the place va lue names are one I ten, hundred I thousand I etc. There are no agreed upon names for the place values in binary I octal, and hexadecimal. We sometimes read the octal number 1,750 as lIoctal one thousand seven hundred and fifty. tr What decimal number is this? Must the binary system use the symbols 0 and 1 ? _ Could it use the symbols a and b? Why would you prefer one set of symbols to the other? Below we gi ve the addition table for octal numbers. - Fill in the empty squares. + 0 1 2 3 0 0 1 2 3 1 1 2 3 2 2 3 3 3 4 5 6 7 4 5 14 6 14 15 7 14 15 16 EX 5-4 Exercise 6 In this Exercise, weIll learn how to add two binary numbers. Again, we III use the computer and a program to help us. The program will add our input number (entered in the input SWitches) to a number already in the computer. This number in the computer will be stored in an "accumulator + ll OLD CONTENTS OF ACCUMULATOR OUR INPUT NUMBER --NEW CONTENTS OF ACCUMULATOR The addition takes place when we push Start & When the computer stops I it will display the new contents of the accumulator in the lights. As soon as we push Clear or one of the input buttons I the light s will then show the input number. When we want to clear the accumulator (set it to zero) I weIll use input switch 7 . 0 DOD ODD and Start clears the accumulator Let s load the program I and see how it works. Notice that the addresses and data have been given in both binary and octal. Try using the octal when you enter the data. When you read the data to check it, you should use the binary. After a while we will use only octal numbers I but until you are familiar with the octal system we III also put the binary number down. Data Location 00 000 000 00 000 001 00 000 010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 000 011 000 100 000 101 000 110 000 III 001 000 001 001 001 010 001 all 001 100 001 101 001 110 001 III 010 000 010 001 010 010 010 all 010 100 000 001 002 003 004 005 006 007 010 all 012 013 014 015 016 017 020 021 022 023 024 000 000 000 021 000 272 377 344 021 004 377 034 200 134 377 344 004 023 000 344 013 00 000 00 000 00 000 00 010 00 000 10 III 11 III 11 100 00 010 00 000 11 III 00 all 10 000 01 011 11 III 11 100 00 000 00 010 00 000 11 100 00 001 000 000 000 001 000 010 III 100 001 100 III 100 000 100 III 100 100 all 000 100 all EX 6-1 it Push Clear. Push Start. The lights should be out. Push switch O. Push Start. Repeat these two several times. Do you see the binary count process as we add one each time? Push switch 7. Push Start. The accumulator should now be zero. Add some number to the accumulator. Then push Clear. Push Start. Did the accumulator change? Are we adding zero to the accumulator? What we want to do now is to find rules for adding binary numbers on paper. The computer will be used to tell whether we are right or wrong. We ca n try our ideas with it. and add. Don It change the binary numbers to decimal Do all of the work in binary. Try to do this in an orderly way and organize your approach. Start with simple cases and little numbers (like 0 and 1). Test your ideas with the computer. After you have tried awhile I come back and finish reading the rest of this exercise. There is more than one way to add. You may have found a way that is different from the one to be given here. That doesn't make yours wrong. When we learned to add decimal numbers ,one of the first things we learned was the addition table. With decimal numbers I it was necessary to learn 100 combinations. One such combination was 8 + 6 = 14. How many combinations do you think there would be in binary? With 10 digits for decimal numbers I there were 10 times 10 cases to be learned. With only 2 digits for binary numbers I there are only 2 times 2 cases to be learned. And of these four cases I three of them consist of adding 0 to another number. EX 6-2 The four cases are: o 1 +-1. +--!L If you know the answers to these four problems and if you know how to "carry" I then you know how to add two binary numbers. Zero plus zero is zero. Zero plus one is one e One plus zero is one. One plus one is two. The number two is written in binary as 10. So we have: o 1 +-1. +-1. 1 10 Adding one to one creates a carry in binary. The carry for binary numbers is used in the same way as for decimal numbers. next column to the left. in a carry 1 It adds one more in the Let s take the four cases above and also add I .. 1 .. 1 ... 1 ...--- 0 0 1 1 +--!L +-1. +--!L 10 10 +-1. t t 1 11 t carry from the right carry to the left Notice that the sum I including the carry I is the binary number for the number of 11 s being added together. For example I 1 1 3 11 s being added +-1. = 3 in binary 11 Let S add two binary numbers I III + carry 1 1010101 1 1 1 a 1 1 0 11001011 first number second number answer Give the sums in the following additions and then check your own work with the computer. 1 0 a +1 a 0 a 1 a 0 1 +_I_!L.Q. 1 0 1 0 1 110 + 110 1 + __L..l.. + 1 0 0 1 1 1 III +1 0 1 1 EX 6-3 While the program is in the computer I try these experiments. Put 000 in the accumulator I then keep adding 2. These are the even numbers. Write the first few even numbers in binary. Now put the number 00 1 in the accumulator I then keep adding 2. These are the odd numbers. Write the first few odd numbers in binary. What do all of the even numbers have in common that the odd numbers do not have? Do this addition 1 0 110 + 1 0 110 How does the sum look compared to the numbers being added? Adding a number to itself is the same as multiplying by 2. Does multiplication by 2 for binary numbers have something in common with multiplication by 10 for decimal numbers? What is the number 2 in binary? _ Appendix I may be used to convert octal numbers to decimal or decimal numbers to octal. EX 6-4 Exercise 7 We have been using programs in the computer. A program consists of instructions which tell the computer what to do. An instruction is a number in the computer. Different numbers tell the computer to do different things. In our computer some of the instructions require two memory locations while other kinds of instructions require one memory location. The pair of numbers r---------- T would tell the computer: I 004 013 - - - - - - - - - - - - - - , I I I-,~A COpy OF THE NUMBER IN LOCATION 013 TO THE CONTENTS OF LOCATION 000 AND PUT THE ANSWER IN LOCATION 000 If we change the 004 to another number I we would get a different instruction I perhaps a Subtract. The 004 is the operation code. The second number in this pair is an address of a memory location. While in this example it is 013, it could be any address from 000 to 377. With this instruction we must always use the number in location 000 as one of the operands and we must use location 000 to receive the answer. We can't change that. The pair of numbers mu·st be stored in consecutive locations such as 100 and 10 1. The 004 number I the operation code, must be in the smaller of the two addresses. The me mory address, such as 013, is in the larger of the two addresses. When we put parentheses around an address, for example, (013) we read this as rtthe contents of location a 13 II • EX 7-1 When we use the notation (000) :' (013) we mean that a copy of the number in location a13 is to be made and this value becomes the contents of location 000. Notice that this kind of statement is read from right to left. We will al so use statements like the following (000) : (000) + (0 13) It says, ([Add the contents of location a13 to the contents of location 000 and then put the answer in location 000 II. This statement I of course I describes our Add instruction above. Since the Add instruction can use any location in memory for the number to add to the number in location 000 I we could express the state- ment as (000) : (000) XXX = 000, 001, ....•.• ,377 + (XXX), The statement on the far right merely says XXX can be any of the memory addresses. Usually we will omit it. It s just understood that it is so. l The single number 000 is an instruction to the computer telling it to stop or halt. We call this an instruction "HaItH. Halt is an instruction in the computer and the program tells the computer to halt. We III use the name Ii Stop If for the action of telling the computer I from the front panel, to stop. It does not require any instruction. Both Halt and Stop produce the same result. When the computer is halted or stopped, it isn It doing anything. The Run light is out and we can store and read memory locations. When the Run light is on, the computer is doing the steps of a program in the computer. We can It read and store data using the front panel then. EX 7-2 A computer can do only one instruction at a time. After doing one, it will do another, followed by another, and so on. How does the computer know where to begin? And how does it know where the next instruction is? TH·E NUMB·ER IN LOCATION 003 T·ELLS THE COMPUTER WHICH MEMORY LOCATION HOLDS THE NEXT INSTRUCTION. After a11 Add instruction, the number in location 003 is increased by 2 since the Add instruction is contained in two locations in the memory. After a Halt instruction, the number in location 003 is increased by 1 since the Halt instruction use·s only one location in the memory. This adjustment to the value of the number in location 003 is done by the computer automatically. We could express this symbolically I for ADD, (003) (003) + 2 for HALT I (003) (003) + 1 WARNING A common mistake that students make is to say that the number in location 003 is the next instruction. This is not correct. number in location 003 is the address of the next instruction. big difference between these two statements. The There is a Be sure you understand the difference. Let S try the Add and the Halt instructions in the computer. I Load the data in the Before column. Location Before 000 250 003 100 100 101 102 004 164 000 164 005 Push Start. The Run light should go out. Comments ADD HALT (000) ~003) 003) (000) + (164) (003) + 2 (003) -}- 1 Read the memory locations and fill in the blanks in the After column above. EX 7-3 Did the contents of location 000 change? - - - - - - - - - By how much did they change? What location holds this number? -------------Did the contents of location 164 change? Did the contents of location 003 change? - - - - - - - - What do the contents of location 003 now tell the computer? Did (100) or (101) or (102) change? Now here is a problem for you to progranl. Write a four instruction program to add together the numbers in location 30 I, in 302 You can choose your own numbers to put in these locations. I and in 303. Pick small numbers. Welve written out a few of the locations and data for you. Try your program in the computer. When the computer stops, you III ha ve to read the contents of location 000 to get your answer. Location 000 Comments 000 Start with zero in location 000 003 100 101 102 103 104 105 106 Put first instruction here 301 302 303 First number Second number Third number HALT Try a different set of numbers in 30 I, 302 I and 303. Don1t forget to put the proper starting values in locations 000 and 003. EX 7-4 Exercise 8 Weill learn some more instructions in this Exercise. This pair of numbers .-WOUld tell the computer: r - - - - - - - - 014 I I 237 - - - - - - - - - - - - -., I A COpy OF THE NUMBER IN LOCATION 237 FROM THE CONTENTS OF LOCATION 000 AND PUT THE ANSWER IN LOCATION 000 We can also give the results produced by this instruction in this way I (000) (000) - (003) (003) + 2 (XXX) SUBTRACT Operation code is 014 And this pair of numbers T r - - - - - - - -024 would tell the computer: 133 - - I - - - - - - - - - - -. I I A COpy OF THE NUMBER IN LOCATION 133 INTO LOCATION 000 LOAD is a transfer of data to location 000 from another location. is not changed in any way. The data Our shorthand notation for Load is I (000) (XXX) (003) (003) + 2 LOAD Operation code is 024 EX 8-1 The pair of numbers -rwould tell the computer: r------ 034 321 - - - - - - - - - - - -, I I I I I I A COPY OF THE NUMBER IN INTO LOCATION 321 LOCATION 000 STORE is a transfer of data fr