私は x86 アセンブリ (Intel 構文) の初心者であり、インライン GCC を使用していくつかの簡単な命令をいじっています。数値と制御フローの操作に成功し、現在は割り込みを使用して標準入出力に取り組んでいます。-m32
Mac OS X を使用しており、 GCC フラグを使用して 32 ビットのコンパイルを強制しています。
文字列を標準出力に出力するために、次のものがあります。
char* str = "Hello, World!\n";
int strLen = strlen(str);
asm
{
mov eax, 4
push strLen
push str
push 1
push eax
int 0x80
add esp, 16
}
コンパイルして実行するHello, World!
と、コンソールに出力されます! ただし、標準入力から読み取ろうとすると、うまく機能しません。
char* str = (char*)malloc(sizeof(char) * 16);
printf("Please enter your name: ");
asm
{
mov eax, 3
push 16
push str
push 0
push eax
int 0x80
add esp, 16
}
printf("Hello, %s!\n", str);
実行すると、プロンプトが表示されますが、「名前を入力してください:」という文字列はありません。入力を入力してEnterキーを押すと、入力文字列と期待される出力が出力されます。
Please enter your name: Hello, Joe Bloggs
!
ユーザーが入力する前に、エントリ文字列を予想される場所に表示するにはどうすればよいですか?