1

I am trying to make a simple OS in x86 assembly, but when I try to assemble it I get a lot of errors along the lines of:

../inc/screen.asm:1: error: label `print' inconsistently redefined
../inc/screen.asm:1: note: label `print' originally defined here

The source for screen.asm:

print:
    pusha
print_loop:
    mov al, [si]
    cmp al, 0
    jne disp_char
    popa
    ret
disp_char:
    mov ah, 0x0E
    int 0x10
    add si, 1
    jmp print_loop

This is in a separate file that is used in the bootloader. bootloader source:

[org 0x7c00]

%include "../inc/screen.asm"
%include "../inc/disk.asm"
%include "../inc/err.asm"

    mov si, mbr_boot_info
    call print
    mov si, mbr_legal
    call print

    call read_kern

    jmp $

mbr_boot_info: db "CCLOS ALPHA BOOTLOADER", 10, 13, 0
mbr_legal: db "Copyright 2021", 10, 13, 0

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

This error appears for all labels in screen.asm and also in err.asm:

%include "../inc/screen.asm"

err:
    mov si, errtxt
    call print
    jmp $


errtxt: db "ERROR", 0

Why is this happening?

1201ProgramAlarm
  • 32,384
  • 7
  • 42
  • 56
  • 3
    Your include files are defining functions, not macros, so they're like `.c` files defining functions, not `.h` files. You can't include them multiple times, even indirectly. Duplicate of [label inconsitently redefined NASM](https://stackoverflow.com/q/64860117) - nobody's answered it but see comments. For the plain error message, duplicate of [nasm assembly: Can't find valid values for all labels after 1004 passes](https://stackoverflow.com/q/58339450), but your duplication is for the actual function, not a same-name different-use label like `loop:`. – Peter Cordes Feb 06 '21 at 03:32
  • 2
    Making an MBR boot sector means it's less convenient to use a linker, so just don't put `%include` into files that you already `%include`, or use `%ifdef` protection against double includes. – Peter Cordes Feb 06 '21 at 03:36

1 Answers1

0

Your files are loop including do not complie all files at once try to complie file to .o file one by one and link them to a binary file with a .lds linker script

AlanCui
  • 137
  • 9