# Homework 1

## CMSC 411 / Olano, Spring 2012

1. Design the encoding for an instruction set using a fixed 32-bits per instruction. Your instruction set should include the following instructions:
Instruction Meaning Notes
ADD a, b, c a = b + c a, b and c must all be registers
SUB a, b, c a = b – c; a, b and c must all be registers
NEG a, b a = – b; a and b must be registers
AND a, b, c a = b & c; a, b and c must all be registers
OR a, b, c a = b | c; a, b and c must all be registers
NOT a, b a = ~ b a and b must be registers
SHR a, b, c a = b >> c; a and b must be registers, c can be a register or 16-bit immediate
SHL a, b, c a = b << c; a and b must be registers, c can be a register or 16-bit immediate
MOV a, b a = b; if a is a register, b can be register, indirect or immediate
if a is indirect, b must be a register
JMP a goto a; a can be an address in a register, or a 16-bit immediate offset from the current PC
BEQ a, b if (a == 0) goto b; a must be a register, b must be a 16-bit immediate offset from the current PC
BLT a, b if (a < 0) goto b; a must be a register, b must be a 16-bit immediate offset from the current PC

Design the enoding to allow as many registers as possible. Be sure to clearly state the number of registers in your ISA, and everything we need to know to compute the binary encoding of any legal instruction.
2. Using this instruction set, write the complete assembly code for the following C, assuming the code will be placed starting at address 0x76543210, that the x array starts at 0x11111111, and that the y array starts at 0x22222222.
```for (i=0; i<10; ++i)
x[i] = y[i] + 0x12345678;```
3. Translate your instructions to binary, using your instruction encoding (you can write the final version in binary or hexadecimal)
4. Write the single-precision IEEE floating point encoding (in hexidecimal) for the following numbers: 0, 0.1, 0.5, 0.75, 1, 10, 16777216 (= 224). Note that 0.1 is a repeating binary fraction 0.000112.
5. What is the encoding and decimal representation for the next number larger and smaller than each? You'll probably want to use a program or calculator for the conversion, but be sure to print enough digits to see the differences.
```
```