Intro to CS255:
Logistics:
Part 1: Fundamental knowledge of the Computer
Intro to the Computer
The computer memory (RAM) :
Storing information using Binary numbers (codes + context = information):
The different types of codes used
in a computer system to represent
various kinds of information
Storing Boolean data inside a computer
Representing and storing unsigned integer (= whole)
numbers inside a computer
Representing unsigned integral values inside the computer:
Other number systems that are related to the Binary number system
(condensed representation of bit patterns):
Homework 1: computer architecture
click here
Representing and storing signed integer (whole)
numbers inside a computer
Representing (and storing)
signed integral values inside the computer:
Representing and storing
fractional numerical values inside a computer:
Homework 2 re-enforces number system concepts:
click here
Representing and storing text data inside the computer
Input and output operations in a computer program
Human <==> Computer communication (explains the need
for conversion from ASCII to other representation and vice versa):
Boolean input and output:
(converting between ASCII representation of Boolean values
and the 0/1 boolean code )
Numeric (integer) input/output :
(converting between
ASCII representation of integer numbers and
the 2's complement code )
Homework 3 re-enforces
string ⟷ int conversion:
click here
Representing computer instructions inside the computer
(intro to hardware):
Part 2: C programming
Introduction to C for
Java programmers
The
C Pre-processor:
I will first discuss language features that are similar
in C and Java to get you programming in C quickly.
First: some things in C that you must be
always remember (very different from Java):
C's data types and variables:
High level operators
(quick review - they are same as Java) :
Arithmetic Operators:
( +, -, *, / ):
click here
---
Assignment Operators:
click here
( +=, -=, *=, /=, &=, |=, ~=, >>=, <<= )
---
Increment/decrement Operators:
click here
( ++, -- )
---
Boolean data type and operations:
The
conditional operator ?:
click here
---
The
comma operator ,
click here
---
The
sizeof operator
click here
---
Priority and
Associativity
of the C operators
click here
---
--------------------------------- 2/13
Statements
(quick review - they are same as Java) :
Homework 4 introduces you the features
in C that are similar to Java by
writing 2 C functions
click here
Arrays:
(C has static arrays, Java has dynamic arrays)
Functions (= methods):
Debugging techniques for C programs:
(debugging will not be covered in tests)
Multi-files C programs -
the importance of
declaring functions :
The make (UNIX) utility:
(Make will not be covered in tests)
Low level operators :
Bit-wise-Operators:
(used in CS350)
Shift-Operators: (used in CS350)
click here
( >>, << )
How to implement a "bit " array
using an array of int
click here
---
Homework 5 reinforces bit operations and
using a bit array
click here
Language features that are both available in C and
Java but differ slightly
User-defined types in C (i.e.: structures )
The life time and scope of
the different kinds of variables in C :
Advanced C language features that are not found in Java
(pointer data type !)
The reference data type and
reference (pointer) variables
Pointer to a user-defined type:
Using pointers
to create and maintain linked lists in C:
Pointer arithmetic and
accessing array elements
Strings in C :
Homework 7 shows you how write a
"class" in C -- it's all about organization using header files
and C program files
click here
C documentations:
The C programming language book - Kernighan and Richie:
click here
The C99 standard :
click here
Obituary of Dennis Ritchie (co-inventory of C):
click here
Part 3: Assembler Programming (complete understanding of how a computer works)
Prelude to assembler programming: internal details of the CPU
Intro to assembler programming using the ARM processor
The text and data assembler program sections/segments
Assembler programming with integer constants and simple integer variables
Introduction (motivate using only
integer data types ):
click here
---
slides
The mov instruction in ARM:
Store-ordering in memory: big and little endian ordering
click here
---
slides
Reading (the value stored in)
a simple memory variable:
click here
---
slides
--------------------------------- 4/2
Writing/updating (the value stored in)
a simple memory variable:
click here
---
slides
What happens when you use an
incorrect load /store instruction:
click here
---
slides
The importance of data type information in the
compilation process :
---
slides ONLY
Translating simple assignment statements to assembler:
b = 4 and
b = a
click here
---
slides
Homework 8 re-enforces
the use of
move, load and store instructions:
click here
Arithmetic operations (instructions):
click here
---
slides
Assignment statement with
arithmetic expressions
using (only) simple variables : c = a + b
click here
---
slides
--------------------------------- 4/4
The array data structure
(teach with demo/asm/3-array/demo.s)
The linked list data structure
(teach with demo/asm/4-linked-list/demo1.s and demo2.s)
How is an object stored in memory:
click here
---
slides
How is a linked list stored in memory:
click here
---
slides
(I kept my old note here:
old )
Defining and accessing the head variable
in assembler :
click here
---
slides
--------------------------------- 4/11
Computiing offsets of fields in a (Node) variable/object:
click here
---
slides
Assembler programming examples of accessing fields in
a linked list:
click here
---
slides
Homework 9 re-enforces
access technique to
structured variables (arrays and linked lists) :
click here
My summary notes on ARM assembler programming techniques
used to prepare the CS255 material:
click here
A single sheet summary of
ARM instruction nmenomic codes
:
click here
Documentation - the complete ARM Instruction set and
encoding
(not part of syllabus material):
click here
Now you know what the computer actually does when it
executes an assignment statement: how it
evaluates an expression and assigns the result to a variable
in a high level programming language.
We will discuss various program flow control structures next.
The Selection (if, if-else) Statements:
Introduction:
click here
---
slides
Branching - out of order program flow:
click here
---
slides
How is the branch instruction implemented ?
click here
---
slides
The Compare (cmp) and Branch
(beq, bne, blt, ble, bgt, bge, bal)
assembler instructions of ARM:
click here
---
slides
Coding Selection statements in assembler:
The Loop Statements:
Homework 10 re-enforces the use of compare
and branching in writing your first assembler program containing
a while loop and if-statements:
click here
Now you know what the computer actually does when it runs a program.
The only thing that you still do not know is what happens
in a function call (there is still a lot to learn...).
Subroutines (a.k.a. methods, procedures, functions)
Introduction:
click here
---
slides
Leaf subroutines and
Non-Leaf subroutines :
click here
---
slides
Implementing Leaf subroutines in
ARM assembler :
Implementing Non-Leaf subroutines in
ARM assembler :
What happens when a called function calls another function:
click here
---
slides
The program runtime stack of a running program:
click here
---
slides
The ARM assembler
push and
pop
instructions:
click here
---
slides
--------------------------------- 4/23
Implementing
non-leaf methods/functions
using the program stack:
click here
---
slides
Using the non-leaf function technique
to implement leaf functions :
click here
---
slides
Leaf functions with
parameters and local variables
in CPU registers
Introduction:
click here
---
slides
Passing parameters to a function and passing
return values using CPU registers :
Intro: using CPU registers to pass parameters and
return values:
click here
---
slides
sumSquares(a,b) :
using CPU registers to pass parameters and
return values
click here
---
slides
sumRange(A, a, b) : using registers as local variables :
click here
---
slides
**** The final will cover upto this point ****
Project 7 (Bubblesort)
re-enforces the use of registers
for passing parameters and storing local variables:
click here
****** NOT ASSIGNED
Non-Leaf functions with
parameters and local variables
in the runtime stack
Passing parameters and allocating local variables
using the program stack :
Intro:
using the program stack to store
parameters and local variables :
click here
---
slides 1
---
slides 2
--------------------------------- 11/28
Why can the stack
avoid the overwrite problem in registers:
click here
---
slides
How to code subroutine return in assembler
--- tearing down a stack frame :
click here
---
slides
Summary and a "How to" guide:
click here
---
slides
A complete example of
passing parameters and allocating local variables
using the program stack :
click here
---
slides
Another usage of the program stack -
saving registers in an interrupted computation :
click here
---
slides
Recursive subroutines/methods: (are always non-leaf functions !)
Introduction:
click here
---
slides
First recursive method in assembler, the classic
factorial function:
click here
---
slides
Second recursive method in assembler:
click here
---
slides
Programming project pj8 re-enforces
storing parameters and local variables on stack with a
recursive function:
click here
I inserted some material here to help you understand recursion :
Recursion is a
divide and conquer technique to solve
problems:
Programming project pj9 is
another recursion project --- inserting a new list element
in an ordered linked list:
click here
Parameter passing techniques:
If you understand everything so far, you now know
exactly what is going on when a computer executes
a program.
You can apply what you learn and write assembler
programs in any assembler language, e.g.,
Intel.
To program with a new chip, all you need to learn are:
its architecture (registers),
the addressing modes
the instruction mnemonic codes and what they do.
I have Intel assembler programming material
after the C lecture notes to demonstrate this process.
(These notes are not part of the CS255 curriculum - it's
"for your eyes only")
That's all, Folks !
Additional Enrichment Material:
Intel 80x86 programming (not covered in CS255)
Rough notes on Intel Assemler programming:
Other resources:
Matloff GNU assembler programming tutorial:
click here
Sourceforge GNU assembler programming tutorial:
click here
Free Intel Macro Assembler (if you want to write
assembler on your PC):
RIGHT click here and SAVE AS
Intel Assembler Programming book
- this book is like the CS255 course using
Intel Assembler code:
click here
Step by step Windows programming tutorial
shows you how to write window programs, menus,
call backs, etc:
click here
The Art of Assembly Programming (a very good online book,
but the 32 bit version uses a non-standard assembler
called "HLA" - High Level Assemble language)
click here