系统级编程作业 lab1解析.docx
- 文档编号:1662499
- 上传时间:2022-10-23
- 格式:DOCX
- 页数:17
- 大小:91.09KB
系统级编程作业 lab1解析.docx
《系统级编程作业 lab1解析.docx》由会员分享,可在线阅读,更多相关《系统级编程作业 lab1解析.docx(17页珍藏版)》请在冰豆网上搜索。
系统级编程作业lab1解析
SystemLevelProgrammingLab
C++fundamentalsandTypeconversion
StudentID_____1043111051________
StudentName王金科_______
StartTime16:
20星期二日2012年09月4FinishTime23:
55星期日09月9日2012年1.Objectives:
TowritesimpleC++programscovering:
?
Understandhowacharacterisstoredinmemory;
?
Understandhowanintegerisstoredinmemory;
?
Understandarrayandpointer;and
?
Performconversionfromeightbits(character)toeightbytestobedisplayedon
screen.
2.TypeandFormatinmemory–character,integer,shortandfloat
2.1
Thisexerciseistodeterminethememorysizeofdifferenttype.
lab1_1.cpp
//Determinethememorysizeofdeclarationandvariabletype
#include
#include
#include
#include
#include
#include
voidmain()
{
charc;
chars[128];
shorti;
shortn[64];
printf(==\n,sizeof(c),sizeof(char));
printf(==\n,sizeof(s),sizeof(char[128]));
printf(==\n,sizeof(i),sizeof(short));
printf(==\n,sizeof(n),sizeof(short[64]));
}
Thedisplayis:
1
--
2018/10/21
SystemLevelProgrammingLab
Nowexecutetheaboveprogramandfillinthefollowing:
Sizeinbit
SizeinbyteType
162Short
81Char
64
512Short[32]
64
512Char[64]
2.2
integer[128],integer,float,theUsetheapproachoftheabove,determinememorysizeof
float[16](lab1_2.cpp)
)]Writeaprogramtoverifyyouranswerandfillinthefollowing:
[hint,usesizeof(…Sizeinbit
TypeSizeinbyte
324Int
324Float
512
4096Int[128]
51264
Float[16]
Writedownyourcodesbelow:
#include
#include
#include
#include
#include
#include
voidmain(){
intc;ints[128];floatI;floatn[16];
printf(“==\n”,sizeof(c),sizeof(int));
printf(“==\n”,sizeof(s),sizeof(int[128]));
printf(“==\n”,sizeof(i),sizeof(float));
printf(“==\n”,sizeof(n),sizeof(float[16]));
}
Writedownyourexpressionamongstthedifferenceinsizebetweencharacter,integer,float,
short,char[8],int[8],short[8],float[8]
Character=1byte
Integer=4bytes
Float=4bytes
Short=2bytes
Char[8]=8bytes
Int[8]=32bytes
Short[8]=16bytes
Float[8]=32bytes
2
--
2018/10/21
SystemLevelProgrammingLab
2.3
Thisexerciseistodisplaythedecimalandoctalvaluessothatyouknowhowitisstoredin
memory.
lab1_3.cpp
//Determinethememorysizeofdeclarationandvariabletype
#include
#include
#include
#include
#include
#include
voidmain()
{
for(chari=30;i<41;++i)
printf(i:
dec=%doct=%o\n,i,i);
}
theoutputis:
well.unsignedashextotheaboveprogrammedisplaydecimal,octal,andmodifyNow
(Hints:
hex,%x,unsigned%u)
Writedownyourcodesbelow:
#include
#include
#include
#include
3
--
2018/10/21
SystemLevelProgrammingLab
#include
#include
voidmain(){
for(chari=30;i<41;++i)
printf(i:
dec=%doct=%ohex=%xunsigned=%u\n,i,i,i,i);}
Writedowntheoutputofthefirst4linessothatyouunderstandthedifferenceamongthem.
i:
dec=30oct=36hex=1eunsigned=30
i:
dec=31oct=37hex=1funsigned=31
i:
dec=32oct=40hex=20unsigned=32
i:
dec=33oct=41hex=21unsigned=33
2.4
Thisexerciseistodumpthecontentofmemoryofdifferenttypesothatyouknowhowitis
storedinmemory.
lab1_4.cpp
//Determinethememorysizeofdeclarationandvariabletype
#include
#include
#include
#include
#include
#include
voidmain()
{
chara='0';//inhex0x30,not0
inti=0x00000013;//indecimalis(1x16+3)=19
shortj=18;//occupiestwobytes,
floatf=1.25;//occupies4bytes
}
Inordertodisplay,youhavetosetabreakpointbypressing“F9”besidetheline,the
programwilldisplayaredcircleasfollows:
4
--2018/10/21
SystemLevelProgrammingLab
Now,typetheaddressofeachvariableasshownintheleft-bottomframetolocatewhether
.Since,visualC++reserves4bytesbuttheyare.Here,wedumptheaddressofvariable‘a'(meansCCtothreeseebyte,youcanthattherestbytesaresetCCCConeccharuses
101010101010101010101010inbinary,thedefaultsetting).
&ais0x0065fdf4,youhavetotype1memorylocationofathenintheAddress,keyin0x0065fdf4,2itdisplays30CCCCCC
3
0x0065FDF4,thehexadecimalis0x30(ASCII)
5
--2018/10/21
SystemLevelProgrammingLab
Now,typeandexecutetheaboveprogramandfillinthefollowing,noteth
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 系统级编程作业 lab1解析 系统 编程 作业 lab1 解析