【发布时间】:2017-03-08 03:48:15
【问题描述】:
extern putchar, getchar, printf
global main
SECTION .data
fmt: db “characters = %d", 10,0
SECTION .bss
SECTION .text
global main
main:
xor eax, eax
xor ebx, ebx
start:
call getchar
cmp eax, -1
jle exit
inc ebx;
cmp eax, "A"
jl print
cmp eax, "z"
jg print
cmp eax, "Z"
jle rotup
cmp eax, "a"
jge rotlow
jmp print
rotup:
cmp eax, "M"
jle add13
sub eax, 13
jmp print
rotlow:
cmp eax, "m"
jle add13
sub eax, 13
jmp print
add13:
add eax,13
jmp print
print:
push eax;
call putchar
add esp,4
jmp start
exit:
push ebx
push fmt
call printf
add esp,8
ret
好的。所以我一直在使用这个程序来为我的一个课程运行 Vigenere Cipher,当我尝试运行 nasm 时,它在第一部分运行良好
nasm -f elf cipher.asm
但是当我尝试时
ld -o cipher cipher.o
继续它给了我
ciper.o: In function 'start':
cipher.asm:(.text+0x5): undefined reference to 'getchar'
cipher.o: In function 'print':
cipher.asm:(.text+0x40): undefined reference to 'putchar'
cipher.o: IN function 'exit':
cipher.asm:(.text+0x50):undefined reference to 'printf'
我不知道为什么它给了我这个,我认为这就是 extern 的重点。另外,如果您想知道我在使用什么我在 64 位上运行 Ubuntu。 我试过阅读如何解决这个问题,但我似乎找不到对我有帮助的。
编辑:现在我正在尝试使用 gcc 而不是 ld 来链接但是当我使用时
gcc -o output cipher.o
或类似的东西给我
/usr/bin/ld: i386 architecture of input file 'cipher.o' is incompatible with i386:x86-64
output
它仍然给了我未定义的引用,我不知道该怎么做或如何链接它,所以我可以在代码中使用 C 函数。
【问题讨论】:
标签: ubuntu assembly nasm x86-64 ld