DEP error after printf in NASM with visual c


I have a strange problem with a very basic task (I just want to print something in the console).
So I have a c++ program which runs an asm function, and this asm function should just print some text and return 3 to c++.
I tried to print the text in many different methods, one of them is the code from this link. C++ runs assembler code which correctly prints text but when it goes to ret it crashed with the following error:

Exception 0xc0000005 encountered at address 0x7ff654f01000: User-mode data execution prevention (DEP) violation at location 0x7ff654f01000

This is my actual code (with different printing method then the one from the link):

; asmTest.asm
[bits 64]       ; allow 64-bit register names

default rel
section .data
    msg db "Asm started", 0xd, 0xa, 0

section .text
    global _firstWatchdog
    extern printf

    lea rcx, [msg]
    call printf
    mov rax, 3
#include <iostream>
#include <thread>
#include <stdio.h>
namespace testCore{
    extern "C"{
        int _firstWatchdog();
#include "main.h"
[[noreturn]] void asmTest(){
    std::cout << "asm thread started" << std::endl;
    while (true) {
        int tmp_func_val = testCore::_firstWatchdog();

[[noreturn]]int main ()
    std::thread asm_test;
    asm_test = std::thread(asmTest);
    while (true){
        std::cout << "Do some stuff here" << std::endl;
asked on Stack Overflow Jan 13, 2021 by Xmno • edited Jan 14, 2021 by Sep Roland

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0