CSE 378 HomeWork 2

Winter 2003, Due: Wednesday 1/15/03

Part A - Binary Representations of Data and Binary Arithmetic

Purpose

Questions

  1. Suppose each of the following decimal integers is repesented in 8-bit two's complement. How many bits are one in the binary representation?
    Example: 5 (= 00000101) ==> 2 (bits are one)
    1. 8
    2. -8
    3. -15
    4. 147

  2. Convert the following decimal numbers to their single-precision floating point equivalents. Give both the exponential and binary encoded representation.
    Remember that the mantissa is biased and that the leading 1-bit of the significand is implicit (not stored).
    Example: 2.12510 = 10.0012 = 1.00012 x 21, whose single precision representation is 0 10000000 00010000000000000000000
    1. -1
    2. 0
    3. 950.5
    4. 0.95

  3. Suppose you want to represent "A message!" as a C-string (a null terminated array of ASCII characters, stored one per byte) starting in memory location 0.
    1. How many bytes do you need to use, at minimum?
    2. Show the contents of the memory used to hold this string, in hex. (Assume memory is byte addressable. There is a table of the ASCII character codes on page 142 of the text.)

Part B - Machine and Assembly Code

Purpose

Exercises

  1. Write a program for the SSI-0 machine that is functionally equivalent to
    	int	 A[5] = {-1, 0, 1, 2, 4};
    	int	 x;
    
    	x = A[0] - A[1] + A[2] - A[3] + A[4];
    
    You will encounter the usual problem that there's no way to gracefully end a program in SSI-0. To handle that for now, add a STOP instruction to the SSI-0 ISA (with opcode 3 and no operands).
    1. Show the contents of memory when your program is loaded, but before execution begins. Assume the PC starts at 0 and the machine is about to execute cycle number 0.
    2. Show the contents of memory after 5 cycles (that is, after five instructions have been executed.)

    Hint:First figure out how to invert an integer in SSI-0, then write the code for this program.

  2. Write a second program for SSI-0 that computes the length of a (null terminated) string stored in locations 0x11-0xFF. The string is stored as one ASCII character per word. (While 239 words of memory are reserved for storing the string, it's current length may be anything from 0 to 238.) Put the result in location 0x10.
    1. Show the contents of memory when your program is loaded, but before execution begins. Assume the PC starts at 0 and the machine is about to execute cycle number 0.
    2. Show the contents of memory after 8 cycles (that is, after eight instructions have been executed.)

    Hint:Memory is just memory. The only thing that makes the contents of a memory location an instruction is that it was fetched to be used as an instruction.

  3. Write a program for the SSI-2 architecture that is functionally equivalent to the following C code. (This code computes a single element of the "convolution" of two vectors of integers.)
             int*    vec1;
    	int*    vec2;
    	int     N;
    	int     index;
    	int     result;
    
    	result = 0;
    	for (index=0; index<N; index++) {
    	    result += vec1[index]*vec2[N-1-index];
             }
    
    Assume that when your program is loaded into memory, vec1 and vec2 are initialized to point at two integer vectors (arrays) of N elements each, and that the PC is initialized to 0.

    Give your program in assembly language - you don't need to translate it into machine code. (Plus, you can use labels, which is an enormous help as you're developing the program!)  Don't be too worried about the details of syntax - no machine will be running your program.