1

Maybe i'm stupid and doesn't know something but i think i'm doing it right. I have two files one boot.asm, second code.asm. At boot.asm i just enable video mode fill screen with blue color and try to load code located at two seconds sectors, but when i try it nothing just happen and can't get out what i'm doing wrong, maybe i reading wrong or code.asm is wrong coded or boot.asm is wrong coded. Why i can't call code stored in two second sectors to complete them.

For more information i going to load this code from MBR and i want to my code call code at two second sectors because i can't fit them all in one sector, so i asking this question.

boot.asm

;bootloader
  bits 16
  org 0x7c00

;Here i try to load code located at second two sectors
Load_Code:    
    ;---Setup segments
    xor ax, ax                  ; AX=0
    mov ds, ax                  ; DS=ES=0 because we use an org of 0x7c00 - Segment<<4+offset = 0x0000<<4+0x7c00 = 0x07c00
    mov ax, es
    mov ax, ss
    mov sp, 0x7c00              ; SS:SP= 0x0000:0x7c00 stack just below bootloader

  ;---Read 2 sectors
  mov bx, buffer              ; ES: BX must point to the buffer
  mov dh,0                    ; head number
  mov ch,0                    ; track number
  mov cl,2                    ; sector number
  mov al,2                    ; number of sectors to read
  mov ah,2                    ; read function number
  int 13h

;Graphics mode
Set_Video:
  mov ax, 12h        ; Graphics mode (640x480x16)
  int 10h            ; BIOS draw function

  mov ah, 06h        ; Scroll up function
  xor al, al         ; Clear entire screen
  xor cx, cx         ; Upper left corner CH=row, CL=column
  mov dx, 3FFFh      ; fill whole screen
  mov bh, 11h        ; blue background 
  int 10h            ; BIOS draw function
  call buffer

;Endless loop
.endloop:
  hlt
  jmp .endloop


;Fake MBR signature
MBR_Signature:
  times 510 - ($ - $$) db 0
  dw 0xAA55

buffer:

