2110206  Assembly Language Programming


3 hours lecture per week at Engineering building 3, room 324, Mon 1-4pm.
Prabhas Chongstitvatana

syllabus

The first half concerned computer systems, so called computer organisation.  The second half concentrated on the understanding of computer at low level abstraction, i.e. the machine level.  Including the programming skill at assembly language level. The implication of future of computing will be explored.

Annoucement

15 Jan 2007    Project 1    Hand-in date is Mon  29  Jan 2007   4pm.  at the box in front of my office  (Engineering Building 4, Floor 18, room 18-13).
16 Jan 2007     Midterm score is here   
1 Feb 2007      Project 1 Presentation Schedule
6 Feb 2007      Project 2 announcement
15 Feb 2007     update S2 calculator engine  See note here. 
23  Feb 2007    Trial session of final exam is today   (9-12am) at Eng. Building 4, Floor 18, room 18-02.
                         Final on-line exam is on Monday 5 March 2007, 10-12am at Eng. Building 4, Floor 18, room 18-02.
14  Mar 2007    Final score is here    Please check and inform me immediately if you find any mistake in your score.

What's new

1  Nov 2006    Lecture 1
6  Nov 2006   Number and Data
29  No 2006   Computer Arithmetic   (Stalling slide and my text chapter 3)
4  Dec 2006    Computer Logic  (Katz's slide ch1 23 pages & 2  16 pages)
15 Jan 2007     S0 processorS2 assembly language
24 Jan 2007     S2 version 2.1 assembly language      How to use assembler-simulator    S2.1 Instruction Set     S2.1 tools
5 Feb 2007      Update S2.1 tools      S2 instruction set document update
6 Feb 2007      Details of project 2  more detail on the project
7 Feb  2007     The S2 Calculator Engine      S2 calculator engine in S2 assembly language
10 Feb 2007    S2 calculator package completed !
13  Feb  2007   S2 package with data structure extension    lecture Data Structure
...

Lecture outline

computer structure   Chapter 1 of my new textbook
number and data representation   (from Comer slide  page 64-103)
computer arithmetic    (from Stalling slide chapter 9, ppt)
4  computer logic    excerpt from Katz's slides  chap 1  and  chap 2  
5  processor and its function  Stalling slide  chap-10    chap-11   chap-12 (page 1-27)
6  computer instruction  S0 processor
assembly language 1   (my lecture of comporg 2006)
    S2 version 2.1 assembly language      How to use assembler-simulator    S2.1 Instruction Set 
    S2 programming examples
8  assembly language 2   more S2 programming examples     S2 instruction set document update
9  assembly language 3    Call function
10  data structure   example of S2 program:  list    bsearch   trie
11 computing future

assessment

midter exam    30
final exam     30
four projects  20
homework       10
participation  10
              ----
total         100

Homework

Week 1

1  Give an example of  "computation " in your daily life.  Explain what is "sensor", "effector" and "computation".
2   Write a list of name of operating system in present days (5 names).  It should include OS for desktop, server, cell phone, PDA etc.).  Give a brief description of each system.
3   Discuss the meaning of the phrase "digital divide" in your opinion.
4   What do you think about "copyright" for software?

Week 2

1   Draw a picture on a 16x16 board, each square is either black or white. ...

Week 3 ...

Week 4

1    Draw circuit using AND,  OR, NOT  gates of the following Boolean formula:    (* and, + or, / not)
1.1   A*B + /A*/B
1.2    A*(/B*C) + /C
2     Draw switch diagram of this propositional formula:
     IF  sunshine
     AND NOT  flood
      THEN   go-play-golf
3   Draw circuit using AND, OR, NOT gates for a 3-bit adder.
4    Let a switch (normally open)  represents a variable (A..G).  What is the truth assignment of the following circuit to output T ?
(you can write a Boolean formula to represent the output).

    A  B  C
T --@--@--@--|
          D  |
      T --@--| ---- OUT
    E        |
F --@--|     |
    G  |-----|
F --@--|

Week 5

1  Write the register transfer language to describe the sequence of operations of a processor running the following program:
load r1 b
load r2 c
add r3 r2 r1
store a r3
     a, b, c reside in the memory. r1, r2, r3 are registers.
2  Given a new instruction add r3 r1 #n, which means
R[r1] + n -> R[r3]      add immediate
    Write a program to add 1+2+3+4 and store it in R[4].
3  Write a program to transfer data  R[1] -> R[2], R[3] -> R[4].
4  Describe how the operation PC + 1 -> PC  should be performed using the register transfer language.

Week 5.5  Bonus

