INT 10h / ah = 13h does not print lines when part of the second-stage bootloader

I used all the memory in the first sector, now I want to save a new variable string in the second sector (second stage) and print it. For instance:

hello db 'Hello World'

The new line must be in another sector (because the first sector no longer has memory). I did this with INT 13h, ah = 2 , to read the second sector of the disk for address 900h: 0000. I saved the variable helloin this sector, as well as the code for printing. It cannot print my line when I use INT 10h / ah = 13h in the code as follows:

mov ax, 7c0h
mov es, ax

mov bp, hello 
mov ah,13h          ; function 13 - write string
mov al,01h          ; attrib in bl, move cursor
mov bl,0bh          ; attribute - magenta
mov cx,30           ; length of string
mov dh,1            ; row to put string
mov dl,4            ; column to put string
int 10h             ; call BIOS service

When a variable is in the first sector, it prints well, but when I save it in the second sector, it does not print, even when I do:

mov ax, 900h
mov es, ax

Code example:

xchg bx, bx
mov ax, 7c0h
mov ds, ax

sector_2:
mov bx, 900h
mov es, bx
mov bx, 0
mov ah, 2
mov al, 1
mov ch, 0
mov cl, 2
mov dh, 0                     
mov dl, 80h                    
int 13h                        
call 900h:0000

jmp $

times 510 - ($-$$) db 0            ; Fill empty bytes to binary file
dw 0aa55h                          ; Define MAGIC number at byte 512
;;;;;;;;;;;;;;;;;;;;;;;;

sector_2:
mov ax, 900h
mov es, ax      
mov bp, hello
mov ah,13h          ; function 13 - write string
mov al,01h          ; attrib in bl, move cursor
mov bl,0bh          ; attribute - magenta
mov cx,5            ; length of string
mov dh,1            ; row to put string
mov dl,4            ; column to put string
int 10h             ; call BIOS service 

retf
jmp $

hello db 'Hello'
times 1024 - ($-$$) db 0
times 2*8*63*512 - ($-$$) db 0
+4
1

, . :

xchg bx, bx
mov ax, 7c0h
mov ds, ax

, :

xchg bx, bx
mov ax, 7c0h
mov es, ax      ; Int 10h/ah=13h takes string address in ES:BP

. sector_2, , , NASM. , .

, - :

nasm -f bin boot.asm -o boot.img

, -f bin, .


ORG, NASM org 0h . 0. , (512 ) . , 0x7c0, , 0 7c00h. : (7c0h < 4) +0 ( 0 - /org ), 7c00h.

, , 900h: 0h. FAR CALL call 900h:0000. .

, ? , NASM , 512 : 0 (900h: 0000h). .

NDISASM , 512 , :

00000000  B80009            mov ax,0x900
00000003  8EC0              mov es,ax
00000005  BD1A02            mov bp,0x21a
00000008  B413              mov ah,0x13

:

ndisasm -e 512 -b16 boot.img

boot.img - . -e 512 , 512 . , :

mov bp,0x21a

0x21a hello. , 0x21a 538 , 0 (900h: 0000h). , NASM, , ( ), 0, . , ( ) , (vstart) reset 0. , , ,

section stage2, vstart=0h

, :

dw 0aa55h                          ; Define MAGIC number at byte 512
;;;;;;;;;;;;;;;;;;;;;;;;

section stage2, vstart=0h          ; Section name can be anything of your choosing
sector_2:
mov ax, 900h
mov es, ax
mov bp, hello

, NDISASM, :

00000000  B80009            mov ax,0x900
00000003  8EC0              mov es,ax
00000005  BD1A00            mov bp,0x1a    ; Notice hello offset is 0x1a not 0x21a

@Jester org 0h, ( ), ORG. , , NASM , . ! "" . NASM `SECTION reset ( 0).

ORG SECTION NASM. SECTION VSTART 7.1.3. bin

+6

All Articles