系统级编程作业 lab1解析文档格式.docx

上传人:b****1 文档编号:14585333 上传时间:2022-10-23 格式:DOCX 页数:17 大小:91.09KB
下载 相关 举报
系统级编程作业 lab1解析文档格式.docx_第1页
第1页 / 共17页
系统级编程作业 lab1解析文档格式.docx_第2页
第2页 / 共17页
系统级编程作业 lab1解析文档格式.docx_第3页
第3页 / 共17页
系统级编程作业 lab1解析文档格式.docx_第4页
第4页 / 共17页
系统级编程作业 lab1解析文档格式.docx_第5页
第5页 / 共17页
点击查看更多>>
下载资源
资源描述

系统级编程作业 lab1解析文档格式.docx

《系统级编程作业 lab1解析文档格式.docx》由会员分享,可在线阅读,更多相关《系统级编程作业 lab1解析文档格式.docx(17页珍藏版)》请在冰豆网上搜索。

系统级编程作业 lab1解析文档格式.docx

and

Performconversionfromeightbits(character)toeightbytestobedisplayedon

screen.

2.TypeandFormatinmemory–character,integer,shortandfloat

2.1

Thisexerciseistodeterminethememorysizeofdifferenttype.

lab1_1.cpp

//Determinethememorysizeofdeclarationandvariabletype

#include<

iostream.h>

stdio.h>

ctype.h>

conio.h>

string.h>

stdlib.h>

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

Nowexecutetheaboveprogramandfillinthefollowing:

Sizeinbit

SizeinbyteType

162Short

81Char

64

512Short[32]

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<

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

2.3

Thisexerciseistodisplaythedecimalandoctalvaluessothatyouknowhowitisstoredin

memory.

lab1_3.cpp

for(chari=30;

i<

41;

++i)

printf(i:

dec=%doct=%o\n,i,i);

theoutputis:

well.unsignedashextotheaboveprogrammedisplaydecimal,octal,andmodifyNow

(Hints:

hex,%x,unsigned%u)

3

voidmain(){

for(chari=30;

41;

++i)

dec=%doct=%ohex=%xunsigned=%u\n,i,i,i,i);

}

Writedowntheoutputofthefirst4linessothatyouunderstandthedifferenceamongthem.

i:

dec=30oct=36hex=1eunsigned=30

i:

dec=31oct=37hex=1funsigned=31

dec=32oct=40hex=20unsigned=32

dec=33oct=41hex=21unsigned=33

2.4

Thisexerciseistodumpthecontentofmemoryofdifferenttypesothatyouknowhowitis

storedinmemory.

lab1_4.cpp

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

Now,typetheaddressofeachvariableasshownintheleft-bottomframetolocatewhether

.Since,visualC++reserves4bytesbuttheyare.Here,wedumptheaddressofvariable‘a'

(meansCCtothreeseebyte,youcanthattherestbytesaresetCCCConeccharuses

101010101010101010101010inbinary,thedefaultsetting).

&

ais0x0065fdf4,youhavetotype1memorylocationofathenintheAddress,keyin0x0065fdf4,2itdisplays30CCCCCC

3

0x0065FDF4,thehexadecimalis0x30(ASCII)

5

Now,typeandexecutetheaboveprogramandfillinthefollowing,noteth

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 经管营销 > 公共行政管理

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1