gpt4 book ai didi

assembly - 不能在 NASM 中包含文件

转载 作者:行者123 更新时间:2023-12-04 13:51:15 31 4
gpt4 key购买 nike

我尝试使用以下命令将文件包含到我的 boot.asm 文件中

%include "input.asm"

但是每次我尝试编译它时,我都会收到一条错误消息,说 nasm 无法打开包含文件。 input.inc与 boot.asm 位于同一目录中
我在这里和谷歌上寻找答案,但没有一个对我有帮助。

在包含之前是否有一种特殊的方式应该编译/格式化包含文件?还是只是我的 nasm 对我吠叫?

编辑:这是包含的代码:
mov ax, 0x07C0  ; set up segments
mov ds, ax mov es, ax
mov si, welcome
call print_string
mov si, welcome2
call print_string
mov si, welcome4
call print_string
jmp .mainloop

%include 'input.asm'
mainloop: ;loop here

输入.asm:
 ; ================
; calls start here
; ================

print_string:
lodsb ; grab a byte from SI

or al, al ; logical or AL by itself
jz .done ; if the result is zero, get out

mov ah, 0x0E
int 0x10 ; otherwise, print out the character!

jmp print_string

.done:
ret

get_string:
xor cl, cl

.loop:
mov ah, 0
int 0x16 ; wait for keypress

cmp al, 0x08 ; backspace pressed?
je .backspace ; yes, handle it

cmp al, 0x0D ; enter pressed?
je .done ; yes, we're done

cmp cl, 0x3F ; 63 chars inputted?
je .loop ; yes, only let in backspace and enter

mov ah, 0x0E
int 0x10 ; print out character

stosb ; put character in buffer
inc cl
jmp .loop

.backspace:
cmp cl, 0 ; beginning of string?
je .loop ; yes, ignore the key

dec di
mov byte [di], 0 ; delete character
dec cl ; decrement counter as well

mov ah, 0x0E
mov al, 0x08
int 10h ; backspace on the screen

mov al, ' '
int 10h ; blank character out

mov al, 0x08
int 10h ; backspace again

jmp .loop ; go to the main loop

.done:
mov al, 0 ; null terminator
stosb

mov ah, 0x0E
mov al, 0x0D
int 0x10
mov al, 0x0A
int 0x10 ; newline

ret

strcmp:
.loop:
mov al, [si] ; grab a byte from SI
mov bl, [di] ; grab a byte from DI
cmp al, bl ; are they equal?
jne .notequal ; nope, we're done.



cmp al, 0 ; are both bytes (they were equal before) null?
je .done ; yes, we're done.

inc di ; increment DI
inc si ; increment SI
jmp .loop ; loop!

.notequal:
clc ; not equal, clear the carry flag
ret

.done:
stc ; equal, set the carry flag
call print_string
ret

错误消息:

D:\ASMT\boot.asm:14: fatal: unable to open include file `input.asm'

最佳答案

看来NASM包括当前目录中的文件:

Include files are searched for in the current directory (the directory you're in when you run NASM, as opposed to the location of the NASM executable or the location of the source file), plus any directories specified on the NASM command line using the -i option.



如果您正在执行 NASM从另一个目录 D:\ASMT在你的情况下,它不起作用是正常的。

来源: http://www.nasm.us/doc/nasmdoc4.html#section-4.6.1

关于assembly - 不能在 NASM 中包含文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18077152/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com