I am using NASM 2.16.01, Arch Linux.
I try to write a boot sector (8086, IBM PC) using the vstart=0x7C00
attribute, so that following address calculations should be relative to that.
However, it does not work, since all addresses are still calculated relative to 0
. Why is this (I do not understand the NASM documentation then)? I want the jmp 0:$+5
in line 33 to eval to EA xx7C 0000
.
My code:
1 bits 16
2 ; this is the boot sector which is located on every floppy
3 ; it gets loaded to CS:IP = 07C00h
4 section .text start=0 vstart=0x7C00
5
6 00000000 EB3C jmp loader
7 00000002 90 nop
8 00000003 52444F5320302E31 oem_name db "RDOS 0.1"
9 0000000B 0002 bytes_pro_sector dw 512
10 0000000D 01 sectors_per_cluster db 1
11 0000000E 0100 reserved_sectors dw 1
12 00000010 02 num_fats db 2
13 00000011 E000 root_entries_max dw 224
14 00000013 400B num_sectors dw 2880
15 00000015 F0 media_desc db 0xF0
16 00000016 0900 sectors_per_fat dw 9
17 00000018 1200 secs_per_track dw 18
18 0000001A 0200 num_heads dw 2
19 0000001C 000000000000000000- reserved db 10 dup 0
19 00000025 00
20 00000026 29 extended_bpb db 0x29
21
22 00000027 FA0E340C volid dd 0x0C340EFA
23 0000002B 4E4F204E414D452020- volname db "NO NAME "
23 00000034 2020
24 00000036 4641543132202020 fatid db "FAT12 "
25
26 loader:
27 0000003E FA cli
28 0000003F 31C0 xor ax, ax
29 00000041 8ED8 mov ds, ax
30 00000043 8EC0 mov es, ax
31 00000045 8ED0 mov ss, ax
32 00000047 BCFF7E mov sp, 7EFFh ; 256 bytes stack after this code
33 0000004A EA[4F00]0000 jmp 0:$+5 ; fix for BIOS that uses 7C0:0 instead of 0:7C00
As @MichaelPetch pointed out (thanks!) nasm
shows relocatable addresses in its code listing with []
, so
33 0000004A EA[4F00]0000 jmp 0:$+5
Is indeed encoded EA 4F 7C 00 00
within the binary that is generated. (Checked with hexdump -C
)
The listing that is generated by using yasm -p nasm
however
does not show square brackets and directly shows the correct binary data that also is stored in the binary file. (As one would expect).
Hence the relocatable binary data which nasm
displays is misleading, because a binary file does not have a relocation table.