Difference between revisions of "CSC231 Class Page 2015"
(→ ) |
(→ ) |
||
(115 intermediate revisions by the same user not shown) | |||
Line 17: | Line 17: | ||
|} | |} | ||
<br /> | <br /> | ||
− | ::{| class="mw-collapsible | + | ::{| class="mw-collapsible " style="width:100%" border="1" |
|- style="background:#dddddd;" | |- style="background:#dddddd;" | ||
|width="60%"| '''Topics''': Introduction, Python, Idle, Piazza, Moodle submission | |width="60%"| '''Topics''': Introduction, Python, Idle, Piazza, Moodle submission | ||
Line 60: | Line 60: | ||
|} | |} | ||
<br /> | <br /> | ||
− | ::{| class="mw-collapsible | + | ::{| class="mw-collapsible " style="width:100%" border="1" |
|- style="background:#dddddd;" | |- style="background:#dddddd;" | ||
|width="60%"| '''Topics''': Processor and Memory, working with the shell, and emacs. | |width="60%"| '''Topics''': Processor and Memory, working with the shell, and emacs. | ||
Line 111: | Line 111: | ||
|} | |} | ||
<br /> | <br /> | ||
− | ::{| class="mw-collapsible | + | ::{| class="mw-collapsible " style="width:100%" border="1" |
|- style="background:#dddddd;" | |- style="background:#dddddd;" | ||
|width="60%"| '''Topics''': Number Systems, the MOV instruction | |width="60%"| '''Topics''': Number Systems, the MOV instruction | ||
Line 173: | Line 173: | ||
| | | | ||
* [[CSC231 Lab 2 2015 | Lab #2]] | * [[CSC231 Lab 2 2015 | Lab #2]] | ||
− | * [[CSC231 Homework 2 2015 | Homework #2]] | + | * [[CSC231 Homework 2 2015 | Homework #2]] and [[CSC231 Homework 2 2015 | Solution programs (at end of page)]] |
| | | | ||
* Finish the reading assigned for Week 1. | * Finish the reading assigned for Week 1. | ||
Line 191: | Line 191: | ||
|} | |} | ||
<br /> | <br /> | ||
− | ::{| class="mw-collapsible" style="width:100%" border="1" | + | ::{| class="mw-collapsible " style="width:100%" border="1" |
|- style="background:#dddddd;" | |- style="background:#dddddd;" | ||
|width="60%"| '''Topics''': The Mov instruction. Arithmetic instructions. Addressing Modes. | |width="60%"| '''Topics''': The Mov instruction. Arithmetic instructions. Addressing Modes. | ||
Line 208: | Line 208: | ||
:* The '''ADD''' instruction | :* The '''ADD''' instruction | ||
:* [[CSC231 Simple String Encryption | Overly-simplified encryption of a string]] | :* [[CSC231 Simple String Encryption | Overly-simplified encryption of a string]] | ||
− | |||
| | | | ||
* [[CSC231 nasmld script | Mini Lab 3]] | * [[CSC231 nasmld script | Mini Lab 3]] | ||
− | * [[CSC231 Homework 3 2015 | Homework 3]] | + | * [[CSC231 Homework 3 2015 | Homework 3]] and [[CSC231 Homework 3 2015 | Solutions (at end of page)]] |
| | | | ||
* [http://cs.smith.edu/~dthiebaut/ArtOfAssembly/CH03/CH03-1.html Chapter 3, Section 1 in ''The Art of Assembly''], to Section 3.2.2. | * [http://cs.smith.edu/~dthiebaut/ArtOfAssembly/CH03/CH03-1.html Chapter 3, Section 1 in ''The Art of Assembly''], to Section 3.2.2. | ||
Line 229: | Line 228: | ||
|} | |} | ||
<br /> | <br /> | ||
− | ::{| class="mw-collapsible" style="width:100%" border="1" | + | ::{| class="mw-collapsible " style="width:100%" border="1" |
|- style="background:#dddddd;" | |- style="background:#dddddd;" | ||
|width="60%"| '''Topics''': | |width="60%"| '''Topics''': | ||
Line 240: | Line 239: | ||
[[File:MultiCore.jpg|150px|right]] | [[File:MultiCore.jpg|150px|right]] | ||
:* Arithmetic instructions: '''ADD''', '''SUB''', '''INC''', '''DEC'''. Skip '''MUL''' and '''DIV''' for right now. | :* Arithmetic instructions: '''ADD''', '''SUB''', '''INC''', '''DEC'''. Skip '''MUL''' and '''DIV''' for right now. | ||
− | :* A quick introduction to calling functions: ''' | + | :* A quick introduction to calling functions: '''CALL''' and '''RET''' |
:* [[CSC231 Printing Decimal Numbers in Assembly | Printing decimal numbers]] in assembly | :* [[CSC231 Printing Decimal Numbers in Assembly | Printing decimal numbers]] in assembly | ||
:* A first look at what is behind code like this: | :* A first look at what is behind code like this: | ||
Line 252: | Line 251: | ||
c = a + b; | c = a + b; | ||
</source> | </source> | ||
− | :* "Compile" the following statements to assembly: | + | |
+ | :* [[Assembly generated by GCC| Example of what the GNU cc compiler would have generated]] | ||
+ | :* '''Exercise 1''': "Compile" the following statements to assembly: | ||
::::<source lang="java"> | ::::<source lang="java"> | ||
int a; | int a; | ||
Line 264: | Line 265: | ||
d = (a + b + 10 + 2*c ) * 2 - 20; | d = (a + b + 10 + 2*c ) * 2 - 20; | ||
</source> | </source> | ||
− | :* | + | :* '''Exercise 2''': translate the following code in assembly. If you need to refresh your memory on Java types, check [https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html this document] out: |
− | |||
::::<source lang="java"> | ::::<source lang="java"> | ||
int a = 3, b = 5, c; | int a = 3, b = 5, c; | ||
Line 279: | Line 279: | ||
| | | | ||
<!-- * Lab --> | <!-- * Lab --> | ||
− | |||
| | | | ||
− | * [http://en.wikipedia.org/wiki/Endianness#Endianness_and_hardware Big Endian vs. Little Endian] hardware. Why does it matter? | + | * [http://en.wikipedia.org/wiki/Endianness#Endianness_and_hardware Big Endian vs. Little Endian] hardware. Why does it matter? |
+ | * [[Big Endian and Little Endian Machines| page with some little-endian and big-endian architectures]]. | ||
* Section 4.1 of Paul Carter's ebook presents indirect addressing. Read this first. Read also Section 5.1.3 about more sophisticated indirect addressing modes. | * Section 4.1 of Paul Carter's ebook presents indirect addressing. Read this first. Read also Section 5.1.3 about more sophisticated indirect addressing modes. | ||
* [http://cs.smith.edu/~thiebaut/ArtOfAssembly/CH06/CH06-5.html#HEADING5-98 The CALL and RET instructions] | * [http://cs.smith.edu/~thiebaut/ArtOfAssembly/CH06/CH06-5.html#HEADING5-98 The CALL and RET instructions] | ||
Line 298: | Line 298: | ||
|} | |} | ||
<br /> | <br /> | ||
− | ::{| class="mw-collapsible | + | ::{| class="mw-collapsible " style="width:100%" border="1" |
|- style="background:#dddddd;" | |- style="background:#dddddd;" | ||
− | |width="60%"| '''Topics''': | + | |width="60%"| '''Topics''': call/ret, looping, mul/div |
|width="15%"| '''Lab/Hw''' | |width="15%"| '''Lab/Hw''' | ||
|width="25%"| '''Reading''' | |width="25%"| '''Reading''' | ||
Line 308: | Line 308: | ||
---- | ---- | ||
* '''Wednesday''' | * '''Wednesday''' | ||
− | + | :* Back to '''call''' and '''ret''' instructions: defining and using functions. | |
+ | ::* '''Exercise 1''': Create a function that adds two int variables together | ||
+ | ::* '''Exercise 2''': Add a function that prints the two variables and their sum | ||
+ | :* '''mul''' and '''div''': multi-register instructions. EDX:EAX used as default registers. | ||
+ | ::* '''Exercise 3''': Write a Teller-Machine program | ||
+ | :* The loop instruction: ECX is the counter | ||
+ | :* [[CSC231_SumProc1.asm| Program 1]]: function computes sum of 2 ints | ||
+ | :* [[CSC231_SumProcPrint.asm | Program 2]]: compute sum of 2 ints and print sum | ||
+ | <!-- | ||
+ | :* [[CSC231_Teller1.asm | Program 3]]: Teller machine program. | ||
+ | :* [[CSC231_Teller2.asm | Program 4]]: Teller machine with function. | ||
+ | --> | ||
| | | | ||
− | * | + | * [[CSC231 Homework 4 2015| Homework #4]] |
− | |||
| | | | ||
− | * | + | * LOOP: Read Section 2.2.3 (Page 41) in [http://cs.smith.edu/~thiebaut/classes/231_0405/doc/pcasm-book.pdf Paul Carter's book]. |
+ | * MUL: Read Section 2.1.3 (Page 33) in [http://cs.smith.edu/~thiebaut/classes/231_0405/doc/pcasm-book.pdf Paul Carter's book]. Do not worry about the mention of 2's complement. Just concentrate on the registers that are used. | ||
+ | * CALL/RET: Section 4.4 (Page 65) in [http://cs.smith.edu/~thiebaut/classes/231_0405/doc/pcasm-book.pdf Paul Carter's book]. | ||
|} | |} | ||
Line 328: | Line 340: | ||
|} | |} | ||
<br /> | <br /> | ||
− | ::{| class="mw-collapsible | + | ::{| class="mw-collapsible " style="width:100%" border="1" |
|- style="background:#dddddd;" | |- style="background:#dddddd;" | ||
|width="60%"| '''Topics''': | |width="60%"| '''Topics''': | ||
Line 336: | Line 348: | ||
| | | | ||
* '''Monday''': | * '''Monday''': | ||
+ | :* Back to mul and div: [[Java and Python multiply integers differently| Java and Python multiply ints differently]] | ||
+ | ::* '''Exercise 1''': Write a Teller-Machine program | ||
+ | :* The loop instruction: ECX is the counter | ||
+ | ::* '''Exercise 2''': Compute the sum of all ints between 1 and ''n''. (There are many possible answers) | ||
+ | ::* '''Exercise 4''': What is the largest amount of looping we can do with the '''loop''' instructions? | ||
+ | ::* '''Exercise 5''': How long does it take a loop to accumulate the sum of all the ints between 1 and 1,000,000? Any particular issues one should be worried about? | ||
+ | ::* [[CSC231_Teller1.asm | Program 3]]: Teller machine program. | ||
+ | ::* [[CSC231_Teller2.asm | Program 4]]: Teller machine with function. | ||
+ | |||
---- | ---- | ||
* '''Wednesday''' | * '''Wednesday''' | ||
− | + | :* [[Speed of Instructions: Nasm, Java, C++ and Python comparison| Comparing execution speed of Java vs C++, vs Nasm, vs Python]]. | |
− | | | + | :* Measuring user time with the Linux '''time''' command: |
− | * | + | :: The '''user time''' is how long your program was running on the processor. The '''sys time''' is how long your program was waiting for the OS to perform tasks for it. In general, ('''user time + sys time''') is a good approximation of the time your program needs to run to completion. The '''real time''' contains the time that other processes took out of the CPU while your program was running. |
− | * | + | :* How many processes are running at the same time? '''ps''' and '''top''' commands. |
+ | :* '''Addressing modes''': the response of processor designers to the complexity of high-level languages. | ||
+ | :: [[Media:CSC231AddressingModes.pdf| Slides on addressing modes]] | ||
+ | ::*inherent | ||
+ | ::*register | ||
+ | ::*immediate | ||
+ | ::*direct | ||
+ | ::*indirect/based/indexed | ||
+ | ::*indirect with displacement | ||
+ | ::*base-indexed | ||
+ | ::*base-indexed with displacement | ||
+ | ::* [[CSC231_Loop_Exercises | Exercises on Loops]] | ||
+ | ::* [[CSC231_Addressing_Mode_Exercises | Exercises on Loops and Addressing Modes]] (Problems 2 to 6) | ||
+ | | | ||
+ | * No homework this week. Prepare for the midterm! | ||
| | | | ||
− | * | + | * [http://cs.smith.edu/~thiebaut/classes/231_0405/doc/pcasm-book.pdf Section 4.1 of Paul Carter's ebook] presents ''indirect addressing''. Read this first. Read also Section 5.1.3 about more sophisticated indirect addressing modes. |
|} | |} | ||
Line 358: | Line 393: | ||
|} | |} | ||
<br /> | <br /> | ||
− | ::{| class="mw-collapsible | + | ::{| class="mw-collapsible " style="width:100%" border="1" |
|- style="background:#dddddd;" | |- style="background:#dddddd;" | ||
|width="60%"| '''Topics''': | |width="60%"| '''Topics''': | ||
Line 365: | Line 400: | ||
|-valign="top" | |-valign="top" | ||
| | | | ||
− | * '''Monday''': | + | |
+ | * '''Monday''': <font color="Magenta">Midterm Exam</font>: in class, on paper, closed everything. | ||
+ | :* [[CSC231 Sample Midterm Questions| Midterm Preparation]] | ||
---- | ---- | ||
* '''Wednesday''' | * '''Wednesday''' | ||
− | + | :* Logic Instructions: OR, AND, XOR, NOT: they work in binary! | |
+ | :* Using logic instruction to mask various bit sections. | ||
+ | :* Exercise: | ||
+ | ::* Clear the upper 16 bits of eax | ||
+ | ::* Set the upper 4 bits of al to 0 | ||
+ | ::* Set the lower 4 bits of al to 1 | ||
+ | ::* <font color="magenta">Print AL in hex.</font> | ||
+ | :* Logic Gates: AND, OR, and NOT. That's what a computer is made of! | ||
+ | :* Taking a look at the mother board of an Apple computer. | ||
+ | :* [http://cs.smith.edu/dftwiki/images/1/12/7408-32-04.pdf The AND, OR, and Inverter gates in one pdf] | ||
+ | :* Schematics from [http://klabs.org/history/ech/agc_schematics/index.htm NASA], and a [http://klabs.org/history/ech/agc_schematics/logic/a04-1.jpg specific sheet] showing logic gates. | ||
+ | :* [http://en.wikibooks.org/wiki/Microprocessor_Design/ALU Schematics of 2-bit Adder] | ||
+ | :* AND, OR, (XOR), NOT (on [[http://en.wikipedia.org/wiki/Introduction_to_Boolean_algebra Wikipedia]]) | ||
| | | | ||
− | * | + | * [[CSC231 Homework 5 2015 | Homework 5]] |
− | |||
| | | | ||
− | * | + | * Reading |
+ | :* [http://cs.smith.edu/~dthiebaut/ArtOfAssembly/CH01/CH01-2.html#HEADING2-86 Logical Operations on Bits] | ||
+ | :* Section 3.2 on Bit operations (AND, OR, NOT, XOR) in [http://cs.smith.edu/~thiebaut/classes/231_0405/doc/pcasm-book.pdf Carter's eBook]. Look at the section that follows on bit manipulation in C. The same operations are also [https://docs.oracle.com/javase/tutorial/java/nutsandbolts/op3.html supported in Java]. | ||
|} | |} | ||
Line 388: | Line 438: | ||
|} | |} | ||
<br /> | <br /> | ||
− | ::{| class="mw-collapsible | + | ::{| class="mw-collapsible" style="width:100%" border="1" |
|- style="background:#dddddd;" | |- style="background:#dddddd;" | ||
− | |width="60%"| '''Topics''': | + | |width="60%"| '''Topics''': And, Or, and Not gates. Signed Integer format. |
|width="15%"| '''Lab/Hw''' | |width="15%"| '''Lab/Hw''' | ||
|width="25%"| '''Reading''' | |width="25%"| '''Reading''' | ||
Line 396: | Line 446: | ||
| | | | ||
* '''Monday''': | * '''Monday''': | ||
+ | :* [http://cs.smith.edu/dftwiki/images/1/12/7408-32-04.pdf The AND, OR, and Inverter gates in one pdf] | ||
+ | :* Schematics from [http://klabs.org/history/ech/agc_schematics/index.htm NASA], and a [http://klabs.org/history/ech/agc_schematics/logic/a04-1.jpg specific sheet] showing logic gates. | ||
+ | :* [http://en.wikibooks.org/wiki/Microprocessor_Design/ALU Schematics of 2-bit Adder] | ||
+ | :* AND, OR, (XOR), NOT (on [[http://en.wikipedia.org/wiki/Introduction_to_Boolean_algebra Wikipedia]]) | ||
+ | :* A 2-bit adder with logic gates. | ||
+ | <center><videoflash>6H62fyZEYsE</videoflash></center> | ||
+ | <br /><br /> | ||
+ | <center><videoflash>xTQDIiSWK_k</videoflash></center> | ||
+ | <!-- :* [http://cs.smith.edu/dftwiki/images/9/92/CSC231NumberSystems.pdf Slides on Number Systems] --> | ||
+ | :* [[Media:CSC231NumberSystemsUpdated.pdf | Slides on Number Systems (updated)]] | ||
+ | :* Example in C++ (Java does not support unsigned ints!) | ||
+ | :::<source lang="cpp"> | ||
+ | // signedUnsigned.cpp | ||
+ | // compile and run: | ||
+ | // g++ signedUnsigned.cpp | ||
+ | // ./a.out | ||
+ | // | ||
+ | |||
+ | #include <iostream> | ||
+ | #include <stdio.h> | ||
+ | using namespace std; | ||
+ | |||
+ | int main( int argc, char *argv[] ) { | ||
+ | unsigned u = 1; // unsigned int variable | ||
+ | int i = 1; // signed int | ||
+ | |||
+ | while ( 1 ) { // forever | ||
+ | i = i*3; | ||
+ | u = u*3; | ||
+ | cout << " u = " << u << endl; | ||
+ | cout << " i = " << i <<endl; | ||
+ | getchar(); // wait for user to press ENTER | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | :* [[CSC231_Exercises_on_Signed_Numbers| Exercises]] | ||
---- | ---- | ||
* '''Wednesday''' | * '''Wednesday''' | ||
− | + | [[File:XkcdCan'tSleep.png|400px]] | |
+ | :* Continue with [[CSC231_Exercises_on_Signed_Numbers| Exercises]] on signed number representation | ||
+ | :* The range of unsigned and signed ints, as byte, words, double words, 64-bit words. See [http://msdn.microsoft.com/en-us/library/s3f49ktz.aspx this Microsoft page on C++ for actual ranges] | ||
+ | :* The NEG and NOT instructions. | ||
+ | :* What is the 32-bit equivalent of a 16-bit 2's complement number? What is the rule for extending numbers in 2's complement? | ||
+ | :* The [http://cs.smith.edu/~thiebaut/ArtOfAssembly/CH06/CH06-1.html#HEADING1-236 CWDE instruction] | ||
+ | :* [[CSC231 Mystery C Program with signed numbers | Mystery problem of the day]]... | ||
+ | :* In case we need it: [[CSC231_4-bit_Unsigned_Nybble| 4-bit chart]] | ||
+ | :* Where does the carry bit go, when an '''add eax, value''' is performed? | ||
+ | :* Introduce the [http://cs.smith.edu/~dthiebaut/ArtOfAssembly/CH06/CH06-1.html#HEADING1-27 '''FLAGS register'''] | ||
+ | :* The [http://cs.smith.edu/~dthiebaut/ArtOfAssembly/CH06/CH06-2.html#HEADING2-244 CMP instruction]: '''Compare''': a SUB instruction that does not store the result anywhere! | ||
+ | :* Conditional Jumps: JA, JAE, JB, JBE, JC, JCXZ, JE, JG, JGE, JL, JLE, JNA, JNAE, JNB, JNBE, JNC, JNE, JNG, JNGE, JNL, JNLE, JNO, JNP, JNS, JNZ, JO, JP, JPE, JPO, JS, JZ (more info [http://cs.smith.edu/~dthiebaut/ArtOfAssembly/CH06/CH06-5.html#HEADING5-226 here]). | ||
+ | :* [[CSC231_Flags_Settings_Examples | Examples of how flag bits are set]] | ||
| | | | ||
− | * | + | * [[CSC231 Homework 6 2015| Homework 6]] |
− | |||
| | | | ||
− | * | + | * Signed and unsigned numbers are covered in [http://maven.smith.edu/~thiebaut/ArtOfAssembly/CH01/CH01-2.html#HEADING2-96 Sections 1.7 and 1.8] and [http://maven.smith.edu/~thiebaut/classes/231_0607/doc/pcasm-book.pdf Chap. 2] |
+ | * The [http://cs.smith.edu/~thiebaut/ArtOfAssembly/CH06/CH06-2.html#HEADING2-313 NEG instruction] | ||
+ | * The [http://cs.smith.edu/~thiebaut/ArtOfAssembly/CH06/CH06-1.html#HEADING1-236 CWDE instruction] | ||
+ | * The [[http://cs.smith.edu/~dthiebaut/ArtOfAssembly/CH06/CH06-2.html#HEADING2-244 CMP instruction] | ||
|} | |} | ||
Line 418: | Line 518: | ||
|} | |} | ||
<br /> | <br /> | ||
− | ::{| class="mw-collapsible | + | ::{| class="mw-collapsible " style="width:100%" border="1" |
|- style="background:#dddddd;" | |- style="background:#dddddd;" | ||
− | |width="60%"| '''Topics''': | + | |width="60%"| '''Topics''': Conditional Jumps, Push & Pop |
|width="15%"| '''Lab/Hw''' | |width="15%"| '''Lab/Hw''' | ||
|width="25%"| '''Reading''' | |width="25%"| '''Reading''' | ||
Line 426: | Line 526: | ||
| | | | ||
* '''Monday''': | * '''Monday''': | ||
+ | :* Unconditional Jump: '''JMP''' | ||
+ | :* Review ALU, Flag bits, Instructions that set flag bits. | ||
+ | :* '''CMP''' is a '''SUB''' that does not store the result of the subtraction. | ||
+ | :* Typical compare/jump instructions: | ||
+ | <br /> | ||
+ | ::<source lang="asm"> | ||
+ | cmp op1, op2 | ||
+ | jne notEqual | ||
+ | ... | ||
+ | jmp done | ||
+ | notEqual: | ||
+ | ... | ||
+ | done: | ||
+ | ... | ||
+ | |||
+ | </source> | ||
+ | <br /> | ||
+ | :* [[CSC231_Flags_Settings_Examples | Examples of instructions that affect the flag bits]] | ||
+ | :* [[CSC231 Exercises with conditional jumps | Exercises to put all this into place]] | ||
---- | ---- | ||
* '''Wednesday''' | * '''Wednesday''' | ||
+ | :* Video lecture. | ||
+ | <br /> | ||
+ | <videoflash>5VcdBOMAEkI</videoflash> | ||
+ | <br /> | ||
+ | :* Information about the current homework is given at the end of the video. | ||
| | | | ||
− | * | + | * [[CSC231 Homework 7 2015 | Homework 7]] |
− | |||
| | | | ||
− | * | + | * The [http://cs.smith.edu/~dthiebaut/ArtOfAssembly/CH06/CH06-2.html#HEADING2-244 CMP instruction] |
+ | * The [http://cs.smith.edu/~thiebaut/ArtOfAssembly/CH06/CH06-5.html#HEADING5-226 conditional jumps page] in Randy Hall's ''Art of Assembly.'' | ||
+ | * [http://cs.smith.edu/~thiebaut/ArtOfAssembly/CH06/CH06-1.html#HEADING1-160 Push and Pop] instructions. | ||
+ | |||
|} | |} | ||
Line 448: | Line 574: | ||
|} | |} | ||
<br /> | <br /> | ||
− | ::{| class="mw-collapsible | + | ::{| class="mw-collapsible " style="width:100%" border="1" |
|- style="background:#dddddd;" | |- style="background:#dddddd;" | ||
|width="60%"| '''Topics''': | |width="60%"| '''Topics''': | ||
Line 456: | Line 582: | ||
| | | | ||
* '''Monday''': | * '''Monday''': | ||
+ | :* Review Push/Pop | ||
+ | :* Passing Parameters ([[Media:CSC231_PassingParametersThroughTheStack2.pdf| Lecture slides (pdf)]]) | ||
+ | ::* Passing Parameters via registers (and bits) | ||
+ | ::* Passing parameters via the stack: ''we need a new register: EBP!'' | ||
+ | ::* Passing by value | ||
+ | [[Image:JavaStackTrace.png|right|150px]] | ||
+ | ::* Passing by reference | ||
+ | ::* Function returning values | ||
+ | ::* [[CSC231 SumProc1.asm |sumProc1.asm]]: Pass through registers | ||
+ | ::* [[CSC231 SumProc2.asm |sumProc2.asm]]: Pass by value | ||
+ | ::* [[CSC231 SumProc3.asm |sumProc3.asm]]: Int returning function | ||
+ | ::* [[CSC231 SumProc4.asm |sumProc4.asm]]: Pass by reference | ||
---- | ---- | ||
* '''Wednesday''' | * '''Wednesday''' | ||
+ | ::* [[CSC231 SumProc5.asm |sumProc5.asm]]: <font color="magenta">'''Local variables'''</font> | ||
+ | ::* [[CSC231 No-no! and Be-Careful! situations | Tips, tricks, and no-nos]]. | ||
| | | | ||
− | * | + | * No new homework this week. Homework 7 extended. |
− | |||
| | | | ||
− | * | + | * [http://cs.smith.edu/~thiebaut/ArtOfAssembly/CH11/CH11-1.html Procedures and Functions]. They are basically the same. Procedure is often used to refer to a function that does not return anything. |
+ | * [http://cs.smith.edu/~thiebaut/ArtOfAssembly/CH06/CH06-1.html#HEADING1-160 Push and Pop] instructions. | ||
+ | * [http://cs.smith.edu/~thiebaut/ArtOfAssembly/CH06/CH06-5.html#HEADING5-98 Call and Ret] instruction. | ||
+ | * ''Functions'' and the topics associated with passing parameters are covered in Carter's Manual on Assembly Language, in [http://maven.smith.edu/~thiebaut/classes/231_0405/doc/pcasm-book.pdf Chapter 4], titled ''Subprograms''. | ||
+ | |||
|} | |} | ||
Line 478: | Line 621: | ||
|} | |} | ||
<br /> | <br /> | ||
− | ::{| class="mw-collapsible | + | ::{| class="mw-collapsible" style="width:100%" border="1" |
|- style="background:#dddddd;" | |- style="background:#dddddd;" | ||
|width="60%"| '''Topics''': | |width="60%"| '''Topics''': | ||
Line 486: | Line 629: | ||
| | | | ||
* '''Monday''': | * '''Monday''': | ||
+ | :* Review passing parameters, by value, by reference, functions returning values, and local variables. | ||
+ | :* Review stack frame. | ||
+ | :* Writing the recursive function for the [[CSC231_Factorial.asm | Factorial]] problem. | ||
---- | ---- | ||
* '''Wednesday''': <font color="magenta">'''Thankgiving Break'''</font> | * '''Wednesday''': <font color="magenta">'''Thankgiving Break'''</font> | ||
+ | <br /> | ||
+ | [[File:Turkey.gif]] | ||
| | | | ||
− | + | <br /> | |
− | |||
| | | | ||
* | * | ||
Line 508: | Line 655: | ||
|} | |} | ||
<br /> | <br /> | ||
− | ::{| class="mw-collapsible | + | ::{| class="mw-collapsible" style="width:100%" border="1" |
|- style="background:#dddddd;" | |- style="background:#dddddd;" | ||
|width="60%"| '''Topics''': | |width="60%"| '''Topics''': | ||
Line 516: | Line 663: | ||
| | | | ||
* '''Monday''': | * '''Monday''': | ||
+ | :* A note on [[Media:BenchmarkingNotes.pdf| benchmarking]]... | ||
+ | :* [[CSC231_No-no!_and_Be-Careful!_situations | Tips and Tricks]] | ||
+ | :* Recursion: [[Assembly_Simulator_in_Python | A Python simulator for Factorial.asm]] | ||
---- | ---- | ||
* '''Wednesday''' | * '''Wednesday''' | ||
− | + | :* Exercises | |
+ | :::* How much stack space is required for computing the factorial of 1000? What else, besides the stack, should we be worried about? | ||
+ | :::* How much stack space, at least, and at most, would we need to recursively visit a 1000x1000 maze? You can find a Java maze traversing program [[Recursive_Maze_Visit|here]]. Express your answer in KB, MB, or GB. | ||
+ | :* [[Stack overflow in Java| Stack Overflow in Java]] | ||
+ | :* [[CSC231_An_Introduction_to_Fixed-_and_Floating-Point_Numbers | Floating-Point Numbers]] | ||
+ | :* [http://cs.smith.edu/dftwiki/media/FixedFloatingPoint.pdf Slides for Fixed-Point & Floating-Point formats] | ||
| | | | ||
− | * | + | * [[CSC231 Homework 8 2015| Homework 8]] |
− | |||
| | | | ||
− | * | + | * [[CSC231_An_Introduction_to_Fixed-_and_Floating-Point_Numbers | Introduction to Fixed- and Floating-Point Numbers]] |
|} | |} | ||
Line 538: | Line 692: | ||
|} | |} | ||
<br /> | <br /> | ||
− | ::{| class="mw-collapsible | + | ::{| class="mw-collapsible " style="width:100%" border="1" |
|- style="background:#dddddd;" | |- style="background:#dddddd;" | ||
|width="60%"| '''Topics''': | |width="60%"| '''Topics''': | ||
Line 546: | Line 700: | ||
| | | | ||
* '''Monday''': | * '''Monday''': | ||
+ | :* Floating Points | ||
---- | ---- | ||
* '''Wednesday''' | * '''Wednesday''' | ||
+ | :* Floating Points | ||
| | | | ||
− | + | ||
− | |||
| | | | ||
* | * | ||
Line 568: | Line 723: | ||
|} | |} | ||
<br /> | <br /> | ||
− | ::{| class="mw-collapsible | + | ::{| class="mw-collapsible " style="width:100%" border="1" |
|- style="background:#dddddd;" | |- style="background:#dddddd;" | ||
|width="60%"| '''Topics''': | |width="60%"| '''Topics''': | ||
Line 575: | Line 730: | ||
|-valign="top" | |-valign="top" | ||
| | | | ||
− | * '''Monday''': <font color="magenta">Last Class</font> | + | * '''Monday''': <font color="magenta">Last Class</font>: Presentation of the take-home final exam. The exam will be due at 4:00 p.m. on the last day of exams. |
| | | | ||
− | * Final Exam | + | * [[CSC231 Final Exam 2015 | Final Exam]] |
| | | | ||
* | * |
Latest revision as of 13:08, 14 December 2015
--D. Thiebaut (talk) 11:28, 26 August 2015 (EDT)
Week 1 Sept 7 |
Topics: Introduction, Python, Idle, Piazza, Moodle submission Lab/Hw Reading - Wednesday
- Syllabus
- Class accounts
- The main players for this semester:
- PC
- Processor
- Memory
- Disk
- First program in assembly: recognize the different elements:
- Structure
- Presentation
- Documentation
- Skeleton program
- Hello World! on Linux (and its Mac version)
- Reading
- Chapter 1 in the Art of Assembly.
- Also Chapter 3, Sections 0 to 3.1.2.
- Sections 1.3.1, 1.3.2, 1.3.3, 1.3.4, and 1.3.5 in Carter's PC Assembly Language. Note, Carter uses 1A92h to represent a hexadecimal number. I prefer 0x1A92.
- Wednesday
Week 2 Sept. 14 |
Topics: Processor and Memory, working with the shell, and emacs. Lab/Hw Reading - Monday:
- Review PC destruction lab. Main players: Processor, cores, RAM, motherboard, crystal
- How would Richard Tuttle see a computer motherboard? This is some of his artwork.
- First diagram of a computer as seen by an assembly language programmer
- Review Hello World program with this new knowledge
Notice how the main character uses all kinds of software packages to solve his problem. It includes working in a shell, using shell commands, and mixing the results with various programming techniques.
- Wednesday
- Linux System Calls. See Slide 5 of this presentation
- Working in a shell
- The bash shell
- Playing with the shell using 231a-xx accounts
- Useful commands
- ls, cd, pwd, mkdir, rm, rmdir, cp
- history, !, !!, alias, w, ps, who am i
- grep, wc, head, tail
- Redirection
- Pipes
- Emacs
- quick overview (see this page)
- set of commands
- Lab
- Homework
Week 3 Sept. 21 |
Topics: Number Systems, the MOV instruction Lab/Hw Reading - Monday:
- Let's talk about the crystal
- Relationship with instructions
- Power-law for increase in processor speed
- Ray Kurzweil on Power Laws (go to marker 3:30 min in video)
- Playing a game of numbers
- Hexadecimal system:
for i in range( 256 ): print( i, format( i, '02X' ) )
- Assembly:
- Review nasm, ld
- Understanding how data fits in memory: printing strings defined by db
- Size of a program: data + code
size helloWorld2 text data bss dec hex filename 34 14 0 48 30 helloWorld2
- Listing of the assembly and its code:
nasm -f elf -l helloWorld2.lst helloWorld2.asm ls ... helloWorld2.lst ...
- Wednesday
- Quick check of number conversion skills
- Observe output of nasm -l (helloWorld2.lst)
- Another way to look at the executable file with hexdump
hexdump -v -C helloWorld2 00000000 7f 45 4c 46 01 01 01 00 ... ... 000002b0 74 61 00 5f 65 6e 64 00 |ta._end.| 000002b8
- Observe the output of hexdump command
- Finish the reading assigned for Week 1.
- The mov instruction
Week 4 Sept. 28 |
Topics: The Mov instruction. Arithmetic instructions. Addressing Modes. Lab/Hw Reading - Monday:
- Wednesday
- A script to automatically assemble and link assembly programs
- Review: MOV instruction: direct and immediate modes of addressing data
- Examples: copying a string to another string
- Exercises with the MOV instruction
- The ADD instruction
- Overly-simplified encryption of a string
- Chapter 3, Section 1 in The Art of Assembly, to Section 3.2.2.
Week 5 Oct 5 |
Topics: Lab/Hw Reading - Monday:
- Arithmetic instructions: ADD, SUB, INC, DEC. Skip MUL and DIV for right now.
- A quick introduction to calling functions: CALL and RET
- Printing decimal numbers in assembly
- A first look at what is behind code like this:
int a; int b; int c; a = 3; b = 5; c = a + b;
- Example of what the GNU cc compiler would have generated
- Exercise 1: "Compile" the following statements to assembly:
int a; int b; int c; int d; a = 3; b = 5; c = a*2 + b; d = (a + b + 10 + 2*c ) * 2 - 20;
- Exercise 2: translate the following code in assembly. If you need to refresh your memory on Java types, check this document out:
int a = 3, b = 5, c; short d = 10, e = 0xff, f = 0; c = ( a * 2 + b ) * 3; f = d + (e-1); c = a * 2* d;
- Wednesday
- Mountain Day?
- Big Endian vs. Little Endian hardware. Why does it matter?
- page with some little-endian and big-endian architectures.
- Section 4.1 of Paul Carter's ebook presents indirect addressing. Read this first. Read also Section 5.1.3 about more sophisticated indirect addressing modes.
- The CALL and RET instructions
Week 6 Oct. 12 |
Topics: call/ret, looping, mul/div Lab/Hw Reading - Monday: Fall Break
- Wednesday
- Back to call and ret instructions: defining and using functions.
- Exercise 1: Create a function that adds two int variables together
- Exercise 2: Add a function that prints the two variables and their sum
- mul and div: multi-register instructions. EDX:EAX used as default registers.
- Exercise 3: Write a Teller-Machine program
- LOOP: Read Section 2.2.3 (Page 41) in Paul Carter's book.
- MUL: Read Section 2.1.3 (Page 33) in Paul Carter's book. Do not worry about the mention of 2's complement. Just concentrate on the registers that are used.
- CALL/RET: Section 4.4 (Page 65) in Paul Carter's book.
Week 7 Oct 19 |
Topics: Lab/Hw Reading - Monday:
- Back to mul and div: Java and Python multiply ints differently
- Exercise 1: Write a Teller-Machine program
- The loop instruction: ECX is the counter
- Exercise 2: Compute the sum of all ints between 1 and n. (There are many possible answers)
- Exercise 4: What is the largest amount of looping we can do with the loop instructions?
- Exercise 5: How long does it take a loop to accumulate the sum of all the ints between 1 and 1,000,000? Any particular issues one should be worried about?
- Program 3: Teller machine program.
- Program 4: Teller machine with function.
- Wednesday
- Comparing execution speed of Java vs C++, vs Nasm, vs Python.
- Measuring user time with the Linux time command:
- The user time is how long your program was running on the processor. The sys time is how long your program was waiting for the OS to perform tasks for it. In general, (user time + sys time) is a good approximation of the time your program needs to run to completion. The real time contains the time that other processes took out of the CPU while your program was running.
- How many processes are running at the same time? ps and top commands.
- Addressing modes: the response of processor designers to the complexity of high-level languages.
- Slides on addressing modes
- inherent
- register
- immediate
- direct
- indirect/based/indexed
- indirect with displacement
- base-indexed
- base-indexed with displacement
- Exercises on Loops
- Exercises on Loops and Addressing Modes (Problems 2 to 6)
- No homework this week. Prepare for the midterm!
- Section 4.1 of Paul Carter's ebook presents indirect addressing. Read this first. Read also Section 5.1.3 about more sophisticated indirect addressing modes.
Week 8 Oct. 26 |
Topics: Lab/Hw Reading - Monday: Midterm Exam: in class, on paper, closed everything.
- Wednesday
- Logic Instructions: OR, AND, XOR, NOT: they work in binary!
- Using logic instruction to mask various bit sections.
- Exercise:
- Clear the upper 16 bits of eax
- Set the upper 4 bits of al to 0
- Set the lower 4 bits of al to 1
- Print AL in hex.
- Logic Gates: AND, OR, and NOT. That's what a computer is made of!
- Taking a look at the mother board of an Apple computer.
- The AND, OR, and Inverter gates in one pdf
- Schematics from NASA, and a specific sheet showing logic gates.
- Schematics of 2-bit Adder
- AND, OR, (XOR), NOT (on [Wikipedia])
- Reading
- Logical Operations on Bits
- Section 3.2 on Bit operations (AND, OR, NOT, XOR) in Carter's eBook. Look at the section that follows on bit manipulation in C. The same operations are also supported in Java.
Week 9 Nov. 2 |
Topics: And, Or, and Not gates. Signed Integer format. Lab/Hw Reading - Monday:
- The AND, OR, and Inverter gates in one pdf
- Schematics from NASA, and a specific sheet showing logic gates.
- Schematics of 2-bit Adder
- AND, OR, (XOR), NOT (on [Wikipedia])
- A 2-bit adder with logic gates.
- Slides on Number Systems (updated)
- Example in C++ (Java does not support unsigned ints!)
// signedUnsigned.cpp // compile and run: // g++ signedUnsigned.cpp // ./a.out // #include <iostream> #include <stdio.h> using namespace std; int main( int argc, char *argv[] ) { unsigned u = 1; // unsigned int variable int i = 1; // signed int while ( 1 ) { // forever i = i*3; u = u*3; cout << " u = " << u << endl; cout << " i = " << i <<endl; getchar(); // wait for user to press ENTER } }
- Wednesday
- Continue with Exercises on signed number representation
- The range of unsigned and signed ints, as byte, words, double words, 64-bit words. See this Microsoft page on C++ for actual ranges
- The NEG and NOT instructions.
- What is the 32-bit equivalent of a 16-bit 2's complement number? What is the rule for extending numbers in 2's complement?
- The CWDE instruction
- Mystery problem of the day...
- In case we need it: 4-bit chart
- Where does the carry bit go, when an add eax, value is performed?
- Introduce the FLAGS register
- The CMP instruction: Compare: a SUB instruction that does not store the result anywhere!
- Conditional Jumps: JA, JAE, JB, JBE, JC, JCXZ, JE, JG, JGE, JL, JLE, JNA, JNAE, JNB, JNBE, JNC, JNE, JNG, JNGE, JNL, JNLE, JNO, JNP, JNS, JNZ, JO, JP, JPE, JPO, JS, JZ (more info here).
- Examples of how flag bits are set
- Signed and unsigned numbers are covered in Sections 1.7 and 1.8 and Chap. 2
- The NEG instruction
- The CWDE instruction
- The [CMP instruction
Week 10 Nov 9 |
Topics: Conditional Jumps, Push & Pop Lab/Hw Reading - Monday:
- Unconditional Jump: JMP
- Review ALU, Flag bits, Instructions that set flag bits.
- CMP is a SUB that does not store the result of the subtraction.
- Typical compare/jump instructions:
cmp op1, op2 jne notEqual ... jmp done notEqual: ... done: ...
- Wednesday
- Video lecture.
- Information about the current homework is given at the end of the video.
- The CMP instruction
- The conditional jumps page in Randy Hall's Art of Assembly.
- Push and Pop instructions.
Week 11 Nov 16 |
Topics: Lab/Hw Reading - Monday:
- Review Push/Pop
- Passing Parameters ( Lecture slides (pdf))
- Passing Parameters via registers (and bits)
- Passing parameters via the stack: we need a new register: EBP!
- Passing by value
- Passing by reference
- Function returning values
- sumProc1.asm: Pass through registers
- sumProc2.asm: Pass by value
- sumProc3.asm: Int returning function
- sumProc4.asm: Pass by reference
- Wednesday
- sumProc5.asm: Local variables
- Tips, tricks, and no-nos.
- No new homework this week. Homework 7 extended.
- Procedures and Functions. They are basically the same. Procedure is often used to refer to a function that does not return anything.
- Push and Pop instructions.
- Call and Ret instruction.
- Functions and the topics associated with passing parameters are covered in Carter's Manual on Assembly Language, in Chapter 4, titled Subprograms.
Week 12 Nov 23 |
Topics: Lab/Hw Reading - Monday:
- Review passing parameters, by value, by reference, functions returning values, and local variables.
- Review stack frame.
- Writing the recursive function for the Factorial problem.
- Wednesday: Thankgiving Break
Week 13 Nov 30 |
Topics: Lab/Hw Reading - Monday:
- A note on benchmarking...
- Tips and Tricks
- Recursion: A Python simulator for Factorial.asm
- Wednesday
- Exercises
- How much stack space is required for computing the factorial of 1000? What else, besides the stack, should we be worried about?
- How much stack space, at least, and at most, would we need to recursively visit a 1000x1000 maze? You can find a Java maze traversing program here. Express your answer in KB, MB, or GB.
Week 14 Dec 7 |
Topics: Lab/Hw Reading - Monday:
- Floating Points
- Wednesday
- Floating Points
Week 15 Dec 14 |
Topics: Lab/Hw Reading - Monday: Last Class: Presentation of the take-home final exam. The exam will be due at 4:00 p.m. on the last day of exams.
Links and Resources
- Notes on Assembling 32-bit Code on 64-bit Machines
- Hello Word in assembly running on Mac OS and on Linux