c++ - 我试图将一个字符串值从一个变量分配给 C++ 嵌入式汇编程序中的第二个字符串变量,但我得到了错误的操作数类型
问题描述
我必须根据 c++ 中的值是正数、负数还是等于零来打印一条语句,但判断的逻辑必须在汇编程序中。我已经工作的逻辑但是当我尝试将字符串值移动到专用于输出的字符串时,我得到一个错误的操作数类型错误。
#include <iostream>
#include <string>
int main(){
double r;
std::string mNeg="r its negative, r = ",
mPos="r its positive, r = ",
mEqu="r its equal to zero, r = ",
mOutput;
_asm{
.
.
.
.
calculate r
.
.
.
.
;comparison
equal:
fld r
ftst
fstsw ax
fwait
sahf
ja Jpos
jb Jneg
mov mOutput, mEqu ;<---this is where the error happens
jmp fin
Jpos:
mov mOutput, mPos ;<---this is where the error happens
jmp fin
Jneg:
mov mOutput, mNeg ;<---this is where the error happens
fin:
}
std::cout<<mOutput<<r; ;<---here i'm supposed to print the output
}
解决方案
我终于这样做了。我把字符串做成了一个数组,decition就是数组中字符串的索引。
#include <iostream>
#include <string>
int main(){
int d;
double r;
std::string mOutput[3]={"r its equal to zero, r = ","r its positive, r = ","r its negative, r = "}; ;<-----Change
_asm{
.
.
.
.
calculate r
.
.
.
.
;comparison
equal:
fld r
ftst
fstsw ax
fwait
sahf
ja Jpos
jb Jneg
mov d, 0 ;<---change
jmp fin
Jpos:
mov d, 1 ;<---change
jmp fin
Jneg:
mov d, 2 ;<---change
fin:
}
std::cout<<mOutput[d]<<r; ;<---print the output
}
推荐阅读
- c# - 多个路由到同一个剃须刀页面
- regex - 替换bash中多行的值
- javascript - 以角度在每个页面上加载外部js
- dataframe - 对象不可调用错误 | 哪里功能
- reactjs - 在 microsoft edge 和 firefox 浏览器中运行 React 时出现空白屏幕
- elasticsearch - 当字段包含感叹号时,Elasticsearch 突出显示的文本中缺少文本
- javascript - 为什么清理命令在 Gradle React 本机项目中不起作用?
- c# - 转换列表
- > 列出
- >
- javascript - 销毁 DOM 元素时如何处理内存?
- angular - 角度材料中是否有任何带有过滤器功能的下拉菜单?注意:使用 mat-select 不是 mat-option