小编MrP*_*le5的帖子

itoa为负数?

赏金:为提供代码的任何人提供+50声望点,使此子程序与负数一起使用.

我写了一个MIPS程序,将华氏温度转换为摄氏温度.它会打开自己的输出窗口(即UART),并以摄氏度正确显示该值.它在从C到汇编的调用时执行所有这些操作,反之亦然.整个代码发布在下方.

我正在努力让它与负数一起工作.由于某种原因,现在只是画一个空白.如何更改我的itoa功能来编写此检查?

任何人都有任何想法如何在MIPS中使用负值?

.ent itoa
itoa:
  // putting the stack frame together
  addiu sp, sp, -16
  sw    fp, 12(sp)
  move  fp, sp
  sw    a0, 16(fp)
  sw    a1, 20(fp)
  sw    s0, 4(fp)
  sw    s1, 0(sp)

  // there is no divide immediate, so using s1
  li    s1, 10

  itoa_div_begin:
        divu  a0, s1
        mfhi  s0
        mflo  a0

        addiu s0, s0, 0x30
        addiu sp, sp, -1
        sb    s0, 0(sp)

        beq   a0, zero, itoa_div_done
        nop

        j     itoa_div_begin
        nop

  itoa_div_done:
  itoa_copy_begin:
        lb    s0, …
Run Code Online (Sandbox Code Playgroud)

assembly mips

5
推荐指数
1
解决办法
734
查看次数

Microsoft.Practices.Unity无处可寻

Microsoft.Practices.Unity当我尝试将其添加为参考时,使用Visual Studio 2012并且不知道为什么不在汇编选项卡(或任何选项卡)下.使用最初是Visual Studio 2012上的Visual Studio 2010解决方案的C#解决方案.

这个命名空间是否已弃用和/或是否有另一个命名空间可以使用该InjectionConstructor对象?

任何人都知道为什么我的Microsoft VS 2012没有Microsoft.Practices.Unity命名空间?

c#

5
推荐指数
1
解决办法
1万
查看次数

该函数的运算符参数太多?

制作了我自己的字符串类(显然是为了家庭作业),并且我的两个运算符出现了奇怪的语法错误。我的相等和添加运算符声称我有太多参数(即在我的 .h 文件中),但随后又声称该方法甚至不属于我的 .cpp 文件中的类!

我什至将相等运算符设为朋友,但智能感知仍然给我相同的错误消息。

有谁知道我做错了什么?

friend bool operator==(String const & left, String const & right);
Run Code Online (Sandbox Code Playgroud)

字符串.h

bool operator==(String const & left, String const & right);
String const operator+(String const & lhs, String const & rhs);
Run Code Online (Sandbox Code Playgroud)

字符串.cpp

bool String::operator==(String const & left, String const &right)
{
    return !strcmp(left.mStr, right.mStr);
}

