1

I try calling asm from a C program

Here is my code:

// Template C to x86 call
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>

extern void asmhello();

int main(int argc, char* argv[]) {
    asmhello();
    return 0;
}

Here is my asm code:

; assembly part using x86-64

section .data
msg db "Hello World",13,10,0
section .text
bits 64
default rel ; to handle address relocation
global asmhello

extern printf
asmhello:

    sub rsp, 8*5 ; caller
    mov rcx, msg1
    call printf
    add rsp, 8*5
    ret

I try running it in VS 2022

the error says..

LNK2019 unresolved external symbol asmhello referenced in function main

The error also says

function definition for 'asmhello' not found.
Jabberwocky
  • 48,281
  • 17
  • 65
  • 115

0 Answers0