I'm trying to implement c++ program which read string from c++ part of program, process it with inline assembly (convert all latin symbols to their HEX representation by number in ASCII table) and print it with c++ code. I have a problem with compiling it, I've found the way to do it without mistakes, but I can't implement it.
I've tried to compile that with:
gcc -S -masm=intel code.cpp -o code
But when I try to implement it, there are a lot of errors like that:
./main: line 1: .file: command not found
./main: line 2: .intel_syntax: command not found
./main: line 3: .text: command not found
./main: line 4: .section: command not found
./main: line 5: .type: command not found
./main: line 6: .size: command not found
./main: line 7: _ZStL19piecewise_construct:: command not found
./main: line 8: .zero: command not found
./main: line 9: .local: command not found
./main: line 10: .comm: command not found
./main: line 11: .LC0:: command not found
Here is a code of my program:
#include <iostream>
#include <fstream>
#include <clocale>
#include <curses.h>
#define MAX_LENGTH 80
using namespace std;
void printWelcomeStr();
int main()
{
char input_string[MAX_LENGTH];
char output_string[MAX_LENGTH];
cin.getline(input_string, MAX_LENGTH, '\n');
asm
(
".intel_syntax;""lea eax, input_string\n""mov esi, %eax\n""lea eax, output_string\n""mov %edi, %eax\n""BEGINCYCLE:\n""lodsb\n""test al, al\n""je EXIT\n""cmp al, 41h\n" // >= 'A'"jnbe LatinLetterGeneral\n""jmp NEXT\n""LatinLetterGeneral:\n""cmp %al, 5Ah\n" // <= 'Z'"jnae LatinLetterFinal\n""cmp al, 61h\n" // >= 'a'"jnbe LatinLetterFinal\n""jmp NEXT\n""LatinLetterFinal:\n""cmp al, 7Ah\n" // > 'z'"ja NEXT\n""cmp ax, al\n""sub ax, 30h\n""push cx\n""mov cx, 2\n""rol dl, 4\n""mov ax, 300fh\n""and al,dl\n""aaa\n""aad 11h\n""pop cx\n""mov al, di\n""jmp NEXT\n""NEXT:\n""stosb\n""jmp BEGINCYCLE\n""EXIT:\n""stosb\n"
);
cout << "\n\nResult:"<< endl;
ofstream file_output("output.txt");
int i = 0;
while (output_string[i] != '\0')
{
cout << output_string[i];
file_output << output_string[i];
i++;
}
cout << endl;
file_output << endl;
file_output.close();
getch();
system("pause");
return 0;
}