<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > GNU ARM匯編--(二)匯編編譯鏈接與運行

          GNU ARM匯編--(二)匯編編譯鏈接與運行

          作者: 時間:2016-11-26 來源:網絡 收藏

          [cpp]view plaincopy
          1. CROSS=arm-linux-
          2. CFLAGS=-nostdlib
          3. beep.bin:start.Sbeep.S
          4. ${CROSS}gcc$(CFLAGS)-c-ostart.ostart.S
          5. ${CROSS}gcc$(CFLAGS)-c-obeep.obeep.S
          6. ${CROSS}ld-Tbeep.ldsstart.obeep.o-obeep.elf
          7. ${CROSS}objcopy-Obinary-Sbeep.elfbeep.bin
          8. rm-f*.o
          9. clean:
          10. rm-f*.elf*.o
          11. rm-fbeep.bin

          編譯后將beep.bin文件燒寫到dram中,就可以聽到聲音了.雖然可以運行了,但還是有兩個疑問:

          1.lds編譯鏈接文件的寫法和技巧 //后續(xù)要繼續(xù)追

          2.elf文件的格式 //elf格式是比較新的可執(zhí)行文件格式,目前在很多OS上都是用這種格式.這個格式可以在有操作系統(tǒng)的情況下直接運行,但是對于裸機的情況,必須對elf文件 做objcopy處理 后續(xù)也要繼續(xù)追

          hello world的例子如下:

          helloworld.S:

          [cpp]view plaincopy
          1. .data
          2. msg:.asciz"hello,world"
          3. .text
          4. .align2
          5. .global_start
          6. _start:
          7. ldrr1,=msg@address
          8. movr0,#1@stdout
          9. movr2,#13@length
          10. swi#0x900004@sys_write
          11. movr0,#0
          12. swi#0x900001@sys_exit
          13. .align2

          makefile:

          [cpp]view plaincopy
          1. all:
          2. arm-linux-ashelloworld.S-ohelloworld.o
          3. arm-linux-ldhelloworld.o-ohelloworld

          將elf文件放到跑有l(wèi)inux的arm板子中,運行就輸出hello world.也可以在ubuntu中qemu-arm helloworld模擬.

          對比x86下同樣用系統(tǒng)調用來輸出hello world的程序:

          [cpp]view plaincopy
          1. .data
          2. msg:.string"hello"
          3. len=.-msg
          4. .text
          5. .global_start
          6. _start:
          7. nop
          8. movl$len,%edx
          9. movl$msg,%ecx
          10. movl$1,%ebx
          11. movl$4,%eax
          12. int$0x80
          13. movl$0,%ebx
          14. movl$1,%eax
          15. int$0x80

          它們有幾點不同:

          1.arm是用swi指令來進行軟中斷,陷入內核態(tài)來實現(xiàn)系統(tǒng)調用的.而x86是用int $0x80

          2.x86的系統(tǒng)調用號是用eax寄存器表示的,是第一個參數.而arm的swi直接帶有系統(tǒng)調用號,0x900004是0x900000+4,其中0x900000是base.

          根據google,做了上面的總結,對GNU ARM匯編有了認識,并且對系統(tǒng)調用軟中斷,中斷處理,uboot異常向量表等等有了探究的欲望,也對elf格式和編譯鏈接有了興趣,根據自己的方向和精力,后續(xù)對這些內容做一個或深或淺的學習.


          上一頁 1 2 下一頁

          評論


          技術專區(qū)

          關閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();