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
Ok. So i have been using this program in order to run a Vigenere Cipher for one of my classes and when i try running nasm it works fine the first part
nasm -f elf cipher.asm
but then when i try
ld -o cipher cipher.o
to continue it gives me
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'
I dont know why it gives me this i thought that was the point of the extern. Also if your wondering what im using im running Ubuntu on 64-bit. Ive tried reading of how to fix this but i cant seem to find one that helps me.
edit: now i am trying to use gcc instead of ld to link the but when i use
gcc -o output cipher.o
or something similar it gives me
/usr/bin/ld: i386 architecture of input file 'cipher.o' is incompatible with i386:x86-64
output
Its still gives me the undefined reference and I dont know what to do or how to link it so i can use the C functions in the code.