aComputer Organization and Assembly Language
Fall 2006

Homework #1  Homework #2  Homework #3  Homework #4  Final Project

Homework #1

dDescription:

 

Write a program that computes k primes in ascending order (i.e., 2, 3, 5, 7, … ), where k is given by user. ØThe prime is assumed in the form of 32-bit unsigned integer. The I/O of your program is

Input: k (# of primes to be generated), where k>0

Output: k primes (starting from 2) in ascending order. The output primes are separated by a line break. That is,

           2

           3

           5

           7

           .... 

n

 

Deadline: Due on 11/9, beginning of class

n

 

Submission: Closed.

n

 

Grading: Bonus points will be added for those with good algorithms and/or performance analysis. Note that nplagiary is not allowed (a demonstration to TA will be required then.) A penalty of 20% is assessed for each day late.

n

Grades: http://www.csie.ntu.edu.tw/~pjcheng/course/asm2006/submit.html

Statistics: http://www.csie.ntu.edu.tw/~pjcheng/course/asm2006/hw1_statistics.png

Homework #2

dDescription:

 

Write a program that performs basic arithmetic, including addition, subtract, multiplication, and division, of large integers. Large integers are numbers that are significantly larger than those ordinarily used in our life. They are widely used in many fields such as cryptography. The program is required to handle signed decimal numbers with more than 15 digits and behave like a calculator with the ability to deal with complex arithmetic expressions, e.g. (A+B)*C/D. If the result of integer division is a real number a.b, just truncate b so that the result is still an integer (like the definition of '/' for integers in C). Note that the program is not allowed to use the floating-point instructions and the ASCII and packed/unpacked decimal arithmetic instructions introduced in Chapter 8, that is, AAA, AAS, AAM, AAD, DAA and DAS. The I/O of your program is

 

Input: arithmetic expressions with $ as the end character.  For example, (A+B)*C/D$.

          The signed numbers (i.e., A, B, C and D) may be more than 15 decimal digits.

Output: the signed answer of the expression

 

Hint: To evaluate an arithmetic expression, one possible solution is to use two stacks: one for numbers (number stack) and the other for operators (operator stack). Going from left to right, if you see a number, push it on the number stack. If you see an operator x,

        while the top of the operator stack, y, holds an operator of equal or higher precedence (compared with x)

        begin
                pop operator y 
                pop the top two values from the number stack and apply operator  y to them

                push the result on the number stack
        end

        push operator x on the operator stack
At the end, perform any remaining operations on both stacks

 

To handle parentheses, when you see a left parenthesis, (, treat it as a low-priority operator, and just put it on the operator stack. When you see a right parenthesis , ), perform all the operations on the operator stack until you reach the corresponding left parenthesis; then remove the left parenthesis.

 

For example, suppose the input is 1+2*3-5/(3+4)$ Your program might scan it from left to right and evaluate the expression by the following steps, where nstack stands for the number stack, pstack stands for the operator stack, and pr(op)=operator op's preference.

 

    (nstack: empty; pstack: empty)

    1 : push 1 on nstack  (nstack: 1; pstack: empty)
    + : push + on pstack (nstack: 1; pstack: +)
    2:  push 2 on nstack  (nstack: 1,2; pstack: +)
    * : because pr(+)<pr(*), push * on pstack (nstack: 1,2; pstack: +,*)

    3:  push 3 on nstack  (nstack: 1,2,3; pstack: +,*)
    -:  because pr(*)>pr(-), pop * from pstack, pop 3, 2 from nstack, compute 2*3=6, push 6 on nstack (nstack: 1,6; pstack: +)

        because pr(+)>pr(-) (while loop),  pop + from pstack, pop 6, 1 from nstack, compute 1+6=7, push 7 on nstack (nstack: 7; pstack: empty)

        push - on pstack  (nstack: 7; pstack: -)

    5: push 5 on nstack  (nstack: 7,5; pstack: -)

     /: because pr(-)<pr(/), push / on pstack (nstack: 7,5; pstack: -,/)

     (: just push '(' on pstack (nstack: 7,5; pstack: -,/,'(')

    3: push 3 on nstack  (nstack: 7,5,3; pstack: -,/,'(')

    +: because pr('(')<pr(+), push + on pstack (nstack: 7,5,3; pstack: -,/,'(',+)

    4: push 4 on nstack (nstack: 7,5,3,4; pstack: -,/,'(',+)

     ): pop + from pstack, pop 4,3 from nstack, compute 3+4=7, push 7 on nstack, pop '(' from pstack (nstack: 7,5,7; pstack: -,/)

    $:  end of the expression, pop / from pstack, pop 7,5 from nstack, compute 5/7=0, push 0 on nstack (nstack: 7,0; pstack: -)

        pop - from pstack, pop 0,7 from nstack, compute 7-0=7, push 7 on nstack (nstack: 7; pstack: empty)

        the answer is 7 (the one on nstack)

         

nn

Deadline: Due on 12/14, beginning of class

n

 

Submission: Closed.

n

 

Grading: Bonus points will be added for those with good algorithms and/or performance analysis. Note that nplagiary is not allowed (a demonstration to TA will be required then.) A penalty of 20% is assessed for each day late.

n

Grades: TBA

Statistics: TBA

Homework #3

dDescription:

 

Write a program that sorts a string array in ascending order based on the quicksort algorithm. There are 5000 strings at most and each string has no more than 16 characters. String comparison acts like the definition of the strcmp function. You are suggested to implement your codes based on the template of http://www.csie.ntu.edu.tw/~pjcheng/course/asm2006/asm_prog/quicksort.zip. Suppose your execution file is a.exe. The I/O of your program is

 

Input: a.exe < infile

         The format of infile looks like (the input strings are separated by a line break):

         TW University

         Dept.of CSIE

         Assembly

    

Output: the sorted strings in ascending order (the output strings are also separated by a line break):

         Assembly

         Dept.of CSIE

         TW University

         

nn

Deadline: Due on 12/28, beginning of class.

n

 

Submission: Closed.

 

Grading: Bonus points will be added for those with good algorithms and/or performance analysis. Note that nplagiary is not allowed (a demonstration to TA will be required then.) A penalty of 20% is assessed for each day late.

n

Grades: TBA

Statistics: TBA

Homework #4

dDescription:

 

Write a very simple game, brick, as shown below in real mode. In this game, a player uses the left and right arrow keys to move a paddle back and forth along the bottom of the screen, bouncing a ball back into the upper field. A score counting # of bounces is shown. The problem should provide the functions of play, pause and stop. Bonus points will be given for other interesting features. For example, one could play more than one ball, change the speed of the ball, break bricks by the ball, show the timers, add sound effects, etc. 

 

n

 

Deadline: Due on 1/15

n

 

Submission: Submit your source code and a report to http://www.csie.ntu.edu.tw/~pjcheng/course/asm2006/submit.html

n

 

Grading: Bonus points will be added for those with other features (see the suggestions in the description). Note that nplagiary is not allowed (a demonstration to TA will be required then.) A penalty of 20% is assessed for each day late.

n

Grades: TBA

Statistics: TBA