Homework Assignment 1

Computer Organization

Spring, 2013


This homework will be graded out of 100 points. Each written exercise is worth 3 points, for a total of 30 points. Each java exercise is worth 35 points.

Written exercises (due February 20 at class time)

Write your solutions to problems 1-9 on paper.  Use the algorithms presented in class and show your work. Section 2.4 in your book will be helpful.

1. Convert the following numbers to base 7

a.  2401
b.  392
c.  54

2. Convert the following numbers to base -4

a.  145
b.  -56
c.  8123

3. Convert the following numbers to their 32-bit binary representations.  Assume that 2's complement is used for negative numbers.  Express your answers in hexadecimal.

a.  1985
b.  -4000
c.  8192

4. What decimal numbers are represented by the following 32-bit values?  (Again, assume that 2's complement is used for negative numbers.)

a.  0000003D
b.  000010B6
c.  FFFFFABC

5. Patterson & Hennessy, 2.1.1, p. 180.

6. Patterson & Hennessy, 2.3.1, p. 181.

7. Patterson & Hennessy, 2.4.1, p. 181.

8. Patterson & Hennessy, 2.6.1, p. 184.

9. Patterson & Hennessy, 2.8.1, p. 186.

10. Patterson & Hennessy, 2.9.2, p. 187.

Programming problems (due February 21th at 8 pm; use handin)

1.  On the MIPS architecture, machine language instructions are encoded in 32-bit words.  The format for instructions which access memory consists of four fields, as shown below:

MIPS I format

Write a program which takes a MIPS instruction, encoded as a hexadecimal number, as its single command-line argument, and extracts these four fields.  Print each one on a separate line of output.  Print the opcode as a 6-bit binary value (including leading zeros if applicable), the rs and rt fields as decimal integers, and the address in hexadecimal.  For example,

input:

java Mips 68ec871c

output:

opcode:  011010
rs: 7
rt: 12
address:  871c


2.  Write a Java program with one command-line argument, an integer expressed in decimal.  The program should print the number in binary, octal and hexadecimal, then invert the number and print the inverse in binary, octal, decimal, and hexidecimal. Use two's compliment representation.

input:

java Inverse -5

output:

x (base 2):  11111011
x (base 8):   77777773
x (base 16):  fffffffb
x inverted (base 2):  00000101
x inverted (base 8):  00000005
x inverted (base 10):  00000005
x inverted (base 16):  00000005

input:

java Inverse 934892812

output:

x (base 2):  00110111101110010101010100001100
x (base 8):  06756252414
x (base 16):  37b9550c
x inverted (base 2):  111001000010001101010101011110100
x inverted (base 8):  71021525364
x reversed (base 10):  -934892812
x reversed (base 16):  c846aaf4