I have some problems when accessing data when it is located in
section .data
I wrote a small program in assembler (using NASM) which consists of a bootloader that loads some 'kernel' code. This kernel code is then executed once loaded in memory.
I'll first show the code, then formulate my problem.
The first part of the program consists of initial statements and data definitions:
org 7C00h
jmp _start
OS_LOCATION equ 0x7E00
STACKSEG equ 0xCE00
STACKSIZE equ 8192
DRIVE_NR equ 80h
NO_ERROR equ 0
BOOT_ERROR equ 1000
PINK equ 0dh
YELLOW equ 0eh
WHITE equ 0fh
letterB db 'B'
;=============================================================================
;section .data ;A PROBLEM OCCURS WHEN I UNCOMMENT THIS LINE (SEE LATER)
letterD db 'D'
The 2nd part is the bootloader code:
;=============================================================================
segment .text
_start:
cli
mov ax, cs
mov ds, ax ; DS = CS
mov es, ax ; ES = CS
mov ax, STACKSEG
mov ss, ax ; SS = STACKSEG
mov sp, ax
add sp, STACKSIZE
mov bp, sp
sti
;-----------------------------------------------------------
; Display tests
;-----------------------------------------------------------
mov ax, 0B800h
mov es, ax
mov di, (160 * 0) + (2 * 0) ; Row and Column
mov ah, PINK ; Attribute byte
mov al, 'A' ; load immediate
mov [es:di], ax ; OK: A IS DISPLAYED
mov ax, 0B800h
mov es, ax
mov di, (160 * 0) + (2 * 1) ; Row and Column
mov ah, PINK ; Attribute byte
mov al, byte [letterB] ; load from memory
mov [es:di], ax ; OK: B IS DISPLAYED
;-----------------------------------------------------------
; Load OS
;-----------------------------------------------------------
mov ax, OS_LOCATION
mov es, ax
mov bx, 0
push dword 4 ; # sectors
push dword 2 ; start sector
call loadSector
cmp ax, BOOT_ERROR
jnz _startOS
_reboot:
mov ah, 0
int 16h
db 0x0ea
dw 0x0000
dw 0xffff
;-----------------------------------------------------------
; Start OS
;-----------------------------------------------------------
_startOS:
jmp OS_LOCATION:0000 ; jump to our os
;***************************************************************************
loadSector:
push ebp
mov ebp, esp
pushad
mov ah, 2
mov al, [ebp+10] ; # sectors
mov ch, 0 ; track
mov cl, [ebp+6] ; start sector
mov dh, 0 ; head
mov dl, DRIVE_NR ; drive nr (NOK: 81h, 0h)
int 0x13
jc _err_loadSector
popad
mov ax, NO_ERROR
jmp _exit_loadSector
_err_loadSector:
popad
mov ax, BOOT_ERROR
_exit_loadSector:
mov esp, ebp
pop ebp
ret 8
;***************************************************************************
times 512d - 2 - ($ - $$) db 0 ;Zerofill up to 510 bytes
dw 0AA55h ;Boot Sector signature
The last part consists of the very simple 'kernel' code (this is to where the bootloader jumps when executing jmp OS_LOCATION:0000)
;-----------------------------------------------------------
; More display tests
;-----------------------------------------------------------
mov ax, 0B800h
mov es, ax
mov di, (160 * 2) + (2 * 0) ; Row and Column
mov ah, YELLOW ; Attribute byte
mov al, 'C' ; load immediate
mov [es:di], ax ; OK: C IS DISPLAYED
mov ax, 0B800h
mov es, ax
mov di, (160 * 2) + (2 * 1) ; Row and Column
mov ah, YELLOW ; Attribute byte
mov al, byte [letterD] ; load from memory
mov [es:di], ax ; D IS DISPLAYED ONLY IF 'section .data' IS COMMENTED
So far for the code.
Now, the above code works when I define 'letterD' NOT in the data section:
;section .data ; IT WORKS WHEN THIS LINE IS COMMENTED
letterD db 'D'
--> The bootloader code displays: AB
--> The kernel code displays: CD
The problem though is when I define 'letterD' in the data section:
section .data ; IT DOESN'T WORK WHEN THIS LINE IS UNCOMMENTED ???
letterD db 'D'
--> The bootloader code displays: AB
--> The kernel code displays: C
The letter 'D' is NOT displayed
It is as if the data can not be found when placed in a data section. (FYI: nasm builds my code to BIN-format)
What is going on here? How to solve this?
thank you
Chris