知识大全 Linux汇编指南

Posted 指南

篇首语:青,取之于蓝而青于蓝;冰,水为之而寒于水。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 Linux汇编指南相关的知识,希望对你有一定的参考价值。

Linux汇编指南  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!

  摘要:The following is designed to be a Linux equivalent to Developing Assembly Language Programs on a PC by Douglas V Hall This tutorial requires the following:   Introduction       The following is designed to be a Linux equivalent to Developing Assembly Language Programs on a PC by Douglas V Hall This tutorial requires the following:       an i family PC running Linux       as the GNU assembler (included with any gcc installation) ld the GNU linker (also included with gcc) gdb the GNU debugger The tutorial was developed on a Redhat Linux installation running a version kernel and the version and C language libraries with ELF file format But I have tried to make the tutorial as general possible with respect to Linux systems I highly remend working through this tutorial with as and gdb documentation close at hand       Overview       The process of developing an assembly program under linux is somewhat different from development under NT In order to acmodate object oriented languages which require the piler to create constructor and destructor methods which execute before and after the execution of main the GNU development model embeds user code within a wrapper of system code In other words the user s main is treated as a function call An advantage of this is that user is not required to initialize segment registers though user code must obey some function requirements       The Code       The following is the Linux version of the average temperature program It will be referred to as average s Note: Assembly language programs should use the s suffix     /* linux version of AVTEMP ASM CS fall */   data /* beginning of data segment */  /* hi_temp data item */   type hi_temp @object /* declare as data object */   size hi_temp /* declare size in bytes */  hi_temp:   byte x /* set value */  /* lo_temp data item */   type lo_temp @object   size lo_temp   lo_temp:   byte x   /* av_temp data item */   type av_temp @object   size av_temp   av_temp:   byte   /* segment registers set up by linked code */  /* beginning of text(code) segment */   text   align /* set double word alignment */   globl main /* make main global for linker */   type main @function /* declare main as a function */  main:   pushl %ebp /* function requirement */   movl %esp %ebp /* function requirement */   movb hi_temp %al   addb lo_temp %al   movb $ %ah   adcb $ %ah   movb $ %bl   idivb %bl   movb %al av_temp   leave /* function requirement */   ret /* function requirement */      assembly instructions      This code may be assembled with the following mand:     as a gstabs o average o average s       The a option prints a memory listing during assembly This output gives the location variables and code with respect to the beginnings of the data and code segments gstabs places debugging information in the executable (used by gdb) o specifies average o as the output file name (the default is a out which is confusing since the file is not executable )       The object file (average o) can then be linked to the Linux wrapper code in order to create an executable These files are crt o crti o and crtn o crt o and crti o provide initialization code and crtn o does cleanup These should all be located in /usr/lib be may be elsewere on some systems They and their source might be located by executing the following find mand:       find / name crt* print       The link mand is the following:     ld m elf_i static /usr/lib/crt o /usr/lib/crti o    lc average o /usr/lib/crtn o        m elf_i instructs the linker to use the ELF file format static cause static rather than dynamic linking to occur And lc links in the standard c libraries (libc a) It might be necessary to include I/libdirectory in the invocation for ld to find the c library       It will be necessary to change the mode of the resulting object file with chmod +x /a out       It should now be possible to execute the file But of course there will be no output       I remend placing the above mands in a makefile       debugging       The gstabs option given to the assembler allows the assembly program to be debugged under gdb The first step is to invoke gdb:       gdb /a out       gdb should start with the following message:     [bjorn@pomade src]$ gdb /a out      GNU gdb       Copyright Free Sofare Foundation Inc GDB is free sofare covered by the GNU General Public License and you are      wele to change it and/or distribute copies of it under certain conditions Type show copying to see the conditions       There is absolutely no warranty for GDB Type show warranty for details       This GDB was configured as i redhat linux       (gdb)       The l mand will list the program sourcecode       (gdb) l     /* linux version of AVTEMP ASM CS fall */   data /* beginning of data segment */      /* hi_temp data item */   type hi_temp @object /* declare as data object */   size hi_temp /* declare size in bytes */   hi_temp:   byte x /* set value */      /* lo_temp data item */  (gdb)       The first thing to do is set a breakpoint so it will be possible to step through the code     (gdb) break main  Breakpoint at x f   (gdb)       This sets a breakpoint at the beginning of main Now run the program     (gdb) run  Starting program: /home/bjorn/src/ /a out   Breakpoint main () at average s:    movb hi_temp %al  Current language: auto; currently asm  (gdb)       values in registers can be checked with either info registers     (gdb) info registers  eax x   ecx xbffffd   edx x   ebx x bf   esp xbffffdd xbffffdd   ebp xbffffdd xbffffdd   esi x   edi x   eip x f x f   eflags x   cs x   ss x b   ds x b   es x b   fs x b   gs x b   (gdb)        or p/x $eax which prints the value in the EAX register in hex The e in front of the register name indicates a bit register The Intel x family has included extended bit registers since the These E registers are to the X registers as the L and H are to the X registers Linux also uses a flat and protected memory model rather that segmentation thus the EIP stores the entire current address     (gdb cha138/Article/program/Oracle/201311/16623

相关参考

知识大全 Linux 中 x86 的内联汇编

Linux中x86的内联汇编  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  作者BharataB

知识大全 一起学习在linux下使用汇编语言(3)

  作者luster  摘要:NeideAsseblerProject计划提供了一个非常好用的i汇编器这个汇编器是用C写的可以支持很多种对象文件格式  今天我们接着看看还有其他什么可以选择的汇编编译器

知识大全 一起学习在linux下使用汇编语言(5)

  作者luster  摘要:好吧我们已经铺垫了很多东西了而且看上去用汇编写程序似乎是一个非常恐怖的事情了不过既然我们感兴趣还是应该开始我们的helloworld程序  我们开始写helloworld

知识大全 Linux拨号服务快速指南

Linux拨号服务快速指南  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  作者HKILL    

知识大全 基于 Linux 和 MiniGUI 的嵌入式系统软件开发指南(七)

基于Linux和MiniGUI的嵌入式系统软件开发指南(七)  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看

知识大全 基于 Linux 和 MiniGUI 的嵌入式系统软件开发指南(六)

基于Linux和MiniGUI的嵌入式系统软件开发指南(六)  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看

知识大全 基于 Linux 和 MiniGUI 的嵌入式系统软件开发指南(八)

基于Linux和MiniGUI的嵌入式系统软件开发指南(八)  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看

《会计改革与发展“十四五”规划纲要》提出,持续完善企业会计准则体系的建设与实施,需要根据国内实务发展和国际趋同需要,定期更新( )、应用指南汇编,研究制定企业会计准则解释,研究修订会计科目和报表格式。

会计改革与发展十四五规划题目:《会计改革与发展“十四五”规划纲要》提出,持续完善企业会计准则体系的建设与实施,需要根据国内实务发展和国际趋同需要,定期更新()、应用指南汇编,研究制定企业会计准则解释,

某局机关正在组织人力编辑一本《文件汇编》,其页数需要用6869个数字,请问,这本《文件汇编》具体是多少页

某局机关正在组织人力编辑一本《文件汇编》,其页数需要用6869个数字,请问,这本《文件汇编》具体是多少页?A、1994B、1968C、1942D、1886答案:A解析:1-9页需要9个数字;10-99

演员张三从摄影师李四为自己摄影的照片中选择了200张,汇编成摄影影集,并由出版社出版,该汇编作品的作者是演员张三本人。_

演员张三从摄影师李四为自己摄影的照片中选择了200张,汇编成摄影影集,并由出版社出版,该汇编作品的作者是演员张三本人。_____答案:正确解析:《著作权法》第14条规定,汇编若干作品、作品的片段或者不