1

I have the following code for my boot-loader:

[org 0x7c00]
KERN_OFFSET equ 0x1000
mov bx, BOOTLOADER_MSG
call print_string
mov [BOOTDISK], dl
mov dl, 0x0 ;0 is for floppy-disk
mov ah, 0x2 ;Read function for the interrupt
mov al, 0x15 ;Read 15 sectors conating kernel
mov ch, 0x0 ;Use cylinder 0
mov cl, 0x2 ;Start from the second sector which contains kernel
mov dh, 0x0 ;Read head 0 
mov bx, KERN_OFFSET
int 0x13
jc disk_error
cmp al, 0x15
jne disk_error
jmp $

disk_error:
mov bx, DISK_ERROR_MSG 
call print_string
jmp $

%include "print_string.asm"

DISK_ERROR_MSG:
db 'Disk Read Error',0

BOOTLOADER_MSG:
db 'Reading Kernel from sector 2',0

BOOTDISK: db 0

times 510-($-$$) db 0
dw 0xaa55

The print_string.asm file is :

print_string:
pusha
mov ah, 0xe
sub bx, 0x1
print:
add bx, 0x1
mov al, [bx]
int 0x10
cmp al, 0x0
jne print
popa
ret

This program assembles fine with nasm command but if I try using as86 it shows lot of errors:

00001                                           [org 0x7c00]
00024                                           %include     "print_string.asm"
00027 003B                        44            db 'Disk Read Error',0
***** junk after operands............................^
00030 003C                        52            db 'Reading Kernel   from sector 2',0
***** junk after operands............................^
00034                       0000003E>           times 510-($-$$) db 0
***** illegal label...................................^
00001                                           [org 0x7c00]
00004 0004           E8         0000            call print_string
***** unbound label..................................^
***** relocation impossible......................................^
00017 0030           EB           00            jmp $
***** relocation impossible..........................^
00021 0036           E8         0000            call print_string
***** unbound label..................................^
***** relocation impossible......................................^
00022 0039           EB           00            jmp $
***** relocation impossible..........................^
00024                                           %include   "print_string.asm"
00027 003B                        44            db 'Disk Read Error',0
***** junk after operands............................^
00030 003C                        52            db 'Reading Kernel    from sector 2',0
***** junk after operands............................^
00034                       0000003E>           times 510-($-$$) db 0
***** illegal label...................................^

I want to assemble this code in 16 bit machine language. Can I use nasm for this code?
Also, why is this code not assembling with as86?

sarthak
  • 774
  • 1
  • 11
  • 27
  • Yes, nasm can produce 16 bit code. as86 has different syntax. – Jester Feb 22 '15 at 18:49
  • Well obviously as86 doesn't know `%include` and `$`, `$$` etc. which are nasm-based macros/tokens. You should be able to replace those with `GET INCLUDE` and `*`. Not sure about `$$` replacement though. – Zdeněk Jelínek Feb 22 '15 at 19:06
  • Not directly related to the question, but you should move the 'mov [BOOTDISK], dl' before the print routine, because the int 10h call will probably overwrite DL. – zx485 Feb 23 '15 at 10:10
  • @Jester Both are producing 16-bit machine code for x86 why is there a difference. Could you please explain? – sarthak Feb 23 '15 at 17:15
  • 1
    Because every assembler has its own syntax, especially apart from instruction mnemonics such as expression format, directives, macros, special symbols, etc. – Jester Feb 23 '15 at 17:24
  • @Jester Is there a difference in the format of the output files as well. The linker command ld86 doesn't seem to work with nasm output. If so, why? – sarthak Feb 23 '15 at 18:08
  • nasm can produce various output formats, see `nasm -hf`. Presumably you need to select `as86`. – Jester Feb 23 '15 at 18:16

0 Answers0