Difference between revisions of "CSC103: DT's Notes 1"

From dftwiki3
Jump to: navigation, search
Line 1,271: Line 1,271:
 
|-
 
|-
 
|style="width: 25%; background-color: white;"|
 
|style="width: 25%; background-color: white;"|
 +
 
  @0
 
  @0
 +
 
|
 
|
 
This line instructs the translator or ''compiler'' that will take this program and generate a list of instructions in memory that it should store the next instructions at '''Address 0'''.  Programs always start at 0.
 
This line instructs the translator or ''compiler'' that will take this program and generate a list of instructions in memory that it should store the next instructions at '''Address 0'''.  Programs always start at 0.
 
|-
 
|-
 
|
 
|
 +
 
  LOD  10
 
  LOD  10
 +
 
|
 
|
 
Load the variable at Address 10 into the AC register.  Whatever AC's original value, after this instruction it will contain whatever is stored at Address 10.  We'll see in a few moments that the number is 2.  So AC will contain 2.
 
Load the variable at Address 10 into the AC register.  Whatever AC's original value, after this instruction it will contain whatever is stored at Address 10.  We'll see in a few moments that the number is 2.  So AC will contain 2.
 
|-
 
|-
 
|
 
|
 +
 
  ADD  11
 
  ADD  11
 +
 
|
 
|
 
Get the variable at Address 11 and add the number found to the number in the AC register.  The AC register's value becomes
 
Get the variable at Address 11 and add the number found to the number in the AC register.  The AC register's value becomes
Line 1,287: Line 1,293:
 
|-
 
|-
 
|
 
|
 +
 
  STO  12
 
  STO  12
 +
 
|
 
|
 
Store the contents of the AC at Address 12.  Since AC contains 5, the number is copied in the variable at Address 12.
 
Store the contents of the AC at Address 12.  Since AC contains 5, the number is copied in the variable at Address 12.
 
|-
 
|-
 
|
 
|
 +
 
  HLT
 
  HLT
 +
 
|
 
|
 
&nbsp;<br />
 
&nbsp;<br />
Line 1,299: Line 1,309:
 
|-
 
|-
 
|
 
|
 +
 
  &nbsp;  
 
  &nbsp;  
 +
 
|
 
|
 
&nbsp;<br />
 
&nbsp;<br />
Line 1,306: Line 1,318:
 
|-
 
|-
 
|
 
|
 +
 
  @10
 
  @10
 +
 
|
 
|
 
We now indicate to the translator that the next information should be stored starting at a new address, in this case Address 10.
 
We now indicate to the translator that the next information should be stored starting at a new address, in this case Address 10.
 
|-
 
|-
 
|
 
|
 +
 
  3
 
  3
 +
 +
 
|
 
|
 
&nbsp;<br />
 
&nbsp;<br />
Line 1,319: Line 1,336:
 
|-
 
|-
 
|
 
|
 +
 
  5
 
  5
 +
 
|
 
|
 
The number 5 should be stored at memory Address 11.  Why 11?  Because the previous variable was at Address 10.  
 
The number 5 should be stored at memory Address 11.  Why 11?  Because the previous variable was at Address 10.  
 
|-
 
|-
 
|
 
|
 +
 
  0
 
  0
 +
 
|
 
|
 
This 0 represents the third variable that will hold the sum of the first two variables.  We store 0 because we want to have
 
This 0 represents the third variable that will hold the sum of the first two variables.  We store 0 because we want to have
Line 1,332: Line 1,353:
 
|}
 
|}
  
<center>[[Image:CSC103FirstAssemblyProgSimul1.jpg|400px]]</center>
+
<center>[[Image:CSC103FirstAssemblyProgSimul1.jpg|600px]]</center>
<center>[[Image:CSC103FirstAssemblyProgSimul2.jpg|400px]]</center>
+
 
<center>[[Image:CSC103FirstAssemblyProgSimul3.jpg|400px]]</center>
+
The figure above shows the program entered in the ''Program Window'' of the simulator.  It is entered simply by typing
<center>[[Image:CSC103FirstAssemblyProgSimul4.jpg|400px]]</center>
+
the information in the window as one would write a paper, or letter.  Programs are texts.  They are written using a particular
<center>[[Image:CSC103FirstAssemblyProgSimul5.jpg|400px]]</center>
+
coding system (in our case assembly language), and a ''translator'' must be invoked to transform the text into numbers.
 +
 
 +
 
 +
<center>[[Image:CSC103FirstAssemblyProgSimul2.jpg|600px]]</center>
 +
 
 +
The figure above shows the result of pressing the '''Translate''' button.  The translator takes the program, transforms each line into a number, and stores the numbers at different addresses in memory.  You should recognize 3 numbers at Addresses
 +
10, 11, and 12.  Yes?
 +
 
 +
 
 +
<center>[[Image:CSC103FirstAssemblyProgSimul3.jpg|600px]]</center>
 +
 
 +
The figure above shows the same information as displayed in the previous image, but this time we have asked the simulator
 +
to show the contents of memory as instructions.  The simulator looks at each number in the memory and simply does a reverse translation.  The problem for us is that the simulator does not understand our logic.  It doesn't know that we divided our program into two separate parts: the instructions and the data, and that they are at different memory location.  If we ask
 +
the simulator to display the contents of memory as instructions, it does so, and not only reverse-decodes the instructions correctly into LOD, ADD, STO, and HLT, but it takes all the other numbers and figures out what instructions would
 +
correspond to these numbers, even though our program doesn't have more instructions.  So 3 becomes '''ADD 3''',
 +
5 becomes '''Add 5''' and 0 becomes '''Add 0'''. 
 +
 
 +
<center>[[Image:CSC103FirstAssemblyProgSimul4.jpg|600px]]</center>
 +
<center>[[Image:CSC103FirstAssemblyProgSimul5.jpg|600px]]</center>
  
  

Revision as of 20:10, 28 September 2013

--© D. Thiebaut 08:10, 30 January 2012 (EST)



This section is only visible to computers located at Smith College













.