assembly - Having trouble calling C functions in NASM -


i creating nasm program calling c function in nasm code simplify life. undefined reference errors. have done wrong? here code below:

command line commands used compile

nasm -fwin32 calculator.asm      gcc - wall -c print.c -o print.obj  $ ld calculator.obj print.obj -o calculator.exe   calculator.obj:calculator.asm:(.text+0x6): undefined reference `print' calculator.obj:calculator.asm:(.text+0x15): undefined reference `sum' calculator.obj:calculator.asm:(.text+0x24): undefined reference `int2string' calculator.obj:calculator.asm:(.text+0x2a): undefined reference `print' calculator.obj:calculator.asm:(.text+0x2f): undefined reference `ps' print.obj:print.c:(.text+0xd): undefined reference `printf' print.obj:print.c:(.text+0x20): undefined reference `atoi' print.obj:print.c:(.text+0x8b): undefined reference `printf' print.obj:print.c:(.text+0xbe): undefined reference `system' 

platform

windows 7 64-bit compiling in 32-bit. shouldn't problem; think.

c code

#include <stdio.h> #include <stdlib.h>  //prototypes void _print(char* string); int _string2int(char* string); char* _int2string(int i); int _sum(int x, int y); int _sub(int x, int y); int _divide(int x, int y); int _multiply(int x, int y); void _pause(); char* itoa(int val, int base);  void print(char* string) {     printf(string); } int string2int(char* string) {     return atoi(string); } char* int2string(int i) {     return itoa(i, 10); } int subtract(int x, int y) {     return x + y; } int sub(int x, int y) {     return x - y; } int divide(int x, int y) {     if (y != 0)     {         return (x / y);     }     else if (y != 0)     {         printf("infinity!");         return 0;     }     return 0; } int multiply(int x, int y) {     return x * y; } void ps() {     system("pause"); } char* itoa(int val, int base){      static char buf[32] = {0};      int = 30;      for(; val && ; --i, val /= base)          buf[i] = "0123456789abcdef"[val % base];      return &buf[i+1];  } 

nasm code

global _main extern print extern sum extern subtract extern divide extern string2int extern int2string extern ps section .data   ;constant message: db 'the sum of 2 + 2 ', 0   section .bss  ;variables answer: resb 255 stranswer: resb 255  section .text _main:  ;call print function , print variable named message. push message call print  ;add 2 , 2 , return value gets placed in eax register. push 2 push 2  call sum mov [answer], eax   push answer call int2string  push eax call print  ;pauses console window. call ps 

conclusion: sorry long post

your ps function not declared , sum not defined. there 2 functions sub , subtract. guess wanted 1 of them sum. last 4 due not linking libc.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -