CSAPP 六个重要实验 lab1

2024-06-06 09:48
文章标签 实验 重要 六个 lab1 csapp

本文主要是介绍CSAPP 六个重要实验 lab1,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

CSAPP && lab1



--------------------------------------------------------------------实验要求--------------------------------------------------------------------

The Bit Puzzles


                             This section describes the puzzles that you will be solving in bits.c. More complete (and definitive, should there be any inconsistencies) documentation is found in the bits.c file itself.
 
Bit Manipulations
                 The table below describes a set of functions that manipulate and test sets of bits. The Rating column gives the difficulty rating (the number of points) for each puzzle and the Description column states the desired output for each puzzle along with the constraints. See the comments in bits.c for more details on the desired behavior of the functions. You may also refer to the test functions in tests.c. These are used as reference functions to express the correct behavior of your functions, although they don't satisfy the coding rules for your functions.
 


Two's Complement Arithmetic


                    The following table describes a set of functions that make use of the two's complement representation of integers. Again, refer to the comments in bits.c and the reference versions in tests.c for more information.
 


 

-------------------------------------------------------------------以上为实验要求-------------------------------------------------------------




实验材料: bits.c

/* * CSE 351 HW1 (Data Lab )* * <Please put your name and userid here>* * bits.c - Source file with your solutions to the Lab.*          This is the file you will hand in to your instructor.** WARNING: Do not include the <stdio.h> header; it confuses the dlc* compiler. You can still use printf for debugging without including* <stdio.h>, although you might get a compiler warning. In general,* it's not good practice to ignore compiler warnings, but in this* case it's OK.  */#if 0
/** Instructions to Students:** STEP 1: Read the following instructions carefully.*/You will provide your solution to this homework by
editing the collection of functions in this source file.INTEGER CODING RULES:Replace the "return" statement in each function with oneor more lines of C code that implements the function. Your code must conform to the following style:int Funct(arg1, arg2, ...) {/* brief description of how your implementation works */int var1 = Expr1;...int varM = ExprM;varJ = ExprJ;...varN = ExprN;return ExprR;}Each "Expr" is an expression using ONLY the following:1. Integer constants 0 through 255 (0xFF), inclusive. You arenot allowed to use big constants such as 0xffffffff.2. Function arguments and local variables (no global variables).3. Unary integer operations ! ~4. Binary integer operations & ^ | + << >>Some of the problems restrict the set of allowed operators even further.Each "Expr" may consist of multiple operators. You are not restricted toone operator per line.You are expressly forbidden to:1. Use any control constructs such as if, do, while, for, switch, etc.2. Define or use any macros.3. Define any additional functions in this file.4. Call any functions.5. Use any other operations, such as &&, ||, -, or ?:6. Use any form of casting.7. Use any data type other than int.  This implies that youcannot use arrays, structs, or unions.You may assume that your machine:1. Uses 2s complement, 32-bit representations of integers.2. Performs right shifts arithmetically.3. Has unpredictable behavior when shifting an integer by morethan the word size.EXAMPLES OF ACCEPTABLE CODING STYLE:/** pow2plus1 - returns 2^x + 1, where 0 <= x <= 31*/int pow2plus1(int x) {/* exploit ability of shifts to compute powers of 2 */return (1 << x) + 1;}/** pow2plus4 - returns 2^x + 4, where 0 <= x <= 31*/int pow2plus4(int x) {/* exploit ability of shifts to compute powers of 2 */int result = (1 << x);result += 4;return result;}FLOATING POINT CODING RULESFor the problems that require you to implent floating-point operations,
the coding rules are less strict.  You are allowed to use looping and
conditional control.  You are allowed to use both ints and unsigneds.
You can use arbitrary integer and unsigned constants.You are expressly forbidden to:1. Define or use any macros.2. Define any additional functions in this file.3. Call any functions.4. Use any form of casting.5. Use any data type other than int or unsigned.  This means that youcannot use arrays, structs, or unions.6. Use any floating point data types, operations, or constants.NOTES:1. Use the dlc (data lab checker) compiler (described in the handout) to check the legality of your solutions.2. Each function has a maximum number of operators (! ~ & ^ | + << >>)that you are allowed to use for your implementation of the function. The max operator count is checked by dlc. Note that '=' is not counted; you may use as many of these as you want without penalty.3. Use the btest test harness to check your functions for correctness.4. Use the BDD checker to formally verify your functions5. The maximum number of ops for each function is given in theheader comment for each function. If there are any inconsistencies between the maximum ops in the writeup and in this file, considerthis file the authoritative source./** STEP 2: Modify the following functions according the coding rules.* *   IMPORTANT. TO AVOID GRADING SURPRISES:*   1. Use the dlc compiler to check that your solutions conform*      to the coding rules.*   2. Use the BDD checker to formally verify that your solutions produce *      the correct answers.*/#endif
// Rating: 1
/* * bitAnd - x&y using only ~ and | *   Example: bitAnd(6, 5) = 4*   Legal ops: ~ |*   Max ops: 8*   Rating: 1*/
int bitAnd(int x, int y) {return 2;
}
/* * bitXor - x^y using only ~ and & *   Example: bitXor(4, 5) = 1*   Legal ops: ~ &*   Max ops: 14*   Rating: 1*/
int bitXor(int x, int y) {return 2;
}
/* * thirdBits - return word with every third bit (starting from the LSB) set to 1*   Legal ops: ! ~ & ^ | + << >>*   Max ops: 8*   Rating: 1*/
int thirdBits(void) {return 2;
}
// Rating: 2
/* * fitsBits - return 1 if x can be represented as an *  n-bit, two's complement integer.*   1 <= n <= 32*   Examples: fitsBits(5,3) = 0, fitsBits(-4,3) = 1*   Legal ops: ! ~ & ^ | + << >>*   Max ops: 15*   Rating: 2*/
int fitsBits(int x, int n) {return 2;
}
/* * sign - return 1 if positive, 0 if zero, and -1 if negative*  Examples: sign(130) = 1*            sign(-23) = -1*  Legal ops: ! ~ & ^ | + << >>*  Max ops: 10*  Rating: 2*/
int sign(int x) {return 2;
}
/* * getByte - Extract byte n from word x*   Bytes numbered from 0 (LSB) to 3 (MSB)*   Examples: getByte(0x12345678,1) = 0x56*   Legal ops: ! ~ & ^ | + << >>*   Max ops: 6*   Rating: 2*/
int getByte(int x, int n) {return 2;
}
// Rating: 3
/* * logicalShift - shift x to the right by n, using a logical shift*   Can assume that 0 <= n <= 31*   Examples: logicalShift(0x87654321,4) = 0x08765432*   Legal ops: ~ & ^ | + << >>*   Max ops: 20*   Rating: 3 */
int logicalShift(int x, int n) {return 2;
}
/* * addOK - Determine if can compute x+y without overflow*   Example: addOK(0x80000000,0x80000000) = 0,*            addOK(0x80000000,0x70000000) = 1, *   Legal ops: ! ~ & ^ | + << >>*   Max ops: 20*   Rating: 3*/
int addOK(int x, int y) {return 2;
}
/* invert - Return x with the n bits that begin at position p inverted *          (i.e., turn 0 into 1 and vice versa) and the rest left *          unchanged. Consider the indices of x to begin with the low-order*          bit numbered as 0.*   Example: invert(0x80000000, 0, 1) = 0x80000001,*            invert(0x0000008e, 3, 3) = 0x000000b6,*   Legal ops: ! ~ & ^ | + << >>*   Max ops: 20*   Rating: 3  */
int invert(int x, int p, int n) {return 2;
}
// Rating: 4
/* * bang - Compute !x without using !*   Examples: bang(3) = 0, bang(0) = 1*   Legal ops: ~ & ^ | + << >>*   Max ops: 12*   Rating: 4 */
int bang(int x) {return 2;
}
// Extra Credit: Rating: 3
/* * conditional - same as x ? y : z *   Example: conditional(2,4,5) = 4*   Legal ops: ! ~ & ^ | + << >>*   Max ops: 16*   Rating: 3*/
int conditional(int x, int y, int z) {return 2;
}
// Extra Credit: Rating: 4
/** isPower2 - returns 1 if x is a power of 2, and 0 otherwise*   Examples: isPower2(5) = 0, isPower2(8) = 1, isPower2(0) = 0*   Note that no negative number is a power of 2.*   Legal ops: ! ~ & ^ | + << >>*   Max ops: 20*   Rating: 4*/
int isPower2(int x) {return 2;
}







对于这种神级bit operation还不能hold住,有些函数并未实现, 欢迎交流讨论 : D

我的解:(update 2015.10.10 原来的solution优点不规范,删了,以托管到github的为准)

https://github.com/jasonleaster/CSAPP/blob/master/lab1/bits.c


激吻 海耶兹 法国 布面油画 1859年 121×97cm 私人收藏
    
这幅画表现的是一对情侣在走廊间深吻的场景。画面构图简单,画家把人物安排在画面正中央,突显了主题。用笔细腻,女子身上的蓝色长裙光彩熠熠,蕾丝边的袖口优雅婉转。裙摆的褶皱在光线的照射下质感极强,女子的婀娜多姿被表现得淋漓尽致。男子暗红色的外袍和红色的裤子色彩对比和谐。暗黄的光线通过情侣投射在墙上,为画面铺上一层深情温馨的气息。 尽管这幅作品并非裸体绘画,但一直被评论家们认为是他的代表作之一。这幅作品在当时就引人注目,引起同时代人们的广泛尊重。作品所表现的内容是匿名人物,它并不需要什么深奥的文学解读便可以看得懂。该画最有味道的地方,也是画面构思最好的地方,是男子的左腿蹬在了一个台阶上,所有的感觉 都来源于这里。 正一艺术认为,这幅作品具有震撼的美感和强烈的现代意识。



