suomeksi Homework

Computer Organization I, Fall 2001, HW 2

To be presented in week 45, 6-8.11.2001
  1. High level language vs. assemble language. Assume that we have program Simple that is written with some high level language (C, Java, Pascal), and that it has been translated into TTK-91 machine language.
    1. What data in program Simple (e.g., variable values) would one want to keep in device registers all the time during program execution? Why? Give examples.
    2. What data in program Simple would one want to keep in memory all the time during program execution? Why? Give examples.
    3. What data in program Simple would one want to keep in sometimes in device registers and sometimes in memory during program execution? Why? Give examples.
    4. What data in program Simple does not need to be anywhere during program execution? Why? Give examples. (This is not a trick question!)

     

  2. Write a ttk-91 symbolic assembly language program that does the same as C program
            int x=7, y=3, z=5;  /* variables x, y, z */
            main () {           /* main program */
                y = 4;
                x = 52 - y * z;
                if (x < 40) {
                    y = x - 34;
                    }
                else {
                    y = x / y + 4;
                    z = 23;
                    }
                printf ( "%d %d %d \n", x, y, z)  /* print x, y, z */
            }
    

    Check your program by compiling and running it in Koksi.

     

  3. Write a ttk-91 symbolic assembly language program that computes the n'th Fibonacci number. Your program could be a translation from C program
            int n, i, prev, fib, next;  /* variables n, i, prev, fib, next */
            main () {                   /* main program */
                scanf ("%d", &n); /* read n */
    
                i = 1;
                prev = 0;
                fib = 1; 
                
                while (i < n) {
                    next = prev+fib;
                    prev = fib;
                    fib = next;
                    
                    i = i+1;
                    }
    
                printf ( "%d %d \n", n, fib);  /* print n, fib */
            }
    

    You can keep variable values either in memory or in device registers.
    Check your program by compiling and running it in Koksi.

     

  4. Constants (e.g., value MAXID=78) can locate in many different places during program execution. Write ttk-91 symbolic assembly language instructions with which one would add constant MAXID value to R1, and where MAXID value (78) is taken from
    1. memory (memory location)
    2. register
    3. machine instruction

    Give an example where case (a) would be best suitable. Similarly, for cases (b) and (c). Give reasoning for your examples.

  5. Personnel register record type has been defined with pseudoinstructions
    	# record person:        3 integer fields 
    	Id   	EQU  0   # relative address within record
    	Age     EQU  1
    	Salary  EQU  2
    

    Records Pekka and Jussi have been allocated from memory with initialized data and record Maija has been allocated with uninitialized data with pseudoinstructions

    	Pekka	DC   3214   # ID     =  3214
    		DC     35   # AGE    =    35
     		DC  12345   # SALARY = 12345
    	Jussi	DC   8888
    		DC     54
     		DC  14321
    	Maija	DS      3   # initial values not defined

    Example: If R4 points to the beginning of record Pekka, then Pekka's salary is obtained to register R5 with machine instruction "LOAD   R5, Salary(R4)".

    Write a ttk-91 symbolic assembly language program to

    1. Print the values of all fields in the record pointed by R1, when R1 is first set to point to Jussi's record with machine instruction "LOAD   R1, =Jussi".
    2. Sets Maija's id to 6666, age to 32, and salary to the same as what Jussi has currently.
    3. Print the sum of Pekka's, Jussi's and Maija's current salary.
    4. Print the current age of the youngest person of these three.

Check your program by compiling and running it in Koksi.

 

Be prepared to show all Koksi related homeworks using a PC at the practice session. Please bring both a listing and on a diskette all the programs you made for this practice session.
Teemu Kerola