Assignment 2, Solutions

Part of the homework for 22C:60, Fall 2009
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Problems

  1. Assume your printing device uses the SO and SI control characters to switch from black ink to red. Give the SMAL code to assemble the following text into memory:
        This is a Red Letter day!
    where the words "Red Letter" are printed in red and the string is terminated by a CR followed by an LF. (0.5 points)
    NUL = #00 LF = #0A CR = #0D SI = #0E SO = #0F ASCII "This is a ",SO ASCII "Red Letter",SI ASCII "day!",CR, LF, NUL

  2. Flip a coin 24 times or use any other random process to produce 24 consecutive random bits. Write them down from left to right in two groups of 12 bits.

    1 0 1 1 0 1 0 0 0 1 0 0

    0 1 0 1 1 1 1 0 1 0 0 1

    a) Treat each group as a 12 bit integer and convert it to decimal. (you should check your work by conversion back to binary.) (0.4 points)

    1 0 1 1 0 1 0 0 0 1 0 0 = 288410

    0 1 0 1 1 1 1 0 1 0 0 1 = 151310

    b) Show each binary number you created for the above problem in octal and in hexadecimal. (0.4 points)

    1 0 1 1 0 1 0 0 0 1 0 0 = 55048 = B4416

    0 1 0 1 1 1 1 0 1 0 0 1 = 27518 = 5EA16

    c) Add the two 12-bit binary numbers you created, showing your work. (you should convert the sum to decimal so you can check the result.) (0.4 points)

    1 1 1 1 1 1
      1 0 1 1 0 1 0 0 0 1 0 0 = 288410
      0 1 0 1 1 1 1 0 1 0 0 1 = 151310
    _________________________  _____
    1 0 0 0 1 0 0 1 0 1 1 0 1 = 439710

    d) Take the two 12-bit binary numbers you created and interpret them as numbers in the 12-bit two's complement number system. Because they are random, each has a 50-50 chance of being negative. Give the signed decimal interpretation of each number, then take their two's complements and give the signed decimal interpretation of their complements. (0.4 points)

    1 0 1 1 0 1 0 0 0 1 0 0 = -121210
    0 1 0 0 1 0 1 1 1 1 0 0 = +121210

    0 1 0 1 1 1 1 0 1 0 0 1 = +151310
    1 0 1 0 0 0 0 1 0 1 1 1 = -151310

  3. Assemble the following SMAL code as it would be loaded into the Hawk memory:
              W       #E3882088
              B       #14, #51
              H       #4444
              H       #8A3E, #4442
              W       #E3810441
    
    Write down the results as 4 consecutive words in binary, with both rows and columns of bits neatly aligned in tabular form. If you get it right, a pattern will emerge that spells a message. (0.8 point)
            000000: E3882088   111...111...1.....1.....1...1...
            000004: 44445114   .1...1...1...1...1.1...1...1.1..
            000008: 44428A3E   .1...1...1....1.1...1.1...11111.
            00000C: E3810441   111...111......1.....1...1.....1
    

    I deliberately used . instead of 0 above to make the IOWA stand out.

  4. Get the SMAL assembler to process the above example, print out the assembly listing, and turn it in. This counts as preparation for the first real machine problem. (0.1 point)
            +000000: E3882088            1            W       #E3882088
            +000004: 14  51              2            B       #14, #51
            +000006: 4444                3            H       #4444
            +000008: 8A3E  4442          4            H       #8A3E, #4442
            +00000C: E3810441            5            W       #E3810441