Write programs for the processor S0  (one-address instruction set) to do the following:
1  Doing the multiplication by repeat addition  C = A * B by adding A, B times.
2  Find the sum of the even integers between 1..10.
3  Write a program to find factorial n.
   fac(n)
     if n == 0 return 1
     else return n * fac(n-1)

Week 6

Write assembly programs of S2 processor for the following tasks.
1  Write a program to find minimum of 4 numbers reside in the memory address 100, 101, 102, 103.
2  Find the sum of odd numbers between 1..21 (1,3,5,..).
3  Find the average of a set of numbers in the array A[0..9].  The integer arithmetic has no decimal point.
4  Construct a table of x^2 in the array x[0..9]  (the result is  x[0] = 0, x[1] = 1, x[2] = 4, ...) 

Week 7

1  write S2 program to reverse the order of element in an array A[0..9].        
2   write S2 program to muliply two numbers (non-negative) n and m by "repeat addition", by adding n, m times.
3   write S2 program to check two arrays AR, BR of the same size of n elements (0..n-1) that all their elements are identical.
4   Solve this equation:  3x^2 + 2x  + 1 = 86, by trying x from 0...n.
Solution to the assignment:   1  reverse    2   mul    3   equal   4   solve

Project 1

Write a report on a study of an instruction of a processor.   The list of processors are:
1) PDP8,  2) VAX,  3)  IBM S/360,  4) Pentium,  5) PowerPC,  6) MIPS R4000,  7) UltraSPARC,  8) Itanium, 
9) ARM processor, 10) Thumb processor, 11) MMX

Hand in the following topics by
1)  Overview of the processor, its organisation. 
2)   Type of instructions, type of data
3)    Some detail of each instruction
4)    Some example of program
5)    Conclusion, including some comment about the processor, such as, it is good for ..., it it different from other in ...

Week 8

Write S2 assembly program to perform the following tasks.
1  Find minimum value from four numbers, named, n1, n2, n3, n4.
2  Find sum of odd number between 1..21
3  Find average of elements in an array A[0..9].
4  Computer a table of x^2 where x is 0..9.  Put it in a table B[0..9].

Project 2

S2 calculator will be the "team" project.  Each student write one special function for this calculator in S2 assembly language. S2 calculator is a "statistical" calculator with many useful functions.  Besides ordinary + - * / (basic four functions), it has random, x^2, x^y, x!,  mod, gcd, fib, x^2+y^2, sum, average.  Surprisingly it has these additional ten functions! :-)

You are to write these functions, called f0..f9
f0  rng   
f1  sq(x)
f2  x!
f3  fib(x)
f4  x^y
f5  x mod y
f6  gcd(x,y)
f7  x^2+y^2 (sum square)
f8  sum(a1..an,n)
f9  average(a1..an,n)

Assignment of project
Each student will do one function.  The number of function f0..f9 will be assigned to students by student_id mod 10. In other words, your five digits ID, takes the last digit (0..9), it is the number of function assigned to you. The deadline for the project 2 is Monday 19 February 2007 at 4pm.  I will implement the calculator and will upload it by the end of this week.  (Friday 9 February 2007).

more detail on the project     
The S2 Calculator Engine    
S2 calculator engine in S2 assembly language
update S2 calculator engine   It is important for the students who got the assignment f8 and f9 to use this version.  The functions f8, f9 cannot be used in mixed with other functions. Please try it on its own one line, like this: >f9 1 2 3 = . 

Tentative projects

1  discussion on computer system
2  concrete study of existing processors
3  assembly language programming
4  study of large computer system of the future
5  (now defunc) Write a simulator of S2 instructions using the following "skeleton" program (sim.txt) .  Each of you implement one instruction.

Readings

Chapter1  Computer structure   (of my new text book)
Chapter3   Computer arithmetic  (my Comp. Arch textbook)
Data Structure  

Tools

S2.1  assembler and simulator
How to use assembler-simulator
Update S2.1 tools
S2 calculator engine in S2 assembly language     s2cal.zip   (completed ! Sat 10 Feb 2007)
S2 package with data structure extension      readme

References

Chongstitvatana, P., "The essence of computer system engineering", in print, 2006.
Chongstitvatana, P., "Computer Architecture: a synthesis approach", 2002.  A copy is available from the library of department of computer engineering, floor 20, Engineering building 4.  I will release part of chapters relevant to the course shortly.
W. Stallings, "Computer organisation and architecture", 6th ed., Prentice-hall, 2003.
Comers, "Essentials of computer architecture", Prentice Hall, 2005.
Katz, "Comtemporary Logic Design", 2nd ed., Prentice Hall, 2005.
My project on computer language (mostly language implementation) Som.

last update  14 Mar 2007