资源描述:
《研究报告三(王爽汇编语言使用内存空间研究实验)》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、研究实验三研究报告王艳芬2012/4/3在这个试验中,主要研究对于内存空间的使用。①首先编写书中的第一个程序,编译连接。在DOS中观察main的汇编代码。ulfa53A:01FA55PUSHBP53A:01FB8BECMOVBP,SP53A:01FDC606002061MOVBVTEPTR[20001,6153A:0202C70600200F00MOVWORDPTR[2000],000F53A:0208BB0020MOVBX,200053A:020B8EC3MOVES,BX53A:020DBB0010MOVBX,100053A:021026ES:53A:0211C6
2、0761MOVBVTEPTR[BX],6153A:0214B80020MOVAX,200053A:02178BD8MOVBXfX53A:0219C60762MOVBVTEPTR[BX],62153A:021CBB0010MOVBX,1000153A:021F03DBADDBX,BX153A:0221C60761MOVBVTEPTR[BX],61153A:02248BD8MOVBXfX153A:02268A07MOVAL,[BX]153A:022833C9XORCX,CX153A:022A81C30010ADDBX,1000153A:022E81D10020ADCCX
3、,2000153A:02328EC1MOVES,CX153A:023426ES:153A:02358807MOV[BX1,AL153A:02375DPOPBP153A:0238C3RET153A:0239C3RET观察发现char型数据占用一个字节,int型数据占用两个字节。用far指明内存空间的地址是段地址和偏移地址时,汇编语言会将段地址放在es中,偏移地址放在bx中。相应内存单元的地址的内容用[bx]表示(如*(char*)_AX=,b,对应的汇编代码为movbx,axmovbyteptr[bx],62。进行地址的相加时,运用了儿次加法指令,然后将段地址放入es
4、。疑问:为什刍会生成bak备份文件_②编写显示a的程序,c语句如下*(intfar*)0x0b8000410=0x0261运行结果如K:如果去掉far则只会显示偏移地址01,1UUWORDPTR[01fi6],00RlWORDPTR[01fi8],00R2WORDPTR[01fiR],00R3±J.U±lUUJLUUU153A:0200C706A601A100MOV153A:0206C706A801A200MOV153A:020CC706AA01A300MOV153A:0212C746FAB100153A:0217C746FCB200MOVMOVWORDPTRWOR
5、DPTRIBP-061,00B1IBP-041,00B2153A:021CC746FEB300MOVWORDPTRIBP-021,00B3153A:02218BE5MOVSP,BP153A:02235DPOPBP1530:0224C3RET通过观察汇编代码,可知全局变量放在内存单元ds:[036]开始的内存中,所冇的函数都可以访问;局部变量放在栈屮。‘pushbpmovbp,sp'因为有局部变量,用到栈用到bp,借助栈传递参数,可以借助bp。疑问:为什么在编译吋会出现警告?④返回值放在了哪里?153A:01FA55PUSHBP153A:01FB8BECMOVBP,S
6、P153A:01FD83EC02SUBSP,-02153A:0200E80700CALL020A153A:02038946FEMOV[BP-02],AX153A:02068BE5MOVSP,BP153A:02085DPOPBP153A:0209C3RET153A:020A55PUSHBP153A:020B8BECMOVBP,SP153A:020DA1A601MOVAXJ01A61153A:02100306A801ADDAXJ01A81153A:0214R3RR01MOV[01RR],RX153A:0217R1RR01MOVAXJ01AA1山汇编代码可知返回值通过ax
7、传递,最后放在了栈中。如果返回单字节的数据,用什么传递。编程如下:L_111charf();main(){charc;c=f();charf(){,,returneeJ;}代码如下ucuuy1•J貝J-ulfa153A:01FA55PUSHBP153A:01FB8BECMOVBP,SP153A:01FD83EC02SUBSP,-02153A:0200E80700CALL020R153A:02038846FFMOV[BP-01],RL153A:02068BE5MOVSP,BP153A:02085DPOPBP可知char型数据用al传递四个字节时如何返冋呢编程如下: