我开始进行系统编程,但遇到了令人讨厌的情况。 我不知道如何使用nasm和g ++编译器在asm文件中运行cpp过程。
这是我在asm中名为kernel.asm的代码:
[BITS 32]
EXTERN scrollup, print
global _start
_start :
mov ax , msggdt
push ax
call print
pop ax
mov ax , msggdt32
push ax
call print
pop ax
mov ax , 3
push ax
call scrollup
pop ax
end:
jmp end
msggdt : db "Load gdt",13 , 10,0
msggdt32 : db "Load protected mode",13,10,0
我的cpp文件包含print,scrollup
功能我指定了我的编译器版本:NASM版本2.14和gcc版本8.2.0(Debian 8.2.0-21)
g++ -c screen.cpp
screen.cpp: In function ‘void _putcar_(uchar)’:
screen.cpp:63:59: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
video = (unsigned char*) (RAMSCREEN + 2 * kX + 160 * kY ) ;
nasm -f elf64 -o kernel.o kernel.asm
现在,看,我已经尝试了4次LD的调用,不仅可以更改对象的顺序,还可以更改输出,但是什么都没有
ld --oformat binary -Ttext 1000 screen.o kernel.o -o screen
ld: kernel.o: in function `_start':
kernel.asm:(.text+0x7): undefined reference to `print'
ld: kernel.asm:(.text+0x14): undefined reference to `print'
ld: kernel.asm:(.text+0x21): undefined reference to `scrollup'
ld --oformat binary -Ttext 1000 screen.o kernel.o -o kernel
ld: kernel.o: in function `_start':
kernel.asm:(.text+0x7): undefined reference to `print'
ld: kernel.asm:(.text+0x14): undefined reference to `print'
ld: kernel.asm:(.text+0x21): undefined reference to `scrollup'
ld --oformat binary -Ttext 1000 kernel.o screen.o -o kernel
ld: kernel.o: in function `_start':
kernel.asm:(.text+0x7): undefined reference to `print'
ld: kernel.asm:(.text+0x14): undefined reference to `print'
ld: kernel.asm:(.text+0x21): undefined reference to `scrollup'
ld --oformat binary -Ttext 1000 kernel.o screen.o -o screen
ld: kernel.o: in function `_start':
kernel.asm:(.text+0x7): undefined reference to `print'
ld: kernel.asm:(.text+0x14): undefined reference to `print'
ld: kernel.asm:(.text+0x21): undefined reference to `scrollup'
请,我需要一些帮助。如果我犯了一些错误,对不起,请告诉我。
谢谢
答案 0 :(得分:0)
我可以建立链接。但是,我使用了:
gcc -c screen.c
nasm -f elf64 -o kernel.o kernel.asm
所以我必须有一个c文件而不是c ++ ..我不明白为什么。 有人可以向我解释为什么会起作用吗?