archive-edu.com » EDU » H » HWS.EDU

Total: 727

Choose link from "Titles, links and description words view":

Or switch to "Titles and links view".
  • CS100 Spring 1997: Quiz #6
    to a global variable which is declared outside of any subroutine A local variable is part of the black box It represents a quantity that is needed only on the inside of the subroutine so there is no need for the rest of the program to know about it In fact a local variable is completely invisible to the rest of the program Local variables exist to help make subroutines more independent of the rest of the program You don t have to worry about whether a variable you want to use in the subroutine has the same name as a global variable for example Question 3 Explain what is meant by the maintenance stage of the software life cycle and explain why maintenance is easier if the program is made up of modules Answer Maintenance is the last stage of the software life cycle in which a program is adapted to changing conditions and new requirements and in which any newly discovered errors are fixed Maintenance can continue over a period of many years Often it costs much more to maintain a program than it did to write it in the first place so it is important for a program to be written in a way that will make maintenance as easy as possible Writing modular programs is one way to do this A module is a component of a larger system that is relatively independent and which interacts with other parts of the system only in well defined easy to understand ways If a program is constructed from modules it will be possible to make changes in one module without affecting the rest of the program Question 4 The subroutine Tri size given below draws a triangle whose side is size units long It leaves the turtle back

    Original URL path: http://math.hws.edu/TMCM/s97/quiz6.html (2016-02-07)
    Open archived version from archive


  • CS100 Spring 1997: Quiz #7
    then draws a bent line radiating out from the origin This line consists of two segments with an angle of 45 degrees between them Here is the picture Question 2 Define the term protocol as it relates to computer networks and give an example of a commonly used protocol Answer A protocol is a specification of how communication is to occur For two computers to communicate they must both be using the same protocol so that each computer can correctly interpret the bits transmitted by the other computer Some commonly used protocols for computer networking include IP TCP FTP Telnet and HTTP Since networks use layered protocols a given communication can involve several different protocols For example FTP is used to transmit files between computers To do this FTP calls upon TCP which is responsible for reliably transmitting a block of data TCP in turn uses IP which knows how to route a packet of bits from one computer to another across a complicated internet Essentially you use FTP as a black box FTP uses TCP as a black box and TCP uses IP as a black box This layering of protocols is a good example of structured complexity Question 3 Define the term critical region as it relates to programs that use parallel processing Answer A critical region is a segment of a program where a process needs exclusive access to a shared variable In the xTurtle language exclusive access can be implemented by using the grab statement Question 4 What is the basic difference between painting and drawing programs Answer In a painting program the user creates an image by coloring pixels The only data that the computer remembers is the color of each pixel The computer does not know about objects in the scene and therefore it

    Original URL path: http://math.hws.edu/TMCM/s97/quiz7.html (2016-02-07)
    Open archived version from archive

  • Index of /TMCM/java/source
    README txt 2004 06 25 13 34 2 6K compile bat 2004 06 25 13 34 2 9K compile sh 2004 06 25 13 34 2 5K manifest files 2004 06 25 14 21 tmcm 2004 06 25 14 21

    Original URL path: http://math.hws.edu/TMCM/java/source/ (2016-02-07)
    Open archived version from archive

  • Introductory Lab
    uses a type of interaction known as a form or fill in form You enter some data in the form and click on a submit button Your Web browser sends your data to another computer which responds to your data by sending a new page for your Web browser to display Web pages can also provide other types of interactivity without involving a second computer One of the new technologies on the Web is Java a programming language that can be used to write applets which are small programs that run on a Web page Many Java applets are more decorative than useful like this Moiré applet Sorry your browser doesn t do Java A Moiré pattern is formed by the interference between two similar patterns In this applet the basic pattern consists of lines radiating out from a command center There are two copies of this pattern One is fixed while the other drifts about Even this decorative applet allows some interaction If you click and drag your mouse on the Moiré applet you can control the motion of the pattern To click and drag means to press the mouse button and then move the mouse while holding down the button If you shift click on the applet you can stop and restart its motion To shift click means to hold down the shift key while you click the mouse button If you are using a slow computer you might want to turn off the Moiré applet so that it doesn t take computer processing time away from other things going on on this page Each of the labs for The Most Complex Machine uses an applet to help you learn something about computer science In order to make it more convenient to use the applets and read the labs at the same time the applets are set up to run in separate windows The lab worksheet contains a button that you can click to launch the applet In most of the labs this button is close to the beginning of the lab where it will be easy to find The button is itself a small applet that runs on the Web page In this lab you will use a fairly simple applet called DataReps You will use this applet to learn how the same binary number can be used to represent different types of data To launch the applet click on this button Sorry your browser doesn t do Java The window that opens when you click this button will probably be marked with some kind of warning to alert you to the fact that the window was created by an applet For example on my computer there is a warning bar like this one along the bottom of windows opened by applets Why the warning A Java applet is a program that you have downloaded from the Internet Whenever you download a program there is a danger that the program is malicious that it will try to damage your computer or steal information from you A great deal of attention has been paid to making Java applets secure that is to making sure that they can t damage your computer or access private information stored on your computer However nothing can stop you from entering private information such as a password into an applet The warning on applet windows is there to stop malicious applets from tricking you into entering such information For example without the warning the applet might imitate a window from a program that has a legitimate need for the information Data Representations You ll be using the DataReps applet which you launched above in some of the exercises at the end of the lab For now you should read about it and experiment with it to see what it does This applet lets you type in a data value You can select the type of data you want to enter by clicking on one of the five radio buttons Just type your data into the input box at the top of the applet and press return You can also click on the 8 by 4 grid of big pixels at the center of the applet The applet takes the data you enter and it converts that data into a 32 bit binary number It has to do this in order to store it It then takes that same binary number and interprets it in six different ways The six interpretations are a binary number an integer a hexadecimal number a real number a string of four characters and an eight by four grid of pixels You should remember that you see the same string of thirty two bits interpreted in different ways You should also remember that the same bit patterns could also be interpreted in an endless variety of additional ways as a bar of music or the chemical ingredients in a bar of soap or your tab at your favorite bar or Here is a short explanation of each of the six data displays You should try entering various types of values in the applet to see how they are represented as binary numbers Binary This is the most direct display of the 32 bit binary number showing a zero or one to represent each individual bit The displayed binary number shows the full 32 bits including any leading zeros The computer stores the zeros even though you don t ordinarily include leading zeros when you write a number Base ten Integer A binary number can be interpreted as a normal positive integer 0 1 2 3 4 written in the base ten Base ten is the usual way of writing numbers using the digits 0 through 9 See Section 1 1 of The Most Complex Machine With 32 bits you can represent 2 32 different numbers Usually you want to use both positive and negative numbers The scheme for representing negative numbers is a bit strange It is explained in

    Original URL path: http://math.hws.edu/TMCM/java/labs/DataRepsLab.html (2016-02-07)
    Open archived version from archive

  • xLogicCircuits Lab 1
    get the wire connected to the right one Circuit Inputs are valid sources for wires So are Tacks So are the outputs of gates Valid destinations include circuit Outputs inputs of gates and Tacks You can draw as many wires as you want from a source but you can only draw one wire to a destination This makes sense because when the circuit is running a destination takes its value from the single wire that leads to it On the other hand the value of a source can be sent to any number of wires that lead from it Once a component is on the board you can still move it to a new position but you have to drag it using the right mouse button Alternatively if you have a one button mouse for example you can drag a component by holding down the control key as you first press the mouse button on it You can delete components and wires that you ve added by mistake Just click on the component or wire to hilite it Then click on the Delete button at the bottom of the applet The hilited item will be deleted from the circuit board If you delete a component that has wires attached the attached wires will also be deleted along with the component If you delete an item or modify the circuit in some other way you get one chance to change your mind You can click on the Undo button to undo one operation Only the most recent operation can be undone in this way There is one shortcut that you might find useful if you like using Tacks You can insert a Tack into an existing wire by double clicking on the wire If you double click and hold the mouse down on the second click you can drag the tack to a different position However some browsers might not support double clicks After you build the practice circuit you can clear the screen since you won t need that circuit again in the rest of the lab However you ll get more practice building circuits in the Exercises at the end of the lab Complex Circuits and Subcircuits In order to have circuits that display structured complexity it is important to be able to build on previous work when designing new circuits Once a circuit has been designed and saved it should be possible to use that circuit as a component in a more complex circuit A lot of the power of xLogicCircuits comes from the ability to use circuits as components in other circuits Circuits used in this way are called subcircuits A circuit that has been saved as an icon in the pallette can simply be dragged into another circuit More exactly a copy of the circuit is created and is added to the circuit board The copy is a separate circuit editing the original will not change the copy This ability to build on previous work is essential for creating complex circuits You can open a circuit from the pallette to see what s inside or to edit it Just click on the icon to hilite it and then click on the Enlarge button The icon will be removed from the pallette and the circuit will appear on the circuit board At the same time any circuit that was previously on the circuit board will be iconified and placed on the pallette You should also be able to enlarge a circuit just by double clicking on it By the way you can change the name of the circuit on the circuit board by editing the text input box at the top of the applet This box contains the name that appears on the iconified circuit The xLogicCircuits applet should have loaded several subcircuits for the pallette One of these circuits is called Two or More Open this circut now The circuit has three inputs It turns its output ON whenever at least two of its inputs are ON Try it Click on the inputs to turn them ON and OFF and don t forget to turn the Power on first As a simple exercise in building circuits from subcircuits use the Two or More circuit as part of a At Most One circuit You want to build a circuit with three inputs that will turn on its output whenever zero or one of its inputs is on Notice that this is just the opposite behavior from the Two or More circuit That is At Most One is ON whenever Two or More is not ON This logical description shows that the At Most One circuit can be built from a NOT gate and a copy of the Two or More circuit Begin by re Iconifying the Two or More circuit then drag a NOT gate and a copy of Two or More onto the empty circuit board Add Inputs Outputs and wires as appropriate then test your circuit to make sure that it works If you like you can give it a name and turn it into an icon Next open the 4 Bit Adder sample circuit You ll see that it contains several copies of a subcircuit called Adder It s possible to look inside one of these circuits Just click on the adder circuit to hilite it and then click the Enlarge button This does not remove the main circuit from the board it just lets you see an enlarged part of it When you shrink the subcircuit back down to its original size the main circuit is still there In this case you ll see that an Adder circuit contains two Half Adder subcircuits which you can enlarge in their turn if you want Circuits and Arithmetic The 4 Bit Adder circuit is an example of a logic circuit that can work with binary numbers Circuits can work with binary numbers as soon as you think of ON as representing the binary value 1

    Original URL path: http://math.hws.edu/TMCM/java/labs/xLogicCircuitsLab1.html (2016-02-07)
    Open archived version from archive

  • xLogicCircuits Lab 2
    to make sure that you know how to use it Registers With the basic one bit memory as a starting point you can build more complex memory circuits Just as you can line up several Adder circuits to get a multibit addition circuit you can combine several one bit memory circuits to get a multibit memory circuit As one of the exercises at the end of the lab you will construct a 4 bit memory circuit A 4 bit memory circuit can store a 4 bit binary number Similarly you can build memory circuits to store 8 bit binary numbers 16 bit numbers or any number of bits Memory circuits of this type are important components in the central processing unit of a computer A memory circuit that is used in the central processing unit to store a binary number is called a register Multibit memory circuits can also be used in the main memory of a computer Recall that main memory contains a sequence of numbered locations Each location stores a binary number so each location can be a simple multibit memory circuit For some purposes a more sophisticated type of multibit memory is needed As an example look at the Count Reg circuit which you will find in the pallette of the xLogicCircuits applet This circuit is a register that counts in binary Turn its control wire on and off several times allowing as always enough time for the circuit to respond As you keep turning the control wire ON and OFF the three outputs of the circuit will cycle through the values 000 001 010 011 100 101 110 111 and back to 000 Read the outputs from bottom to top If you convert these binary numbers to decimal numbers the circuit is counting from zero to seven A count register of this sort could be used in a CPU to count off the steps in a computation for example The count register is made from three Flip Flop circuits It is not important for you to understand how a flip flop works but if you look inside you ll see that it is made from two interconnected one bit memories of the type you have seen above In fact a flip flop is itself a kind one bit memory but it can do things that the simpler one bit memory cannot such as count The count register is used in one of the exercises at the end of the lab but mainly it is here to show you that registers can be made to do more than just store numbers Random Access Memory A random access memory or RAM is a memory circuit that can hold several different binary numbers Each binary number is stored in a separate location The locations are numbered 0 1 2 3 and so on The number of a location is called its address Every computer has a RAM which it uses as a main memory where it stores the data and programs that it is working with A RAM can have any given number of locations In a typical computer the RAM has several million locations The binary numbers that are stored in a RAM can have any given number of bits In a typical modern computer each location holds an eight bit binary number In this section you ll see how a very simple RAM can be constructed The RAM you will look at has only two locations and each location holds just a single bit The exercises at the end of the lab will investigate how larger and more useful RAM s can be built The sample RAM is named 2 Bit RAM It is one of the sample circuits loaded by the xLogicCircuits applet Find it in the applet s pallette and open it You ll see a circuit with one data input two control inputs and one output The ADDRESS wire picks out one of the two locations in the RAM When the ADDRESS wire is OFF one location is used the location with address zero When the ADDRESS wire is ON the other location is used the location with address one The DATA OUT wire shows the contents of the selected location Turning the LOAD DATA wire on and off stores a value in the selected location The DATA IN wire specifies the value that is to be stored For example suppose you want to store a 1 in location 0 Then you should Turn the DATA IN wire ON representing the value 1 Turn the ADDRESS wire OFF representing the address of location 0 Turn the LOAD DATA wire ON Wait long enough for the signals to propagate through the circuit Turn the LOAD DATA wire OFF To read the value stored in location 0 all you have to do is turn the ADDRESS wire OFF to represent the address of the location you want to read The value stored in location 0 will appear on the DATA OUT wire If you want to work with location 1 instead of with location 0 all you have to do is turn the ADDRESS wire ON A real RAM should have more than one ADDRESS wire Every combination of values that can be put on the ADDRESS wires specifies a different address For example if there are three address wires they can be set to any of the eight combinations OFF OFF OFF OFF OFF ON OFF ON OFF OFF ON ON ON OFF OFF ON OFF ON ON ON OFF and ON ON ON These combinations represent the binary numbers 000 001 010 011 100 101 110 and 111 In ordinary decimal notation they represent 0 1 2 3 4 5 6 and 7 So a RAM with three ADDRESS wires can have eight locations numbered 0 through 7 Twenty ADDRESS wires are enough to specify over a million locations and thirty ADDRESS wires can specify over a billion You should spend some time understanding

    Original URL path: http://math.hws.edu/TMCM/java/labs/xLogicCircuitsLab2.html (2016-02-07)
    Open archived version from archive

  • xComputer Lab 1
    They are not covered in this lab but they will be an important part of the next lab If you want to type a new program just click on the New Program button in the Control area of the applet Alternatively you can select New from the pop up menu at the very top of the applet The computer display will disappear and will be replaced by a text input area when you can type your program Enter the following program into that text area lod c 1 sto 12 lod 12 inc sto 12 jmp 2 This program counts It starts by putting the number 1 into memory location 12 and then it adds one to the number in that location over and over forever You ll see this in action in a moment There are several new instructions here Lod 12 tells xComputer to copy the number from memory location 12 into the accumulator Note how this differs from lod c 12 which puts the number 12 itself into the AC rather than the number stored in memory location 12 The inc instruction adds one to the value in the accumulator And jmp 2 is a jump instruction that sends the computer back to location 2 After typing this program click on the Translate button that is located below the text area on the left end of a row of buttons If the program contains some error an error message will be displayed If you ve typed the program correctly it will be translated into machine language and stored in the xComputer s memory The text area will be replaced by the computer display and the computer will be ready to run the program Click on the Run button to run the program and see how it operates You can watch as the PC counts off the instructions in the program You will see the assembly language instructions themselves as they are loaded into the IR And you can observe that the value in memory location 12 changes from 1 to 2 to 3 to 4 and so on This program will run forever if you let it You will be working with this little program throughout most of the remainder of the lab Your objective is to understand how xComputer operates and to appreciate the fetch and execute cycle Controlling Speed and Memory Display Style As you let the counting program run you can try varying the speed at which the computer executes instructions by changing the setting on the speed pop up menu located just below the Run button The lower speeds allow you to watch what is happening in more detail The higher speeds allow the computer to get more done At the very highest speed the registers are not displayed so that the computer can run as quickly as possible without updating the register display all the time When you have had enough of this stop the program and experiment with the memory display style pop up menu which is located just above the scrolling memory display This menu allows you to select how you would like to view the contents of main memory There is also a similar pop up menu for setting the register display style Of course the actual contents of memory are binary numbers but a binary number can mean many things depending on how it is interpreted When the applet first starts up it is set to display the contents of memory as ordinary decimal integers in the range 32768 to 32767 This is only one possible interpretation of the binary numbers that are stored in memory Using the display style pop up menu you can select from six different interpretations The Instructions display shows the contents of each memory location as an assembly language instruction In this display style you should see the original counting program in memory locations 0 through 5 Most of the other locations contain Add 0 which just happens to be the assembly language instruction encoded by the 16 bit binary number 0000000000000000 Since not every 16 bit binary number corresponds to a legitimate assembly language instruction you might see some funny things in this display style The Integers and Unsigned Ints displays show ordinary decimal integers The difference is that signed 16 bit integers are in the range 32768 to 32767 while unsigned 16 bit integers are in the range 0 to 65535 In either case there are 2 16 different possible values it s just a question of how they are interpreted See Subsection 2 2 3 in the text The Binary display shows a 16 bit binary number in each memory location this display style is closest to the actual physical contents of the memory The ASCII display interprets each sixteen bit number in memory as made up of two eight bit ASCII character codes and shows the two characters Some eight bit binary numbers do not represent visible ASCII characters These numbers are shown in the form N where N is the number in decimal form Thus for example the 16 bit binary number 0000000000000000 is shown in ASCII display style as 0 0 The Graphics display is very different from the others It shows the entire memory at once Each bit in memory all 16 times 1024 of them is represented by one pixel on the screen That pixel is white if the bit is zero and is black if the bit is one If you choose the Graphics display now the memory will be almost entirely white except for a few black dots at the top that represent the program you entered into memory You can try out the various memory display styles You ll be using them in Exercise 1 at the end of the lab I should note that when you enter information into Memory using the data input box in the Control area of the applet you can type the information in several of the

    Original URL path: http://math.hws.edu/TMCM/java/labs/xComputerLab1.html (2016-02-07)
    Open archived version from archive

  • xComputer Lab 2
    sample program ThreeNPlusOne txt computes a 3N 1 sequence This is a problem that you will see several times in these labs Given a positive integer N the program applies the rule If N is even then replace N by N 2 if N is odd then replace it by 3N 1 It applies this rule over and over until the number N becomes equal to 1 For example if the starting value of N is 7 then the program generates the sequence of values 7 22 11 34 17 52 26 13 and so on Run the ThreeNPlusOne txt program To see the numbers as they are generated watch memory location number 17 which contains the successive values of N starting with 7 You will probably want to bump the speed up to Fast You can run the program again with any other starting value of N Modify the value of N in the assembly language program and then reload it into memory with the Translate button You could also change the number in location 17 directly and then run the program If you do this don t forget to click the Set PC 0 button to reset the Program Counter to zero You should also read the program and note how it uses the five labels NextN Odd Even Done and N The label Odd is defined but is never referred to in the program It is really just there for human readers Another sample program MultiplyByAdding txt adds two numbers by adding one of the numbers to itself over and over The program is set up to multiply 13 by 7 Read the program and try it out Use it to multiply some other pairs of numbers Make sure that you understand these programs and the general ideas of loops and decisions You will need to understand them to complete the exercises at the end of the lab Indirect Addressing The next sample program is ListSum txt This program illustrates a common type of processing where the computer processes a sequence of consecutive locations in memory In ListSum txt the computer adds up the numbers stored in consecutive locations It stops when it gets to a location that contains a zero In the exercises you will write two programs based on this one Before doing those exercises you should read the sample program run it and try to understand how it works The ListSum txt program uses indirect addressing to access numbers in the list Indirect addressing is used in several assembly language instructions including LOD I STO I ADD I and SUB I Recall that LOD C XXX tells the computer to load the number XXX into the accumulator LOD XXX on the other hand tells the computer to copy the contents of memory location XXX into the accumulator This is known as direct addressing In the LOD I XXX instruction XXX is the address of a memory location but not of the memory location containing the data Instead memory location XXX contains another address and that address specifies the location whose contents are to be loaded into the accumulator For example if location 17 contains the number 42 then LOD I 17 will load the contents of memory location 42 into the accumulator Admittedly this is confusing but it turns out to be just what we need to do list processing In fact in that context its not all that confusing after all Consider the following program outline Set up LOD ListStart Load Loc with the starting location of the list STO Loc Loop LOD I Loc Process the number LOD Loc Add 1 to Loc INC STO Loc JMP Loop Return to the start of the loop Loc data Location of next number to be processed ListStart 183 List of data to be processed 72 902 164 The first time LOD I Loc is executed it loads 183 the first number in the list into the accumulator since the value of Loc is ListStart After processing the 183 the program adds 1 to the number in Loc and jumps back to the start of the loop The value stored in Loc is now the address of the second number in the list 72 So now when LOD I Loc is executed it loads 72 into the accumulator The next time through the loop it will load 902 then 164 and so on So each time through the loop a different location is processed even though the instructions in the loop don t change Loc is said to be a pointer since the value stored in Loc is not really the number we are interested in Instead the value in Loc indicates where to go to find the number we want It points to that value Pointers and indirect addressing are used in various ways even in high level languages In the next lab you ll see how useful indirect addressing can be in a jump instruction Dancing Bits There is another sample program that I ve provided mostly for your amusement but also because watching it run might just give you a better appreciation of what a computer is really doing as it computes Select the sample program PowersOfThree txt from the pop up menu in the xComputer Window Read the comments at the beginning of the file and then load the program into xComputer s memory by clicking on the Translate button Set the display style to Graphics and the run speed to Fastest and run the program You will see the bits in xComputer s memory dance as a non trivial computation is performed Exercises Exercise 1 The sample program SimpleCounter txt is a copy of the program that counts forever which was discussed earlier in this lab Modify this program so that it counts to 16 and then halts This was also an exercise in the previous lab except that in that lab you didn t use labels Add a HLT

    Original URL path: http://math.hws.edu/TMCM/java/labs/xComputerLab2.html (2016-02-07)
    Open archived version from archive