Inline Assembly in GCC Vs VC

Inline Assembly in GCC Vs VC

ID:40081492

大小:182.32 KB

页数:10页

时间:2019-07-20

Inline Assembly in GCC Vs VC  _第1页
Inline Assembly in GCC Vs VC  _第2页
Inline Assembly in GCC Vs VC  _第3页
Inline Assembly in GCC Vs VC  _第4页
Inline Assembly in GCC Vs VC  _第5页
资源描述:

《Inline Assembly in GCC Vs VC 》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库

1、InlineAssemblyinGCCVsVC++ByGurvinderSingh,20Oct2003�Introduction�介绍InlineAssemblyisdifferentinVC++andgcc.VCusesIntelsyntaxwhilegccusesAT&Tsyntax.HerewedefinethedifferenceinsyntaxofAT&TandIntel'sassembly.VC++和gcc的内联汇编是不同的。VC使用intel汇编语法格式,而gcc使用AT&T语法格式。这里我们简略说说这两种语法格式的不同。�So

2、urceandDestinationOrdering�原操作数和目标操作数的位置顺序InAT&Tsyntaxthesourceisalwaysontheleft,andthedestinationisalwaysontherightwhichisoppositeoftheIntel'ssyntax.在AT&T中,原操作数始终在左边,目标操作数始终在右边。而intel格式中恰恰相反(即原操作数始终在右边,目标操作数始终在左边);AT&TIntelMoveebxtoeaxmovl%ebx,%eaxmoveax,ebxMove100toebxMov

3、l$100,%ebxMovebx,100�Prefixes/SuffixesforregisternamingandImmediateValues�寄存器以及立即数的前缀和后缀Registernamesareprefixedwith"%"inAT&TwhileinIntelsyntaxtheyarereferencedasis.InAT&Tsyntax$isprefixedtoalltheimmediatevalueswhilenoprefixisrequiredinIntel'sformat.InIntelsyntaxhexadecimal

4、orbinaryimmediatedataaresuffixedwith'h'and'b'respectively.Alsoifthefirsthexadecimaldigitisaletterthena'0'prefixesthevalue.在AT&T格式中,寄存器必须加上前缀"%",而intel的没有这个要求。在AT&T中格式,立即数必须加上前缀"$",而intel的没有这个要求。在intel格式中,十六进制和二进制格式的立即数会分别以'h'和'b'为后缀,如果十六进制数的第一位数字是字母的话,号必须加上'0'前缀。InAT&Tthein

5、structionsaresuffixedbyb,w,orl,dependingonwhethertheoperandisabyte,word,orlong.ThisisnotmandatoryasGCCtriestoprovidetheappropriatesuffixbyreadingtheoperands.Butitisrecommendedtoprovidethesuffixesasitimprovescodereadabilityanditpreventscompilerfrommakingamistakewhileguessing

6、.TheequivalentformsforIntelisbyteptr,wordptr,anddwordptronlywhenreferencingmemory在AT&T中,会根据操作数的大小是字节,双字节还是四字节分别在指令后面加上字母b,w和l。当然,这对以gcc来说不是强制性的,因为gcc可以根据读取的操作数实际大小自动添加合理的后缀。不过,我们还是推荐通过添加后缀来增强程序的可读性,也避免当编译器必须猜测操作数大小时而犯的错误。这种方法在intel语法格式中是通过byteptr,wordptr和dwordptr来实现的。AT&TIn

7、telRegisters%eax%ebx%ecxeaxebxecxedx%edxMoveebxtoeaxmovl%ebx,%eaxmoveax,ebxMoveFFinebxmovl$0xff,%ebxmovebx,0ffh�AccessingvariablesfrominsideInlineASM�在内联汇编中访问变量Foraccessingvaluesofglobalvariablesanunderscorehastobeprefixedinbothcases.Letssayxisaglobalorstaticvariable.InInte

8、l'sformat_xgivespointertothevariablewhile[_x]givesitsvalue.InAT&Tformat$_xgivesthe

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。