这篇关于CSAPP 六个重要实验 lab1的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1035761

相关文章

STM32(十一):ADC数模转换器实验

AD单通道: 1.RCC开启GPIO和ADC时钟。配置ADCCLK分频器。 2.配置GPIO,把GPIO配置成模拟输入的模式。 3.配置多路开关,把左面通道接入到右面规则组列表里。 4.配置ADC转换器, 包括AD转换器和AD数据寄存器。单次转换,连续转换;扫描、非扫描;有几个通道,触发源是什么,数据对齐是左对齐还是右对齐。 5.ADC_CMD 开启ADC。 void RCC_AD

HNU-2023电路与电子学-实验3

写在前面: 一、实验目的 1.了解简易模型机的内部结构和工作原理。 2.分析模型机的功能,设计 8 重 3-1 多路复用器。 3.分析模型机的功能,设计 8 重 2-1 多路复用器。 4.分析模型机的工作原理,设计模型机控制信号产生逻辑。 二、实验内容 1.用 VERILOG 语言设计模型机的 8 重 3-1 多路复用器; 2.用 VERILOG 语言设计模型机的 8 重 2-1 多

Cmake之3.0版本重要特性及用法实例(十三)

简介: CSDN博客专家、《Android系统多媒体进阶实战》一书作者 新书发布:《Android系统多媒体进阶实战》🚀 优质专栏: Audio工程师进阶系列【原创干货持续更新中……】🚀 优质专栏: 多媒体系统工程师系列【原创干货持续更新中……】🚀 优质视频课程:AAOS车载系统+AOSP14系统攻城狮入门视频实战课 🚀 人生格言: 人生从来没有捷径,只有行动才是治疗恐惧

研究生生涯中一些比较重要的网址

Mali GPU相关: 1.http://malideveloper.arm.com/resources/sdks/opengl-es-sdk-for-linux/ 2.http://malideveloper.arm.com/resources/tools/arm-development-studio-5/ 3.https://www.khronos.org/opengles/sdk/do

平时工作学习重要注意的问题

总体原则:抓住重点,条理清晰,可回溯,过程都清楚。 1 要有问题跟踪表,有什么问题,怎么解决的,解决方案。 2 要有常用操作的手册,比如怎么连sqlplus,一些常用的信息,保存好,备查。

matlab一些基本重要的指令

重点内容 运行MATLAB的帮助demo,在Command Window 输入 “demo”,或在Launch Pad 选项卡“demos” 任何时候都可以: 清除Command Window内容:clc 清除Figure Window(图形窗口) clf 清除workspace 变量内容: clear 注意:M脚本文件和输入指令中的变量都在workspace中,为避免变量冲突,一般在

61.以太网数据回环实验(4)以太网数据收发器发送模块

(1)状态转移图: (2)IP数据包格式: (3)UDP数据包格式: (4)以太网发送模块代码: module udp_tx(input wire gmii_txc ,input wire reset_n ,input wire tx_start_en , //以太网开始发送信

Post-Training有多重要?一文带你了解全部细节

1. 简介 随着LLM学界和工业界日新月异的发展,不仅预训练所用的算力和数据正在疯狂内卷,后训练(post-training)的对齐和微调方法也在不断更新。InstructGPT、WebGPT等较早发布的模型使用标准RLHF方法,其中的数据管理风格和规模似乎已经过时。近来,Meta、谷歌和英伟达等AI巨头纷纷发布开源模型,附带发布详尽的论文或报告,包括Llama 3.1、Nemotron 340

LTspice模拟CCM和DCM模式的BUCK电路实验及参数计算

关于BUCK电路的原理可以参考硬件工程师炼成之路写的《 手撕Buck!Buck公式推导过程》.实验内容是将12V~5V的Buck电路仿真,要求纹波电压小于15mv. CCM和DCM的区别: CCM:在一个开关周期内,电感电流从不会到0. DCM:在开关周期内,电感电流总会到0. CCM模式Buck电路仿真: 在用LTspice模拟CCM电路时,MOS管驱动信号频率为100Khz,负载为10R(可自

HCIA--实验十:路由的递归特性

递归路由的理解 一、实验内容 1.需求/要求: 使用4台路由器,在AR1和AR4上分别配置一个LOOPBACK接口,根据路由的递归特性,写一系列的静态路由实现让1.1.1.1和4.4.4.4的双向通信。 二、实验过程 1.拓扑图: 2.步骤: (下列命令行可以直接复制在ensp) 1.如拓扑图所示,配置各路由器的基本信息: 各接口的ip地址及子网掩码,给AR1和AR4分别配置