NASM Forum > Using NASM

Error message on windows: fatal: unable to open output file (?)

(1/2) > >>

gomi:
Hello, I am interested in assembly programs. I want to make simple boot.asm file and run it in qemu. I made asm file run nasm in order to compile to bin on win10x64 with command " nasm boot.asm -f bin -o boot.bin " Note that my nasm was came from installer so it is located in " C:\Program Files\NASM> " so I put my boot.asm inside it too. However, I got fatal: " unable to open output file boot.bin "

Yes I know that I would do it on linux but somehow I have to do this on windows10x64.

Thank you very much for any help.

debs3759:
I'm not sure, but it could be because you are trying to output it under "Program Files". Windows can be quite strict about where you can write files, and Program Files is possibly a protected operating system directory.

gomi:
Thank you, I changed my path to desktop and run command line as Admin. Now I got another issue  ;D ===> "boot.asm:18: error: parser: instruction expected"

Here is my code which is an example code I got:


--- Code: ---;org 0x7C00                      ; BIOS loads our programm at this address
;bits 16                         ; We're working at 16-bit mode here

start:
cli                     ; Disable the interrupts
mov si, msg             ; SI now points to our message
mov ah, 0x0E            ; Indicate BIOS we're going to print chars
.loop lodsb                   ; Loads SI into AL and increments SI [next char]
or al, al               ; Checks if the end of the string
jz halt                 ; Jump to halt if the end
int 0x10                ; Otherwise, call interrupt for printing the char
jmp .loop               ; Next iteration of the loop

halt: hlt                     ; CPU command to halt the execution
msg: db "Hello, World!", 0   ; Our actual message to print

;; Magic numbers
times 510 – ($ – $$) db 0
dw 0xAA55
--- End code ---

gomi:
Alright I found an answer for myself, compiler needs a compatible code for itself, I searched and found the compatible code

Source: https://medium.com/@g33konaut/writing-an-x86-hello-world-boot-loader-with-assembly-3e4c5bdd96cf

nasm compatible code:


--- Code: ---[bits 16] ; use 16 bits
[org 0x7c00] ; sets the start address
init:
  mov si, msg ; loads the address of "msg" into SI register
  mov ah, 0x0e ; sets AH to 0xe (function teletype)
print_char:
  lodsb ; loads the current byte from SI into AL and increments the address in SI
  cmp al, 0 ; compares AL to zero
  je done ; if AL == 0, jump to "done"
  int 0x10 ; print to screen using function 0xe of interrupt 0x10
  jmp print_char ; repeat with next byte
done:
  hlt ; stop execution
msg: db "Hello world!", 0 ; we need to explicitely put the zero byte here
times 510-($-$$) db 0 ; fill the output file with zeroes until 510 bytes are full
dw 0xaa55 ; magic number that tells the BIOS this is bootable
--- End code ---

I got my boot.bin without error now.

Thanks.

debs3759:
If/when you want to expand on your bootsector, you might find my sample boot sector useful. It can be found at https://forum.nasm.us/index.php?topic=2265.0 and is FAT12 only (should be simpler to write one that can read your OS loader off other file systems). It can read whatever loader you code into it, and if your loader sets up 32 or 64 bit modes it can be any size. It can even cope with fragmented code :)

Navigation

[0] Message Index

[#] Next page

Go to full version