Docsity

Computer Organization - Problem Set 2 | COMP 411, Assignments of Computer Architecture and Organization

Toggle sidebar
bg1
Comp 411 – Fall 2007 - 1 - Problem Set #2
The U
NIVERSITY
of
N
ORTH
C
AROLINA
at
C
HAPEL
H
ILL
Comp 411 Computer Organization
Fall 2007
Problem Set #2
Issued Wednesday, 9/5/07; Due Thursday, 9/12/07
Homework Information: Some of the problems are probably too long to be done the night
before the due date, so plan accordingly. Late homework will not be accepted. Feel free to get
help from others, but the work you hand in should be your own.
Problem 1. “Some Assembly Required”
The conversion of a mnemonic instruction to its binary representation is called assembly. This
tedious process is generally delegated to a computer program for a variety of reasons. The first is
that it alleviates the need to keep track of all the various bit encodings for each type of
instruction. A second reason is that frequently the precise encoding of an instruction cannot be
determined in a single pass. This is particularly true when referencing labels. In the following
exercises, you will get a taste of what the task of translating from assembly to machine language
is like.
Give binary and hexadecimal encodings for the following instructions:
(A) sll $0, $0, 0
(B) addi $4, $0, 2
(C) add $2, $0, $4
(D) and $3, $2, $4
(E) ori $3, $2, 1
(F) sra $3, $2, 8
(G) lui $2, 0xfeed
(H) ori $2, $2, 0xface
(I) loop: bne $t0,$0,loop
Problem 2. “Diss Assembly”
The inverse of assembly is disassembly, which involves translating an encoded binary instruction
into its mnemonic representation. The process involves breaking an instruction into its constitute
fields and decoding each instruction part.
For each of the following 32-bit numbers, given in hexadecimal, decode the corresponding MIPS
instruction mnemonics, or otherwise indicate that it is an illegal instruction.
(A) 0x2002fff0
(B) 0x00021822
(C) 0x8c440010
(D) 0x00021100
(E) 0x28850010
(F) 0x3042000f
(G) 0x3c03c0de
pf3

Partial preview of the text

Download Computer Organization - Problem Set 2 | COMP 411 and more Assignments Computer Architecture and Organization in PDF only on Docsity!

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

Comp 411 Computer Organization Fall 2007

Problem Set # Issued Wednesday, 9/5/07; Due Thursday, 9/12/

Homework Information: Some of the problems are probably too long to be done the night before the due date, so plan accordingly. Late homework will not be accepted. Feel free to get help from others, but the work you hand in should be your own.

Problem 1. “Some Assembly Required”

The conversion of a mnemonic instruction to its binary representation is called assembly. This tedious process is generally delegated to a computer program for a variety of reasons. The first is that it alleviates the need to keep track of all the various bit encodings for each type of instruction. A second reason is that frequently the precise encoding of an instruction cannot be determined in a single pass. This is particularly true when referencing labels. In the following exercises, you will get a taste of what the task of translating from assembly to machine language is like.

Give binary and hexadecimal encodings for the following instructions:

(A) sll $0, $0, 0 (B) addi $4, $0, 2 (C) add $2, $0, $ (D) and $3, $2, $ (E) ori $3, $2, 1 (F) sra $3, $2, 8 (G) lui $2, 0xfeed (H) ori $2, $2, 0xface (I) loop: bne $t0,$0,loop

Problem 2. “Diss Assembly”

The inverse of assembly is disassembly, which involves translating an encoded binary instruction into its mnemonic representation. The process involves breaking an instruction into its constitute fields and decoding each instruction part.

For each of the following 32-bit numbers, given in hexadecimal, decode the corresponding MIPS instruction mnemonics, or otherwise indicate that it is an illegal instruction.

(A) 0x2002fff (B) 0x (C) 0x8c (D) 0x (E) 0x (F) 0x3042000f (G) 0x3c03c0de

Problem 3. “Faking it”

MIPS assembly language provides opcode mnemonics for instructions that are not part of the instruction set architecture. For the most part, these pseudoinstructions can be generated using a sequence of one or more “true” MIPS instructions.

Find a “true-instruction” equivalent for each of the following pseudo-instructions (some are official MIPS pseudoinstructions, others are made up). Each of these can be implemented using only one real MIPS instruction. Discuss of your implementations, if any, and whether or not your implementation is unique (i.e. could some other instruction be used to achieve the same effect).

(A) move rA, rB Reg[rA] ← Reg[rB] Move register rB to rA

(B) neg rA, rB Reg[rA] ← -Reg[rB] Put the negative of register rB into register rA

(C) not rA, rB Reg[rA] ← ~Reg[rB] Put the bitwise complement of register rB into register rA

(D) pow2 rA, rB Reg[rA] ← 2 rB Load register rA with 2 raised to the power specified by rB

(E) dec rA Reg[rA] ← Reg[rA] - 1 Subtract 1 from rA and place result in rA

(F) sign rA,rB if (Reg[rB] < 0) Reg[rA] ← - else Reg[rA] ← 0 Set rA to -1 if rB is negative, otherwise set rB to 0

Problem 4. “Loading up at the Store”

The MIPS ISA provides access to memory exclusively through load (lw) and store (sw) instructions. Both instructions are encoded using the I-format, thus providing three operands, two registers and a 16-bit sign-extended constant. The memory address is computed by adding the contents of the register specified in the rs register field to the sign-extended 16-bit constant. The contents of the specified memory location are either loaded in the register specified in rt instruction field (lw), or the contents of that register are stored the indicated memory location (sw).

(A) It is possible to “directly” address a limited range of 32-bit memory locations by encoding the rs field as $0. How many memory locations can be addressed this way? Is this range of memory locations contiguous?