歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Linux匯編寫引導扇區

Linux匯編寫引導扇區

日期:2017/3/1 10:52:12   编辑:Linux編程

最近再看《Orange‘s一個操作系統的實現》,裡面用的是intel的匯編語法,自己比較習慣AT&T的語法了,自己研究了好長時間才將代碼修改成功。

  1. .code16
  2. .section.text
  3. .globl_start
  4. _start:
  5. movw%cs,%ax
  6. movw%ax,%ds
  7. movw%ax,%es
  8. callDispStr
  9. loop1:jmploop1
  10. DispStr:
  11. movw$BootMessage,%ax
  12. movw%ax,%bp
  13. movw$0x10,%cx
  14. movw$0x1301,%ax
  15. movw$0xc,%bx
  16. movb$0,%dl
  17. int$0x10
  18. ret
  19. BootMessage:.ascii "Hello, OS world!"
  20. .org510
  21. .word0xAA55

.code16指示as生成16位的代碼。While `as' normally writes only "pure" 32-bit i386 code or 64-bit x86-64 code depending on the default configuration, it also supports writing code to run in real mode or in 16-bit protected mode code segment.

編譯的話 as -o boot.o boot.s ;

ld -Ttext=0x7c00 --oformat binary -o boot.bin boot.o;

這樣就ok了~~

Copyright © Linux教程網 All Rights Reserved