Computer Organization and Design--计组作业习题(1)
Computer Organization and Design
?
?----------------------個人作業(yè),如果有后輩的作業(yè)習(xí)題一致,可以參考學(xué)習(xí),一起交流,請勿直接copy
Problem 1:
Convert the following decimal values to both binary and hexadecimal representations using 8 bit two’s complement. If you cannot convert to twos complement please explain why.?
?
2310= 00010111two=17hex
?
-1510= 11110001two=F1hex
?
-12810= 10000000two=80hex
?
12810: 關(guān)于 2’s complement,8 bit可以表示的數(shù)值范圍只有【-128,+127】;故128無法用8 bit2’s complement 表示;
?
?
-110= 11111111two=FFhex
?
Problem 2:
?
Convert the following LC2K assembly code into machine code in hex. All unused bits should be 0 and the machine code instructions should be 32 bits long.
?
? ? ? ? ? ? ? add? ????? 1? 2? 3 ? ? ? ? ? ? ? ? ? ? ? ? ? : 0x000A0003
start? ???? lw? ???????? 4? 5? ten ?????????????????????? : 0x00A50004
? ? ? ? ? ? ?beq? ????? 3? 5? start ? ? ? ? ? ? ? ? ? ? ? : 0x011DFFFE
? ? ? ? ? ? ?halt ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? : 0x01800000
ten? ?????? .fill? ??????? 10 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?: 0x0000000A
?
?
Problem 3:?
Convert the following hex numbers to LC2K instructions.
?
0x00550003 ? ? ? ? ? ? ? ? ? ? : nand? 2? 5? 3
?
0x01670000 ???????????????????? : jalr 4?? 7
?
0x00CAFFFF ? ? ? ? ? ? ? ? ? ? ?: sw??? 1?? 2?? -1
?
?
Problem 4:?
Given the following MIPS assembly code (and assuming all registers start at 0):
?
??? ???????? addi ? $1??? $0??? 3
??? ???????? addi?? $2??? $0??? 8
? ? loop?? add?? $1??? $1??? $2
??? ???????? nand? $3??? $1??? $2
??? ???????? addi?? $2??? $2??? -2
??? ???????? bne?? $0??? $2??? loop
?
?
a) Translate the MIPS code into C Code that performs the same operations. Please use the variable names reg1, reg2, and reg3 for $1, $2, and $3.?
?
int reg1, reg2, reg3;
reg1 = 3;
reg2 = 8;??
do
{
?? reg1 = reg1+reg2;
?? reg3 = ~(reg1®2);
?? reg2 = reg2+(-2);
}
while (reg2 !=0);
?
b) How many times is the line, “nand $3, $1, $2” executed?
?? ? 4 times;
c) What is the final value of $3?
??????? -310;
?
Problem 5:?
?
Below is the description of a new, stack-based ISA that only contains one register, REG. The ISA is byte addressable.
?
R-type Instructions?? ???????? bits 7-5: opcode
?? ????????????????????????? bits 4-0: unused
?
?
?
I-type Instructions?? bits 7-5: opcode
?? ???????????????????? bits 4-0: immediate value in 2’s complement form
?
?
?
?
U-type Instructions?? ??????? bits 7-5: opcode
bits 4-2: unused?
bits 1-0: math code
?
?
?
a) Translate the following instructions into machine code. Please write your answers in HEX.
?
?
| Instruction | Machine Code |
| flip | 40 |
| load-2 | 7E |
| ALU. Sub | C1 |
?
b) You are given the following C code that you are to translate into this ISA’s assembly.
a = b nand c
?
Assume that the stack is NOT initially empty and STACK[bottom] = 0.
?
a is located at memory address 10, b is at 20, c is at 30. REG is initially 0. Write your code below.
?
load?? ????? 20
push
load ??????? 30
ALU.Nand
store ????? 10
?
轉(zhuǎn)載于:https://www.cnblogs.com/nanashi/p/6661603.html
總結(jié)
以上是生活随笔為你收集整理的Computer Organization and Design--计组作业习题(1)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【LeetCode】排序
- 下一篇: www的构建技术