The Easiest Way to Save and Share Code Snippets on the web

Untitled

asm | by: MohamedIBrahi10

last edit: Jan, 26th 2012 | jump to bottom

  1. org 0x7c00 ; This is where BIOS loads the bootloader
  2.  
  3.  
  4. ; Execution begins here
  5. entry:
  6. jmp short begin ; jump over the DOS boot record data
  7.  
  8.  
  9. ; ----------------------------------------------------------------------
  10. ; data portion of the "DOS BOOT RECORD"
  11. ; ----------------------------------------------------------------------
  12. brINT13Flag DB 90H ; 0002h - 0EH for INT13 AH=42 READ
  13. brOEM DB 'MSDOS5.0' ; 0003h - OEM name & DOS version (8 chars)
  14. brBPS DW 512 ; 000Bh - Bytes/sector
  15. brSPC DB 1 ; 000Dh - Sectors/cluster
  16. brResCount DW 1 ; 000Eh - Reserved (boot) sectors
  17. brFATs DB 2 ; 0010h - FAT copies
  18. brRootEntries DW 0E0H ; 0011h - Root directory entries
  19. brSectorCount DW 2880 ; 0013h - Sectors in volume, < 32MB
  20. brMedia DB 240 ; 0015h - Media descriptor
  21. brSPF DW 9 ; 0016h - Sectors per FAT
  22. brSPH DW 18 ; 0018h - Sectors per track
  23. brHPC DW 2 ; 001Ah - Number of Heads
  24. brHidden DD 0 ; 001Ch - Hidden sectors
  25. brSectors DD 0 ; 0020h - Total number of sectors
  26. DB 0 ; 0024h - Physical drive no.
  27. DB 0 ; 0025h - Reserved (FAT32)
  28. DB 29H ; 0026h - Extended boot record sig
  29. brSerialNum DD 404418EAH ; 0027h - Volume serial number (random)
  30. brLabel DB 'Joels disk ' ; 002Bh - Volume label (11 chars)
  31. brFSID DB 'FAT12 ' ; 0036h - File System ID (8 chars)
  32. ;------------------------------------------------------------------------
  33.  
  34.  
  35. ; --------------------------------------------
  36. ; Boot program code begins here
  37. ; --------------------------------------------
  38. ; boot code begins at 0x003E
  39. begin:
  40. xor ax, ax ; zero out ax
  41. mov ds, ax ; set data segment to base of RAM
  42. mov si, msg ; load address of our message
  43. call putstr ; print the message
  44.  
  45. hang:
  46. jmp hang ; just loop forever.
  47.  
  48. ; --------------------------------------------
  49. ; data for our program
  50.  
  51. msg db 'Hello, World!', 0
  52.  
  53. ; ---------------------------------------------
  54. ; Print a null-terminated string on the screen
  55. ; ---------------------------------------------
  56. putstr:
  57. lodsb ; AL = [DS:SI]
  58. or al, al ; Set zero flag if al=0
  59. jz putstrd ; jump to putstrd if zero flag is set
  60. mov ah, 0x0e ; video function 0Eh (print char)
  61. mov bx, 0x0007 ; color
  62. int 0x10
  63. jmp putstr
  64. putstrd:
  65. retn
  66. ;---------------------------------------------
  67.  
  68. size equ $ - entry
  69. %if size+2 > 512
  70. %error "code is too large for boot sector"
  71. %endif
  72. times (512 - size - 2) db 0
  73.  
  74. db 0x55, 0xAA ;2 byte boot signature
63 views