code.asm - second two sectors that contains this code - (this is just example code)

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 0          ; x co-ordinate
mov dx, 0          ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 1          ; x co-ordinate
mov dx, 1          ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 2          ; x co-ordinate
mov dx, 2          ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 3          ; x co-ordinate
mov dx, 3          ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 4          ; x co-ordinate
mov dx, 4          ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 5          ; x co-ordinate
mov dx, 5          ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 6          ; x co-ordinate
mov dx, 6          ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 7          ; x co-ordinate
mov dx, 7          ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 8          ; x co-ordinate
mov dx, 8          ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 9          ; x co-ordinate
mov dx, 9          ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 10         ; x co-ordinate
mov dx, 10         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 11         ; x co-ordinate
mov dx, 11         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 12         ; x co-ordinate
mov dx, 12         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 13         ; x co-ordinate
mov dx, 13         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 14         ; x co-ordinate
mov dx, 14         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 15         ; x co-ordinate
mov dx, 15         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 16         ; x co-ordinate
mov dx, 16         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 17         ; x co-ordinate
mov dx, 17         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 18         ; x co-ordinate
mov dx, 18         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 19         ; x co-ordinate
mov dx, 19         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 20         ; x co-ordinate
mov dx, 20         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 21         ; x co-ordinate
mov dx, 21         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 22         ; x co-ordinate
mov dx, 22         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 23         ; x co-ordinate
mov dx, 23         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 24         ; x co-ordinate
mov dx, 24         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 25         ; x co-ordinate
mov dx, 25         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 26         ; x co-ordinate
mov dx, 26         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 27         ; x co-ordinate
mov dx, 27         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 28         ; x co-ordinate
mov dx, 28         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 29         ; x co-ordinate
mov dx, 29         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 30         ; x co-ordinate
mov dx, 30         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 31         ; x co-ordinate
mov dx, 31         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 32         ; x co-ordinate
mov dx, 32         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 33         ; x co-ordinate
mov dx, 33         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 34         ; x co-ordinate
mov dx, 34         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 35         ; x co-ordinate
mov dx, 35         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 36         ; x co-ordinate
mov dx, 36         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 37         ; x co-ordinate
mov dx, 37         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 38         ; x co-ordinate
mov dx, 38         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 39         ; x co-ordinate
mov dx, 39         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 40         ; x co-ordinate
mov dx, 40         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 41         ; x co-ordinate
mov dx, 41         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 42         ; x co-ordinate
mov dx, 42         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 43         ; x co-ordinate
mov dx, 43         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 44         ; x co-ordinate
mov dx, 44         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 45         ; x co-ordinate
mov dx, 45         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 46         ; x co-ordinate
mov dx, 46         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 47         ; x co-ordinate
mov dx, 47         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 48         ; x co-ordinate
mov dx, 48         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 49         ; x co-ordinate
mov dx, 49         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 50         ; x co-ordinate
mov dx, 50         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 51         ; x co-ordinate
mov dx, 51         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 52         ; x co-ordinate
mov dx, 52         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 53         ; x co-ordinate
mov dx, 53         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 54         ; x co-ordinate
mov dx, 54         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 55         ; x co-ordinate
mov dx, 55         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 56         ; x co-ordinate
mov dx, 56         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 57         ; x co-ordinate
mov dx, 57         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 58         ; x co-ordinate
mov dx, 58         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 59         ; x co-ordinate
mov dx, 59         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 60         ; x co-ordinate
mov dx, 60         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 61         ; x co-ordinate
mov dx, 61         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 62         ; x co-ordinate
mov dx, 62         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 63         ; x co-ordinate
mov dx, 63         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 64         ; x co-ordinate
mov dx, 64         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 65         ; x co-ordinate
mov dx, 65         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 66         ; x co-ordinate
mov dx, 66         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 67         ; x co-ordinate
mov dx, 67         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 68         ; x co-ordinate
mov dx, 68         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 69         ; x co-ordinate
mov dx, 69         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 70         ; x co-ordinate
mov dx, 70         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 71         ; x co-ordinate
mov dx, 71         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 72         ; x co-ordinate
mov dx, 72         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 73         ; x co-ordinate
mov dx, 73         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 74         ; x co-ordinate
mov dx, 74         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 75         ; x co-ordinate
mov dx, 75         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 76         ; x co-ordinate
mov dx, 76         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 77         ; x co-ordinate
mov dx, 77         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 78         ; x co-ordinate
mov dx, 78         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 79         ; x co-ordinate
mov dx, 79         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 80         ; x co-ordinate
mov dx, 80         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 81         ; x co-ordinate
mov dx, 81         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 82         ; x co-ordinate
mov dx, 82         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 83         ; x co-ordinate
mov dx, 83         ; y co-ordinate
int 10h            ; BIOS draw function

mov al, 15         ; color - white
mov ah, 0ch        ; set pixel
mov cx, 84         ; x co-ordinate
mov dx, 84         ; y co-ordinate
int 10h            ; BIOS draw function

ret
times 1024 - ($ - $$) db 0x00