String const String::operator+(String const & lhs, String const & rhs)
{
    //Find the length of the left and right hand sides of the add operator
    int lengthLhs = strlen(lhs.mStr); …
Run Code Online (Sandbox Code Playgroud)

c++ operator-overloading

2
推荐指数
1
解决办法
2万
查看次数

找到一个子集,但F#不会让我比较两组不同的长度

我试图找出一组是否是另一组的子集.如果两个集的长度相同,我的代码就可以正常工作.

例如,

如果,我的代码将返回true

x = [a; b; c] y = [a; b; c]

如果,我的代码将返回false

x = [a; b; c] y = [a; b; d]

但是,如果我尝试,我的代码甚至都不会编译

x = ['a';'b';'c'] y = ['a';'b';'c';'d']

它应该返回true,但是我收到以下错误消息:

Type mismatch. 
Expecting a Set<char * char * char> but given a Set<char * char * char * char> 

The tuples have differing lengths of 3 and 4
Run Code Online (Sandbox Code Playgroud)

我的代码如下

let mySubList x y =
printfn "%A is a proper subset of %A: %b" x y (Set.isSubset x y) …
Run Code Online (Sandbox Code Playgroud)

f#

2
推荐指数
1
解决办法
119
查看次数

麻烦与argc和argv

尝试向我的程序添加命令行参数.所以我正在进行实验,无法弄清楚这对我生命的智能警告.它继续说它期待')',但我不知道为什么.

这是它不喜欢的代码:

    // Calculate average
    average = sum / ( argc – 1 );   
Run Code Online (Sandbox Code Playgroud)

然后它强调减法运算符.以下是完整的计划.

#include <iostream>

int main( int argc, char *argv[] )
{
    float average;
    int sum = 0;

    // Valid number of arguments?
    if ( argc > 1 ) 
    {
       // Loop through arguments ignoring the first which is
       // the name and path of this program
       for ( int i = 1; i < argc; i++ ) 
       {
           // Convert cString to int 
           sum += atoi( …
Run Code Online (Sandbox Code Playgroud)

c++ argv argc

0
推荐指数
1
解决办法
906
查看次数

复制构造函数不工作?

OOP有些新东西(即C程序员转换为C++)并且无法弄清楚为什么我的背包类中的数据成员是空的.我向我的背包传递了一系列药水,但数据成员说mType =""(即什么都没有).

我以前从来没有觉得这在节目中输了.开始讨厌OOP(即开玩笑......但这非常令人沮丧).

main.cpp中

#include <iostream>
#include "rogue.h"
#include "weapon.h"
#include "backpack.h"
#include "potion.h"
#include "coinpouch.h"

int main()
{
Potion myFavoritePotions[5];
myFavoritePotions[0].setName("love");
myFavoritePotions[1].setName("hate");
myFavoritePotions[2].setName("shrink");
myFavoritePotions[3].setName("grow");
myFavoritePotions[4].setName("disappear");
BackPack myFavoriteBackPack(myFavoritePotions);
Weapon myFavoriteWeapon("AK-47");
Weapon mySecretWeapon("Me-262");
Weapon myLeastFavoriteWeapon("Luger");
CoinPouch myFavoritePurse(6,5,4,3);
Rogue myFavoriteRogue("Cynic", myFavoriteWeapon, mySecretWeapon, myFavoriteBackPack, myFavoritePurse);

mySecretWeapon = myFavoriteWeapon;  

myFavoriteRogue.setOffHand(myLeastFavoriteWeapon);
//std::cout << myFavoriteRogue.getOffHand();

return 0;
}
Run Code Online (Sandbox Code Playgroud)

potion.cpp

#include <iostream>
#include "potion.h"

//Manager function definitions

//Default constructor
Potion::Potion()
{}

//Constructor
Potion::Potion(std::string name)
:mName(name)
{
std::cout << "Potion's constructor " << std::endl;
}

//Destructor
Potion::~Potion()
{ …
Run Code Online (Sandbox Code Playgroud)

c++ oop copy-constructor

0
推荐指数
2
解决办法
1543
查看次数

递归地查找子字符串

不知道为什么这个问题对我来说太难了.迭代地,这是蛋糕,但是一旦堆叠展开,它就会破坏我的整个功能.

它正确地找到针并且如果找到它则给函数赋值true.但是,一旦调用堆栈展开,它就会一直恢复为false.有谁知道如何解决这个或我的代码我做错了什么?

这是我到目前为止所拥有的......

bool mySubStr(char * needle, char * haystack)
{
    int needleLength = strlen(needle);
    int haystackLength = strlen(haystack);
    bool found = false;

    if(needleLength < haystackLength)
    {
        if(strncmp(haystack, needle, needleLength) == 0)
        {
            found = true;
        }
        else
        {
            mySubStr(needle, haystack + 1);
        }
    }

    return found;
}
Run Code Online (Sandbox Code Playgroud)

c++

0
推荐指数
1
解决办法
124
查看次数

标签 统计

c++ ×4

argc ×1

argv ×1

assembly ×1

c# ×1

copy-constructor ×1

f# ×1

mips ×1

oop ×1

operator-overloading ×1