I have a program in assembler language that moves all characters back 1 character. It works fine under windows, but under macos it throws a segmentation fault.
Here is the code that works under Windows:
#include <string>
#include <iostream>
using namespace std;
int main()
{
string str1 = "Hello world!";
char* str = &str1[0];
int str_len = str1.length();
__asm {
mov eax, str
mov ecx, str_len
dec ecx
mov esi, eax
add esi, ecx
mov dl, [esi]
shift:
mov ebx, esi
dec ebx
mov al, [ebx] // ! - 11 symbol
mov [esi], al
dec esi
loop shift
mov [esi], dl
}
cout << str;
}
I heard that in mac os addressing works differently and you need to use lea and rel. For example, this code throws a segment fault:
char* str = &str1[0];
__asm {
mov eax, str
mov edx, [eax]
}
To compile on macos I use the command:
g++ -o asm asm.cpp -fasm-blocks -std=c++17
I will be glad for any help.