How it look like in hex.

  • 1
    Nothing obviously wrong at first glance. Use a debugger. Also, add error handling. Furthermore, add some ending and if you want to troubleshoot loading then don't mess with graphics. I have done that and it seems to work as expected. – Jester Aug 01 '18 at 22:17
  • 1
    `buffer` doesn't end with a `ret` to return to the pointer after the `call` – Michael Petch Aug 01 '18 at 22:25
  • 2
    Also noticed that all your segment register settings are reversed `mov ax, ds` should be `mov ds,ax` same thing applies for es and ss. – Michael Petch Aug 01 '18 at 22:34
  • 1
    Use a debugger to single-step this; BOCHS has one built-in. – Peter Cordes Aug 01 '18 at 22:36
  • i don't understood where i have to add `ret` it in `boot.asm` or `code.asm`? –  Aug 01 '18 at 22:36
  • 2
    You also clobber DL that had the drive number when you did `mov dx, 0x3fff` . You could `push `dx` before you modify DX and then `pop dx` after the `int 10h` or move DX into another register temporarily and move it back. Either way you need to save DX before youmodify it so that the disk reads have the proper boot drive number later on in DL – Michael Petch Aug 01 '18 at 22:36
  • As for the `ret` it should be placed after the last line of code in `code.asm` and before the `times` directive in `code.asm` – Michael Petch Aug 01 '18 at 22:40
  • The alternative to saving and restoring DX is to load the disk sectors before you do the graphics work. – Michael Petch Aug 01 '18 at 22:48
  • 2
    @MichaelPetch looks like my first glance wasn't all that thorough :) – Jester Aug 01 '18 at 23:07
  • I have to apologize. I realized the segment setting code looked rather familiar.It came from this answer I wrote this past week: https://stackoverflow.com/a/51583105/3857942 . I mistakenly in haste was responsible for that mess. I was the one who wrote them backwards and people used the code. I have fixed that mistake in that answer. – Michael Petch Aug 02 '18 at 16:29

2 Answers2

1

The most likely cause of your problem is that you are clobbering the contents of dl when you clear the screen.

When BIOS loads your boot sector and then calls it, it puts the drive number into dl. You must preserve this value for use when you attempt, later, to load in the subsequent sectors into memory. Since you fail to do so, when you attempt to read the drive, BIOS is trying to read from a (likely) non-existent device.

David Hoelzer
  • 15,862
  • 4
  • 48
  • 67
  • Yes you are right, but how do i clear screen without clobbering the contents of `dl`? I can't fist load sectors and then clear screen, i have to clean screen first and don't ask why. –  Aug 02 '18 at 15:07
  • The absolutely simplest way to do it is to either define the stack first and push it there or define where DS is and store it in your code segment somewhere out of the way. :) – David Hoelzer Aug 02 '18 at 15:42
  • now my stack is 128kb big and i have to load it 4 times with 32kb and when i define it at start i can't run it later, because 16bit mode limit is 64k, so it complete only for 50%. And i don't know how to fix it. –  Aug 02 '18 at 16:44
  • It sounds like you are moving on to other questions. :) I'm not clear on why you think you need such a large stack, though... – David Hoelzer Aug 02 '18 at 18:32
  • because i in this big stack i stored code that draw image pixel by pixel. –  Aug 02 '18 at 18:36
  • Why are you putting your code in the stack? Load it into a memory location and jump to it. – David Hoelzer Aug 02 '18 at 20:11
  • ok, but i have only one problem i am limited with 64 sectors, but my code is 256 sectors big and i can't load 4 times by 64kb, because after fist call i am unable to read next 64sectors. –  Aug 02 '18 at 21:07
  • You ought to start a new question for that. ;) – David Hoelzer Aug 02 '18 at 21:57
1
xor ax, ax                  ; AX=0
mov ds, ax                  ; DS=ES=0 because we use an org of 0x7c00 - Segment<<4+offset = 0x0000<<4+0x7c00 = 0x07c00
mov ax, es
mov ax, ss
mov sp, 0x7c00 

Setting up the segment registers fails!

You need to store AX in them and not the other way.

xor ax, ax
mov ds, ax
mov es, ax                    <---
mov ss, ax                    <---
mov sp, 0x7c00 

mov ah, 0x07        ; function to call with interrupt
mov bh, 0x01        ; blue background 
mov dx, 0x3FFF      ; fill whole screen
int 0x10            ; BIOS draw function

How you paint the screen 12h is rather strange!

This screen has 80 columns and 30 rows, so the lower right corner is at (79,29).
You also forgot to specify the upperleft corner which is (0,0). Your bootloader program should never rely on CX having a zero value when the program starts!

mov ah, 0x07        ; function to call with interrupt
mov bh, 0x01        ; blue background 
xor cx, cx          ; (0,0)                       <-----
mov dx, 0x1D4F      ; (79,29)                     <-----
int 0x10            ; BIOS draw function
Fifoernik
  • 9,779
  • 1
  • 21
  • 27
  • I'm solely responsible for the segment operations being done in the wrong direction. I realized the segment setting code looked rather familiar.It came from this answer I wrote this past week: http://stackoverflow.com/a/51583105/3857942 . I was the one who wrote them backwards and people used the code. I have fixed that mistake in that answer. Until a little while ago I didn't realize it. – Michael Petch Aug 02 '18 at 16:31