- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我不太了解汇编。以下代码用于写入硬件端口。
编译器在使用内联 asm 的每一行中给出操作数类型不匹配错误。当我编译时,我得到这些错误:
port.cpp: Assembler messages:
port.cpp:27: Error: operand type mismatch for 'out'
port.cpp:34: Error: operand type mismatch for 'in'
port.cpp:51: Error: operand type mismatch for 'out'
port.cpp:69: Error: operand type mismatch for 'out'
port.cpp:75: Error: operand type mismatch for 'in'
port.cpp:94: Error: operand type mismatch for 'out'
port.cpp:100: Error: operand type mismatch for 'in'
端口.h
#ifndef __PORT_H
#define __PORT_H
#include "types.h"
class Port
{
protected:
Port(uint16_t portnumber);
~Port();
uint16_t portnumber;
};
class Port8Bit : public Port
{
public:
Port8Bit(uint16_t portnumber);
~Port8Bit();
virtual uint8_t Read();
virtual void Write(uint8_t data);
};
class Port8BitSlow : public Port8Bit
{
public:
Port8BitSlow(uint16_t portnumber);
~Port8BitSlow();
virtual void Write(uint8_t data);
};
class Port16Bit : public Port
{
public:
Port16Bit(uint16_t portnumber);
~Port16Bit();
virtual uint16_t Read();
virtual void Write(uint16_t data);
};
class Port32Bit : public Port
{
public:
Port32Bit(uint16_t portnumber);
~Port32Bit();
virtual uint32_t Read();
virtual void Write(uint32_t data);
};
#endif
端口.cpp
#include "port.h"
Port::Port(uint16_t portnumber)
{
this->portnumber = portnumber;
}
Port::~Port()
{
}
Port8Bit::Port8Bit(uint16_t portnumber)
: Port(portnumber)
{
}
Port8Bit::~Port8Bit()
{
}
void Port8Bit::Write(uint8_t data)
{
__asm__ volatile("outb %0, %1" :: "a" (data), "Nd" (portnumber));
}
uint8_t Port8Bit::Read()
{
uint8_t result;
__asm__ volatile("inb %1, %0" : "=a" (result) : "Nd" (portnumber));
return result;
}
Port8BitSlow::Port8BitSlow(uint16_t portnumber)
: Port8Bit(portnumber)
{
}
Port8BitSlow::~Port8BitSlow()
{
}
void Port8BitSlow::Write(uint8_t data)
{
__asm__ volatile("outb %0, %1\njmp 1f\n1: jmp 1f\n1:" :: "a" (data), "Nd" (portnumber));
}
Port16Bit::Port16Bit(uint16_t portnumber)
: Port(portnumber)
{
}
Port16Bit::~Port16Bit()
{
}
void Port16Bit::Write(uint16_t data)
{
__asm__ volatile("outw %0, %1" :: "a" (data), "Nd" (portnumber));
}
uint16_t Port16Bit::Read()
{
uint16_t result;
__asm__ volatile("inw %1, %0" : "=a" (result) : "Nd" (portnumber));
return result;
}
Port32Bit::Port32Bit(uint16_t portnumber)
: Port(portnumber)
{
}
Port32Bit::~Port32Bit()
{
}
void Port32Bit::Write(uint32_t data)
{
__asm__ volatile("outl %0, %1" :: "a" (data), "Nd" (portnumber));
}
uint32_t Port32Bit::Read()
{
uint32_t result;
__asm__ volatile("inl %1, %0" : "=a" (result) : "Nd" (portnumber));
return result;
}
我该如何纠正?程序结构有什么问题吗?
最佳答案
OP 从未显示 types.h
但后续评论仅表明存在一种真正的可能性,即 uint16_t
未定义为 16 位类型。在 x86/x86-64 上,这样的类型可以定义为:
typedef unsigned short int uint16_t;
错误的产生是因为为了为扩展内联汇编模板选择寄存器,GCC 使用约束中传递的类型的大小来确定所选寄存器是否应为 16/32/64 位寄存器。如果大小不是 16 位,则会选择错误大小的寄存器,生成的程序集将有一个操作数不匹配。
在这种情况下,显然 OP 在创建自己的 uint16_t
定义时不正确地指定了错误的大小类型。端口命令(in、out 等)只将DX(16 位)作为寄存器操作数,而不是EDX、RDX 或 DL。如果生成的寄存器不是 DX,则代码将编译/汇编时出现 OP 看到的错误。
关于c++ - 内联汇编 : operand type mismatch for 'out' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47467839/
我正在尝试为一个简单的数学 Vector 类重载 += 运算符,以对两个 vector 的元素求和,如下所示: vector1 += vector2 部分Vector2D.h: #ifndef _VE
我正在尝试在 ASM 中编写一个简单的 for 循环。我需要访问两个数组,它们是在 C++ 代码片段之外编写的(即 OrigChars 和 EncrChars) char temporary_
Qt 版本 5.01 平台 windows 64 位 问题:错误:没有操作数“ #include #include #include namespace { std::ost
#include #include #define SIGBAD(signo) ((signo) = NSIG) int sigaddset(sigset_t *set, int signo
请看下面的代码。我正在使用 Apache Derby 作为嵌入式数据库 public List getDetails(String name) { List details =
我和我的讲师/实验室助理都被难住了。 出于某种原因,以下 HLSL 代码在输出窗口中返回: error X8000 : D3D11 Internal Compiler error : Invalid
我有一个创建时间跟踪器的 NPM 包,它使用 for in 来定位 MD 文件的标题,然后将其转换为跟踪器。目前,在 Mac 上运行它时工作正常,在 Windows 上我收到 dirname:miss
请注意这个问题是不是 this 的副本或 this ,因为其他问题没有运算符(operator) 组件,不要询问我正在询问的参数和参数的详细信息。 我将使用 vb.net 教授第一门编程类(class
输入 sudo apt autoremove 后出现此错误在终端 readlink: missing operand Try 'readlink --help' for more informatio
为什么 GCC 给我这个错误?我在这里做错了什么? temp.c: In function main: temp.c:6: error: invalid operands to binary +
我对此很陌生,我正在尝试将值从一个数组移动到另一个数组, 它假设是: vec1 = 1, 2, 3, 4, 5 vec2 = 5, 4, 3, 2, 1 但我收到一个错误:“指令操作数必须是相同的大小
我有一个 OR 表达式,它应该返回不是 NaN 的操作数: (1 || NaN) // evaluates to 1 (NaN || 1) // evaluates to 1 但是当另一个操作数也是一
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 4 年前。 Improve th
这道题是基于 Javascript 的,但适用于一般的逻辑运算 拿代码举例 if (baseText[i] == "."){ /*splice array*/;} if (baseText[
我似乎无法找到使程序运行的问题。 C 告诉我“错误:二进制操作数无效!= 'grocerylist'(又名 structgrocerylist)和 'int' 当我尝试解决此问题时,会弹出其他错误,除
我正在查看 the docs并尝试了解运算符的实际工作方式。 The increment operator (++) increments its operand by 1. The incremen
我有一个很长的 json 字符串,"attributeName":"Loc ID"},"operands":["10000"]}],"Frequency":{"type":" 这个只是其中的一部分,我
目前,我尝试编译 OpenVDB,它依赖于 Threading Building Blocks。我收到以下错误: In file included from /usr/include/tbb/enum
我收到的错误: /usr/include/c++/7/bits/stl_function.h:386: error: no operator " NearestNeighbor::nearest_pa
我有一个类Color , 那有 friend std::ostream& operator void print_head(const T& head, sost& o) { o (rsym,
我是一名优秀的程序员,十分优秀!