我正在尝试使用带有以下代码的程序集插入在屏幕上打印单个字符:
output:
keywords search_volume loan mortgage accounts cards
0 loans 132000 10 0 0 0
1 funding circle 81000 0 0 0 0
2 government 36000 0 0 0 0
3 short term loans 30000 10 0 0 0
4 company 27000 0 0 0 0
但是我不知道如何在此c ++代码中插入80h函数调用。
asm(“ int 80h”)和asm(“ int 80h”:)无效。 我正在使用clang ++
好的,我实际上用以下代码成功解决了这个问题:
char z[]="x";
int result;
asm( "mov 4, %%eax" : );
asm( "mov 1, %%ebx" : );
asm( "mov %%edx, %%ecx" : : "d"(&z) );
asm( "mov 2, %%edx" : );
//int 80h
但是执行后,我收到了分段错误错误。我还收到带有-fsanitize = undefined,address标志的消息:
char z[]="x";
int result;
asm( "mov 4, %%eax" : : : "eax" );
asm( "mov 1, %%ebx" : : : "ebx" );
asm( "mov %%edx, %%ecx" : : "d"(&z) : "ecx" );
asm( "mov 2, %%edx" : : : "edx" );
asm( "int $0x80" : );
我也用gdb调试了它,所以我知道该程序在此行上崩溃了:
AddressSanitizer:DEADLYSIGNAL
=================================================================
==6068==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000004 (pc 0x558c9691bb24 bp 0x7ffde7b2e180 sp 0x7ffde7b2e0c0 T0)
==6068==The signal is caused by a READ memory access.
==6068==Hint: address points to the zero page.
#0 0x558c9691bb23 (/notroot/Documents/asmcheckcpp.e+0x137b23)
#1 0x7faa9eb49ce2 (/usr/lib/libc.so.6+0x23ce2)
#2 0x558c9680311d (/notroot/Documents/asmcheckcpp.e+0x1f11d)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/notroot/Documents/asmcheckcpp.e+0x137b23)
==6068==ABORTING
但是我不知道为什么。 -我已经解决了这个问题,所以这段代码:
asm( "mov 4, %%eax" : : : "eax" );
有效但显示
cout << 'a' << endl;
char z[]="x";
asm( "mov $4, %%eax \n"
"mov $1, %%ebx \n"
"mov $2, %%edx \n"
"int $0x80"
:
: "ecx"(&z)
: "eax", "ebx", "edx" );
cout << 'a' << endl;
不是
a
a
在屏幕上