首页 > 解决方案 > 我试图将一个字符串值从一个变量分配给 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
}

标签: c++assemblyx86inline-assembly

解决方案


我终于这样做了。我把字符串做成了一个数组,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
}

推荐阅读