%include "asm_io.inc"
segment .data
segment .bss
segment .text
global secret_func
secret_func:
enter 0,0
push ebx
cmp ebx, 1
jne while_init
jmp case_one
while_init:
mov ecx, 2
while:
cmp ecx, ebx
jge case_two
xor edx, edx
mov eax, ebx
div ecx
cmp edx, 0
je case_one
add ecx, 1
jmp while
case_one:
mov eax, 0
jmp end
case_two:
mov eax, 1
end:
mov ebx, eax
pop ebx
mov eax,0
leave
ret
given the above secret.asm, which as far as i understand it checks if a given int value is prime or not. or?
#include <stdio.h>
extern int secret_func (int);
int main()
{
int ret_status;
ret_status = secret_func(3);
printf("%i\n",ret_status);
return 0;
}
and the above main.c which is supposed to call the assembly function with the value 3 and then print the assembly functions return value.
im trying to compile and link these 2 files with (using asm_io from paul carters set):
nasm -f elf -o secret.o secret.asm
nasm -f elf -d ELF_TYPE -o asm_io.o asm_io.asm
gcc -m32 -c -o main.o main.c -std=c99 -Wall
gcc -m32 -o secret -std=c99 -Wall main.o secret.o asm_io.o
I am not sure where my mistake is, did i understand the assembly program correctly or is there a mistake while linking or compiling?