fork download
  1. use16
  2. org 0x7c00
  3.  
  4. ; Set stack
  5. mov bp, 0x8000
  6. mov sp, bp
  7.  
  8. ; Load 2nd stage
  9. mov bx, 0x07E0
  10. mov es, bx
  11. mov ds, bx
  12. xor bx, bx
  13.  
  14. mov al, 0x01 ; number of sectors to read
  15. mov ch, 0x00 ; cylinder number
  16. mov cl, 0x02 ; sector number
  17. mov dh, 0x00 ; head number
  18. mov dl, 0x80 ; drive number (using a disk drive in qemu)
  19.  
  20. clc
  21. mov ah, 0x02
  22. int 0x13
  23. jc error ; error handling is omitted, not important & doesnt cause problems
  24.  
  25. jmp 0x07E0:0x00
  26.  
  27. times 510 - ($-$$) db 0
  28. dw 0xaa55
  29.  
  30.  
  31.  
  32. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  33. ; second stage code
  34. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  35.  
  36. use16
  37. org 0x7E00
  38.  
  39. bootsect_second_stage:
  40. ; WITHOUT THIS BIT IT DOESNT WORK...
  41. ; WHY DO I NEED TO SET THE SEGMENT REGISTERS to 0... (and not 0x07E0 for example)?
  42. mov bx, 0
  43. mov ds, bx
  44. mov es, bx
  45. mov fs, bx
  46. mov gs, bx
  47. mov ss, bx
  48.  
  49. call switch_to_protected_mode
  50.  
  51. cli
  52. hlt
  53.  
  54. gdt_start:
  55. gdd_null:
  56. dq 0
  57. gdt_code:
  58. dw 0xFFFF
  59. dw 0
  60. db 0
  61. db 10011010b
  62. db 11001111b
  63. db 0
  64. gdt_data:
  65. dw 0xFFFF
  66. dw 0
  67. db 0
  68. db 10010010b
  69. db 11001111b
  70. db 0
  71. gdt_end:
  72.  
  73. gdt_descriptor:
  74. dw gdt_end - gdt_start - 1
  75. dd gdt_start
  76.  
  77. CODE_SEG equ gdt_code - gdt_start
  78. DATA_SEG equ gdt_data - gdt_start
  79.  
  80. switch_to_protected_mode:
  81. mov bx, switching_to_protected_mode
  82. call print_str
  83.  
  84. cli
  85. lgdt [gdt_descriptor]
  86. mov eax, cr0
  87. or eax, 1
  88. mov cr0, eax
  89.  
  90. jmp CODE_SEG:protected_mode_start
  91. ret ; Should never be reached
  92.  
  93. use32
  94. protected_mode_start:
  95. mov ax, DATA_SEG
  96. mov ds, ax
  97. mov es, ax
  98. mov fs, ax
  99. mov gs, ax
  100. mov ss, ax
  101. mov esp, 090000h
  102.  
  103. ; Write 'A' to the middle of the screen (beginning of the video memory is at 0xB8000)
  104. mov edi, 0xB85EC
  105. mov byte [edi], 'A'
  106. mov edi, 0xB85ED
  107. mov byte [edi], 4
  108.  
  109. hlt
  110.  
  111. times 512 - ($ - $$) db 0
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.s: Assembler messages:
prog.s: Warning: end of file not at end of a line; newline inserted
prog.s:1: Error: no such instruction: `use16'
prog.s:2: Error: no such instruction: `org 0x7c00'
prog.s:4: Error: no such instruction: `set stack'
prog.s:5: Error: too many memory references for `mov'
prog.s:6: Error: too many memory references for `mov'
prog.s:8: Error: no such instruction: `load 2nd stage'
prog.s:9: Error: too many memory references for `mov'
prog.s:10: Error: too many memory references for `mov'
prog.s:11: Error: too many memory references for `mov'
prog.s:12: Error: too many memory references for `xor'
prog.s:14: Error: too many memory references for `mov'
prog.s:14: Error: no such instruction: `number of sectors to read'
prog.s:15: Error: too many memory references for `mov'
prog.s:15: Error: no such instruction: `cylinder number'
prog.s:16: Error: too many memory references for `mov'
prog.s:16: Error: no such instruction: `sector number'
prog.s:17: Error: too many memory references for `mov'
prog.s:17: Error: no such instruction: `head number'
prog.s:18: Error: too many memory references for `mov'
prog.s:18: Error: no such instruction: `drive number (using a disk drive in qemu)'
prog.s:21: Error: too many memory references for `mov'
prog.s:22: Error: operand size mismatch for `int'
prog.s:23: Error: no such instruction: `error handling is omitted,not important&doesnt cause problems'
prog.s:25: Error: junk `:0x00' after expression
prog.s:27: Error: no such instruction: `times 510 - ($-$$)db 0'
prog.s:28: Error: no such instruction: `dw 0xaa55'
prog.s:33: Error: no such instruction: `second stage code'
prog.s:36: Error: no such instruction: `use16'
prog.s:37: Error: no such instruction: `org 0x7E00'
prog.s:40: Error: no such instruction: `without THIS BIT IT DOESN84WORK...'
prog.s:41: Error: no such instruction: `why DO I NEED TO SET THE SEGMENT REGISTERS to 0... (and not 0x07E0 for example)?'
prog.s:42: Error: too many memory references for `mov'
prog.s:43: Error: too many memory references for `mov'
prog.s:44: Error: too many memory references for `mov'
prog.s:45: Error: too many memory references for `mov'
prog.s:46: Error: too many memory references for `mov'
prog.s:47: Error: too many memory references for `mov'
prog.s:56: Error: no such instruction: `dq 0'
prog.s:58: Error: no such instruction: `dw 0xFFFF'
prog.s:59: Error: no such instruction: `dw 0'
prog.s:60: Error: no such instruction: `db 0'
prog.s:61: Error: no such instruction: `db 10011010b'
prog.s:62: Error: no such instruction: `db 11001111b'
prog.s:63: Error: no such instruction: `db 0'
prog.s:65: Error: no such instruction: `dw 0xFFFF'
prog.s:66: Error: no such instruction: `dw 0'
prog.s:67: Error: no such instruction: `db 0'
prog.s:68: Error: no such instruction: `db 10010010b'
prog.s:69: Error: no such instruction: `db 11001111b'
prog.s:70: Error: no such instruction: `db 0'
prog.s:74: Error: no such instruction: `dw gdt_end - gdt_start - 1'
prog.s:75: Error: no such instruction: `dd gdt_start'
prog.s:77: Error: no such instruction: `code_seg equ gdt_code - gdt_start'
prog.s:78: Error: no such instruction: `data_seg equ gdt_data - gdt_start'
prog.s:81: Error: too many memory references for `mov'
prog.s:85: Error: invalid char '[' beginning operand 1 `[gdt_descriptor]'
prog.s:86: Error: too many memory references for `mov'
prog.s:87: Error: too many memory references for `or'
prog.s:88: Error: too many memory references for `mov'
prog.s:90: Error: junk `:protected_mode_start' after expression
prog.s:91: Error: no such instruction: `should never be reached'
prog.s:93: Error: no such instruction: `use32'
prog.s:95: Error: too many memory references for `mov'
prog.s:96: Error: too many memory references for `mov'
prog.s:97: Error: too many memory references for `mov'
prog.s:98: Error: too many memory references for `mov'
prog.s:99: Error: too many memory references for `mov'
prog.s:100: Error: too many memory references for `mov'
prog.s:101: Error: too many memory references for `mov'
prog.s:103: Error: no such instruction: `write 65to the middle of the screen (beginning of the video memory is at 0xB8000)'
prog.s:104: Error: too many memory references for `mov'
prog.s:105: Error: junk `[edi]' after expression
prog.s:105: Error: too many memory references for `mov'
prog.s:106: Error: too many memory references for `mov'
prog.s:107: Error: junk `[edi]' after expression
prog.s:107: Error: too many memory references for `mov'
prog.s:111: Error: no such instruction: `times 512 - ($ - $$)db 0'
stdout
Standard output is empty