华中科技大学计算机系统基础实验报告

2018-12-25 23:47

课程实验报告

课程名称:计算机系统基础

专业班级: 学号: 姓名: 指导教师:

报告日期:2016年5月 24日

计算机科学与技术学院

1

目录

实验1: ...................................................................................................... 2 实验2: ...................................................................................................... 9 实验3: .................................................................................................... 23 实验总结 ................................................................................................... 32

2

实验1: 数据表示

1.1 实验概述

本实验的目的是更好地熟悉和掌握计算机中整数和浮点数的二进制编码表示。

实验中,你需要解开一系列编程“难题”——使用有限类型和数量的运算操作实现一组给定功能的函数,在此过程中你将加深对数据二进制编码表示的了解。 实验语言:c; 实验环境: linux

1.2 实验内容

需要完成 bits.c 中下列函数功能,具体分为三大类:位操作、补码运算和浮点数操作。

1.3 实验设计

源码如下: /*

* lsbZero - set 0 to the least significant bit of x * Example: lsbZero(0x87654321) = 0x87654320 * Legal ops: ! ~ & ^ | + <<>> * Max ops: 5 * Rating: 1 */

int lsbZero(int x) {

//x右移一位再左移一位实现把最低有效位置0 x = x>>1; x = x<<1; return x; } /*

* byteNot - bit-inversion to byte n from word x * Bytes numbered from 0 (LSB) to 3 (MSB)

* Examples: getByteNot(0x12345678,1) = 0x1234A978 * Legal ops: ! ~ & ^ | + <<>> * Max ops: 6 * Rating: 2

1

*/

int byteNot(int x, int n) {

//x第n个字节每位都和1异或实现取反 int y = 0xff; n = n<<3; y = y<

* byteXor - compare the nth byte of x and y, if it is same, return 0, if not, return 1

* example: byteXor(0x12345678, 0x87654321, 1) = 1 *

byteXor(0x12345678, 0x87344321, 2) = 0

* Legal ops: ! ~ & ^ | + <<>> * Max ops: 20 * Rating: 2 */

int byteXor(int x, int y, int n) {

//把x和y的第n个字节取出来异或,再转换为逻辑的0和1 n = n<<3; x = x>>n; y = y>>n; x = x&(0xff); y = y&(0xff); return !!(x^y); } /*

* logicalAnd - x && y * Legal ops: ! ~ & ^ | + <<>> * Max ops: 20 * Rating: 3 */

2

int logicalAnd(int x, int y) {

//把x和y分别转化为逻辑的0和1,再相与 x = (!(!x))&(!(!y)); return x; } /*

* logicalOr - x || y

* Legal ops: ! ~ & ^ | + <<>> * Max ops: 20 * Rating: 3 */

int logicalOr(int x, int y) {

//把x和y分别转化为逻辑的0和1,再相或 x = (!(!x))|(!(!y)); return x; } /*

* rotateLeft - Rotate x to the left by n * Can assume that 0 <= n <= 31

* Examples: rotateLeft(0x87654321,4) = 0x76543218 * Legal ops: ~ & ^ | + <<>> ! * Max ops: 25 * Rating: 3 */

int rotateLeft(int x, int n) {

//先构造低n位为1,高(32-n)位为0的数z,x左移n位后的数加上x右移(32-n)位的数&z即可 int z;

z = ~(((1<<31)>>31)<>(32+(~n+1)))&z)+(x<

* parityCheck - returns 1 if x contains an odd number of 1's * Examples: parityCheck(5) = 0, parityCheck(7) = 1

3


华中科技大学计算机系统基础实验报告.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:计算机组装与调试报告 - 图文&nbsp;-

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: