COSI 31a: Spring 2009
Problem Set 1

Problem 1

An assembly language program implements the following loop:

sum = 0;
for(i = 0; i < 100; i++)
    sum = sum + 1;

The program stores the resulting sum into memory location x+1000, where x is the address of the memory location where the assembly program is loaded. Write the assembly program using the assembly language introduced in class.

Problem 2

Assume again an assembly program that has been loaded into a memory location x.

Assume the memory location x+1000 stores the memory address of an array that contains 100 consecutive integers (4 bytes each). Write the assembly program that sets all the elements of the array to zero.

Problem 3

Disk locations d, d+4, d+8 .. contain a list of non-zero integers corresponding to quiz grades. The list is terminated by an integer that is equal to zero.

Write an assembly program that computes quiz grade average. Show two implementations:

  1. one that corresponds to Java while loop that checks the loop condition at the entrance to the loop; and,
  2. another that corresponds to Java do-while loop that checks the loop condition at the end of the loop.

Problem 4

The machine instruction:

br FIXED_MEM_DEST

causes the computer to execute its next instruction from memory location FIXED_MEM_DEST. What are the detailed steps of the ALU and/or control unit to execute this instruction? Provide the same steps for the conditional branch instruction:

bleq R1, R2, loop

Problem 5

Assume that it takes an average of 2.5 clock cycles to execute an instruction in a one-address machine language introduced in class (that is, each individual instruction can reference at most one memory location). Estimate the number of clock cycles it would take to execute the following loop if the code is compiled without optimization (explain your answer):

for(i=0; i<100; i++)
    a[i] = 0;

Hint: consider the Assembly Language equivalent you wrote in problem (2) first.