计算机组成实验报告0424.docx
《计算机组成实验报告0424.docx》由会员分享,可在线阅读,更多相关《计算机组成实验报告0424.docx(12页珍藏版)》请在冰点文库上搜索。
计算机组成实验报告0424
课程实验报告
课程名称:
计算机组成
实验项目名称:
专业班级:
智能科学与技术1302
姓名:
王家威
学号:
201308070217
指导教师:
赵欢
完成时间:
2015年04月24日
计算机科学与工程系
实验题目:
ubuntu系统下的datalab
实验目的:
修改代码,通过dlc和btest测试
实验环境:
32位ubuntu
实验内容及操作步骤:
首先,大家阅读Readme文件,详细了解实验要求;
其次,本次实验本质上是填写bits.c文件中尚未完成的各个函数的内容。
但是,本实验要求只使用有限数量、规定的操作符。
第三,目录下带了dlc和btest两个工具,用于检测你所写的函数代码格式及功能是否正确(两者的用法在readme中有介绍)。
代码如下:
//*
*CS:
APPDataLab
*
*
*
*bits.c-SourcefilewithyoursolutionstotheLab.
*Thisisthefileyouwillhandintoyourinstructor.
*
*WARNING:
Donotincludetheheader;itconfusesthedlc
*compiler.Youcanstilluseprintffordebuggingwithoutincluding
*,althoughyoumightgetacompilerwarning.Ingeneral,
*it'snotgoodpracticetoignorecompilerwarnings,butinthis
*caseit'sOK.
*/
#if0
/*
*InstructionstoStudents:
*
*STEP1:
Readthefollowinginstructionscarefully.
*/
YouwillprovideyoursolutiontotheDataLabby
editingthecollectionoffunctionsinthissourcefile.
INTEGERCODINGRULES:
Replacethe"return"statementineachfunctionwithone
ormorelinesofCcodethatimplementsthefunction.Yourcode
mustconformtothefollowingstyle:
intFunct(arg1,arg2,...){
/*briefdescriptionofhowyourimplementationworks*/
intvar1=Expr1;
...
intvarM=ExprM;
varJ=ExprJ;
...
varN=ExprN;
returnExprR;
}
Each"Expr"isanexpressionusingONLYthefollowing:
1.Integerconstants0through255(0xFF),inclusive.Youare
notallowedtousebigconstantssuchas0xffffffff.
2.Functionargumentsandlocalvariables(noglobalvariables).
3.Unaryintegeroperations!
~
4.Binaryintegeroperations&^|+<<>>
Someoftheproblemsrestrictthesetofallowedoperatorsevenfurther.
Each"Expr"mayconsistofmultipleoperators.Youarenotrestrictedto
oneoperatorperline.
Youareexpresslyforbiddento:
1.Useanycontrolconstructssuchasif,do,while,for,switch,etc.
2.Defineoruseanymacros.
3.Defineanyadditionalfunctionsinthisfile.
4.Callanyfunctions.
5.Useanyotheroperations,suchas&&,||,-,or?
:
6.Useanyformofcasting.
7.Useanydatatypeotherthanint.Thisimpliesthatyou
cannotusearrays,structs,orunions.
Youmayassumethatyourmachine:
1.Uses2scomplement,32-bitrepresentationsofintegers.
2.Performsrightshiftsarithmetically.
3.Hasunpredictablebehaviorwhenshiftinganintegerbymore
thanthewordsize.
EXAMPLESOFACCEPTABLECODINGSTYLE:
/*
*pow2plus1-returns2^x+1,where0<=x<=31
*/
intpow2plus1(intx){
/*exploitabilityofshiftstocomputepowersof2*/
return(1<}
/*
*pow2plus4-returns2^x+4,where0<=x<=31
*/
intpow2plus4(intx){
/*exploitabilityofshiftstocomputepowersof2*/
intresult=(1<result+=4;
returnresult;
}
FLOATINGPOINTCODINGRULES
Fortheproblemsthatrequireyoutoimplentfloating-pointoperations,
thecodingrulesarelessstrict.Youareallowedtouseloopingand
conditionalcontrol.Youareallowedtousebothintsandunsigneds.
Youcanusearbitraryintegerandunsignedconstants.
Youareexpresslyforbiddento:
1.Defineoruseanymacros.
2.Defineanyadditionalfunctionsinthisfile.
3.Callanyfunctions.
4.Useanyformofcasting.
5.Useanydatatypeotherthanintorunsigned.Thismeansthatyou
cannotusearrays,structs,orunions.
6.Useanyfloatingpointdatatypes,operations,orconstants.
NOTES:
1.Usethedlc(datalabchecker)compiler(describedinthehandout)to
checkthelegalityofyoursolutions.
2.Eachfunctionhasamaximumnumberofoperators(!
~&^|+<<>>)
thatyouareallowedtouseforyourimplementationofthefunction.
Themaxoperatorcountischeckedbydlc.Notethat'='isnot
counted;youmayuseasmanyoftheseasyouwantwithoutpenalty.
3.Usethebtesttestharnesstocheckyourfunctionsforcorrectness.
4.UsetheBDDcheckertoformallyverifyyourfunctions
5.Themaximumnumberofopsforeachfunctionisgiveninthe
headercommentforeachfunction.Ifthereareanyinconsistencies
betweenthemaximumopsinthewriteupandinthisfile,consider
thisfiletheauthoritativesource.
/*
*STEP2:
Modifythefollowingfunctionsaccordingthecodingrules.
*
*IMPORTANT.TOAVOIDGRADINGSURPRISES:
*1.Usethedlccompilertocheckthatyoursolutionsconform
*tothecodingrules.
*2.UsetheBDDcheckertoformallyverifythatyoursolutionsproduce
*thecorrectanswers.
*/
#endif
/*
*bitAnd-x&yusingonly~and|
*Example:
bitAnd(6,5)=4
*Legalops:
~|
*Maxops:
8
*Rating:
1
*/
intbitAnd(intx,inty){
return~(~x|~y);
}
/*
*getByte-Extractbytenfromwordx
*Bytesnumberedfrom0(LSB)to3(MSB)
*Examples:
getByte(0x12345678,1)=0x56
*Legalops:
!
~&^|+<<>>
*Maxops:
6
*Rating:
2
*/
intgetByte(intx,intn){
return((x>>(n<<3))&0x000000ff);
}
/*
*logicalShift-shiftxtotherightbyn,usingalogicalshift
*Canassumethat0<=n<=31
*Examples:
logicalShift(0x87654321,4)=0x08765432
*Legalops:
!
~&^|+<<>>
*Maxops:
20
*Rating:
3
*/
intlogicalShift(intx,intn){
return~(1<<31>>n<<1)&(x>>n);
}
/*
*bitCount-returnscountofnumberof1'sinword
*Examples:
bitCount(5)=2,bitCount(7)=3
*Legalops:
!
~&^|+<<>>
*Maxops:
40
*Rating:
4
*/
intbitCount(intx){
return2;
}
/*
*bang-Compute!
xwithoutusing!
*Examples:
bang(3)=0,bang(0)=1
*Legalops:
~&^|+<<>>
*Maxops:
12
*Rating:
4
*/
intbang(intx){
return1&(~((x|(~x+1))>>31));
}
/*
*tmin-returnminimumtwo'scomplementinteger
*Legalops:
!
~&^|+<<>>
*Maxops:
4
*Rating:
1
*/
inttmin(void){
return1<<31;
}
/*
*fitsBits-return1ifxcanberepresentedasan
*n-bit,two'scomplementinteger.
*1<=n<=32
*Examples:
fitsBits(5,3)=0,fitsBits(-4,3)=1
*Legalops:
!
~&^|+<<>>
*Maxops:
15
*Rating:
2
*/
intfitsBits(intx,intn){
return!
(x^((x<<(~n+33))>>(~n+33)));
}
/*
*divpwr2-Computex/(2^n),for0<=n<=30
*Roundtowardzero
*Examples:
divpwr2(15,1)=7,divpwr2(-33,4)=-2
*Legalops:
!
~&^|+<<>>
*Maxops:
15
*Rating:
2
*/
intdivpwr2(intx,intn){
intsign=x>>31;
intbias=sign&((1<return(x+bias)>>n;
}
/*
*negate-return-x
*Example:
negate
(1)=-1.
*Legalops:
!
~&^|+<<>>
*Maxops:
5
*Rating:
2
*/
intnegate(intx){
return~x+1;
}
/*
*isPositive-return1ifx>0,return0otherwise
*Example:
isPositive(-1)=0.
*Legalops:
!
~&^|+<<>>
*Maxops:
8
*Rating:
3
*/
intisPositive(intx){
return!
(!
x|(x>>31));
}
/*
*isLessOrEqual-ifx<=ythenreturn1,elsereturn0
*Example:
isLessOrEqual(4,5)=1.
*Legalops:
!
~&^|+<<>>
*Maxops:
24
*Rating:
3
*/
intisLessOrEqual(intx,inty){
return2;
}
/*
*ilog2-returnfloor(logbase2ofx),wherex>0
*Example:
ilog2(16)=4
*Legalops:
!
~&^|+<<>>
*Maxops:
90
*Rating:
4
*/
intilog2(intx){
return2;
}
/*
*float_neg-Returnbit-levelequivalentofexpression-ffor
*floatingpointargumentf.
*Boththeargumentandresultarepassedasunsignedint's,but
*theyaretobeinterpretedasthebit-levelrepresentationsof
*single-precisionfloatingpointvalues.
*WhenargumentisNaN,returnargument.
*Legalops:
Anyinteger/unsignedoperationsincl.||,&&.alsoif,while
*Maxops:
10
*Rating:
2
*/
unsignedfloat_neg(unsigneduf){
return2;
}
/*
*float_i2f-Returnbit-levelequivalentofexpression(float)x
*Resultisreturnedasunsignedint,but
*itistobeinterpretedasthebit-levelrepresentationofa
*single-precisionfloatingpointvalues.
*Legalops:
Anyinteger/unsignedoperationsincl.||,&&.alsoif,while
*Maxops:
30
*Rating:
4
*/
unsignedfloat_i2f(intx){
return2;
}
/*
*float_twice-Returnbit-levelequivalentofexpression2*ffor
*floatingpointargumentf.
*Boththeargumentandresultarepassedasunsignedint's,but
*theyaretobeinterpretedasthebit-levelrepresentationof
*single-precisionfloatingpointvalues.
*WhenargumentisNaN,returnargument
*Legalops:
Anyinteger/unsignedoperationsincl.||,&&.alsoif,while
*Maxops:
30
*Rating:
4
*/
unsignedfloat_twice(unsigneduf){
return2;
}
实验结果及分析:
实验分析:
1.正确的通过了8道测试题
收获与体会:
1.在此次实验当中发现自己很多问题,对部分概念还是没有理解透彻,应该加强学习
2.其中第三道的错误问题没有找到原因,在vs2012中运行通过,结果无误,再三寻找问题也没有找到原因,后来在交报告之前突然解决了这问题。
。
。
原来是不能使用减法,细心看题
实
验成绩