prog01 : -------- [BITS 16] ; indique a nasm que l'on travaille en 16 bits [ORG 0x0] ; initialisation des segments en 0x07C0 mov ax,0x07C0 mov ds,ax mov es,ax mov ax,0x8000 ; stack en 0xFFFF mov ss,ax mov sp, 0xf000 ; affiche un msg mov si,msgDebut call afficher end: jmp end ;--- Variables --- msgDebut db "Hello world !",13,10,0 ;----------------- ;--------------------------------------------------------- ; Synopsis: Affiche une chaine de caracteres se terminant par 0x0 ; Entree: ds:si -> pointe sur la chaine a afficher ;--------------------------------------------------------- afficher: push ax push bx .debut: lodsb ; ds:si -> al cmp al,0 ; fin chaine ? jz .fin mov ah,0x0E ; appel au service 0x0e, int 0x10 du bios mov bx,0x07 ; bx -> attribut, al -> caractere ascii int 0x10 jmp .debut .fin: pop bx pop ax ret ;--- NOP jusqu'a 510 --- times 510-($-$$) db 144 dw 0xAA55 |
Que fait exactement ce programme ?
[BITS 16] ; indique a nasm que l'on travaille en 16 bits |
; initialisation des segments en 0x07C0 mov ax,0x07C0 mov ds,ax mov es,ax |
mov ax,0x8000 ; stack en 0xFFFF mov ss,ax mov sp, 0xf000 |
; affiche un msg mov si,msgDebut call afficher |
end: jmp end |
msgDebut db "Hello world !",13,10,0 |
;--- NOP jusqu'a 510 --- times 510-($-$$) db 144 dw 0xAA55 |
$ nasm -f bin -o bootsect bootsect.asm |
Pour lancer le secteur de boot, la methode la plus simple est certainement de copier le binaire sur une disquette avec la commande suivante :
$ dd if=bootsect of=/dev/fd0 |
%define BASE 0x100 %define KSIZE 1 ; nombre de secteurs de 512 octets a charger [BITS 16] [ORG 0x0] jmp start %include "UTIL.INC" start: mov [bootdrv],dl ; recuparation de l'unite de boot ; initialisation des segments en 0x07C0 mov ax,0x07C0 mov ds,ax mov es,ax mov ax,0x8000 ; stack en 0xFFFF mov ss,ax mov sp, 0xf000 ; affiche un msg mov si,msgDebut call afficher ; charger le noyau xor ax,ax int 0x13 push es mov ax,BASE mov es,ax mov bx,0 mov ah,2 mov al,KSIZE mov ch,0 mov cl,2 mov dh,0 mov dl,[bootdrv] int 0x13 pop es ; saut vers le kernel jmp dword BASE:0 msgDebut db "Chargement du kernel",13,10,0 bootdrv: db 0 ;; NOP jusqu'a 510 times 510-($-$$) db 144 dw 0xAA55 |