愚蠢的问题,但我在gcc中找不到必要的标志.基本上,我在我的C程序中有以下内联汇编代码
__asm__ __volatile__ ("lea ebx, [timings] \n\t");
Run Code Online (Sandbox Code Playgroud)
编译时,我得到一个错误消息,上面写着:Error: invalid char '[' beginning operand 2[时间]'`
现在我记得很久以前我使用某种标志告诉编译器它是x86内联汇编.但无法在网上找到它,也许有人请告诉我哪个国旗我必须使用?
非常感谢!
我正在尝试将一些内联汇编写入C.我有两个数组作为输入,我需要的是将array1中的一个元素复制到array2中,以下是我目前所拥有的:
asm (
"movl %0,%%eax;"
"movl %1,%%ebx;"
"movl (%%eax),%%ecx;"
"movl %%ecx,(%ebx);"
"xor %%ecx,%%ecx;"
"movl 4(%%eax),%%ecx;"
//do something on %ecx
"movl %%ecx,4(%ebx);" //write second
:
:"a"(array1),"b"(array2)
);
Run Code Online (Sandbox Code Playgroud)
为什么我会出现分段错误?
我有这个函数使用SSE2将一些值加在一起它应该将lhs和rhs加在一起并将结果存储回lhs:
template<typename T>
void simdAdd(T *lhs,T *rhs)
{
asm volatile("movups %0,%%xmm0"::"m"(lhs));
asm volatile("movups %0,%%xmm1"::"m"(rhs));
switch(sizeof(T))
{
case sizeof(uint8_t):
asm volatile("paddb %%xmm0,%%xmm1":);
break;
case sizeof(uint16_t):
asm volatile("paddw %%xmm0,%%xmm1":);
break;
case sizeof(float):
asm volatile("addps %%xmm0,%%xmm1":);
break;
case sizeof(double):
asm volatile("addpd %%xmm0,%%xmm1":);
break;
default:
std::cout<<"error"<<std::endl;
break;
}
asm volatile("movups %%xmm0,%0":"=m"(lhs));
}
Run Code Online (Sandbox Code Playgroud)
我的代码使用这样的函数:
float *values=new float[4];
float *values2=new float[4];
values[0]=1.0f;
values[1]=2.0f;
values[2]=3.0f;
values[3]=4.0f;
values2[0]=1.0f;
values2[1]=2.0f;
values2[2]=3.0f;
values2[3]=4.0f;
simdAdd(values,values2);
for(uint32_t count=0;count<4;count++) std::cout<<values[count]<<std::endl;
Run Code Online (Sandbox Code Playgroud)
但是这不起作用,因为当代码运行时,输出1,2,3,4而不是2,4,6,8
我在Visual C++中使用内联汇编,并且已经尝试了几天以获得int 21h以使用我的程序.其他中断工作(int 3)让我相信要么我21h错误或者某种方式被阻止.我使用int 21h时只会遇到运行时错误.如果我评论它可以移动寄存器罚款.
到目前为止,我已经将它们结合在了一起:
int _tmain(int argc, _TCHAR* argv[])
{
__asm {
mov ah, 1h
int 21h
mov dl, al
mov ah, 2h
int 21h
}
}
Run Code Online (Sandbox Code Playgroud) 如何使用8086程序集从BIOS获取有关连接到PC(软盘,HDD,USB磁盘驱动器,闪存驱动器)的存储设备的信息.我正在使用VS 2008.你能指点我参考书或一些信息吗?我想检测所有工作这样的设备,并能够读取和写入它们.谢谢.
最奇怪的错误输出:
#include <iostream>
int main(int arg, char **LOC[])
{
asm
(
"mov eax, 0CF;"
"pusha;"
);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它抱怨,这是GCC的错误:
ts:汇编程序消息:
ts:31:错误:'mov'的内存引用太多
我在linux x86_64上构建了一个用C和内联汇编编写的简短程序.它应该写一个字符串给stdout.我在互联网上的一篇文章中找到了它:
int write_call( int fd, const char * str, int len ){
long __res;
__asm__ volatile ( "int $0x80":
"=a" (__res):"0"(__NR_write),"b"((long)(fd)),"c"((long)(str)),"d"((long)(len)) );
return (int) __res;
}
void do_write( void ){
char * str = "Paragon output string.\n";
int len = strlen( str ), n;
printf( "string for write length = %d\n", len );
n = write_call( 1, str, len );
printf( "write return : %d\n", n );
}
int main( int argc, char * argv[] ){
do_write();
return EXIT_SUCCESS; …Run Code Online (Sandbox Code Playgroud) 使用Microsoft的编译器的Visual C ++,允许我们使用以下命令定义内联汇编代码:
__asm {
nop
}
Run Code Online (Sandbox Code Playgroud)
我需要的是一个宏,可以将这样的指令乘以n次:
ASM_EMIT_MULT(op, times)
Run Code Online (Sandbox Code Playgroud)
例如:
ASM_EMIT_MULT(0x90, 160)
Run Code Online (Sandbox Code Playgroud)
那可能吗?我该怎么办?
我正在编写一个简单的引导程序,并且有一个getch功能。
char getch()
{
uint16_t inchar;
__asm__ __volatile__ ("int $0x16\n\t"
: "=a"(inchar)
: "0"(0x0));
return (char)inchar;
}
Run Code Online (Sandbox Code Playgroud)
我尝试了第一个显而易见的解决方案,即删除inchar变量对char的强制转换,但是当我打印它时,仍然返回char而不是代码。
我的println实现:
void println(char *str)
{
while (*str)
{
// AH=0x0e, AL=char to print, BH=page, BL=fg color
__asm__ __volatile__ ("int $0x10"
:
: "a" ((0x0e<<8) | *str++),
"b" (0x0000));
}
}
Run Code Online (Sandbox Code Playgroud)
链接描述文件:
ENTRY(start);
SECTIONS
{
. = 0x7C00;
.text : {
/* Place the code in hw.o before all other code */
boot.o(.text);
*(.text);
}
/* Place …Run Code Online (Sandbox Code Playgroud) 我试图从C调用一些汇编代码。最近,我在将程序从x86切换到x86-64之前开始工作。我有以下代码:
__asm__ __volatile__("lidtl (%0)" : : "r" (&idt_reg));
Run Code Online (Sandbox Code Playgroud)
哪里&idtreg是对结构的引用。用GCC进行编译会给我这个错误:
'lidt'的无效指令后缀
当我添加$令牌时:
__asm__ __volatile__("lidtl $(%0)" : : "r" (&idt_reg));
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
非法的立即寄存器操作数(%rax)
为什么会出现此问题,我该如何解决?