- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将此 C++ 函数转换为 mips。我想我在循环中遇到了问题,因为当我运行它时,它给了我 13..1.17.5.. 但我的输出应该是两个 ip 地址:130.52.0.10 和 171.9.50.186
C++函数代码:
void IPtoDD(int arg0, char *arg1)
{
int temp, numChar, shift = 24;
for (int i=0; i<4; i++) {
temp = arg0 >> shift;
temp = temp & 0x000000ff;
numChar = byteToDec(temp,arg1);
arg1 += numChar;
*arg1++ = '.';
shift -= 8;
}
arg1--;
*arg1 = 0;
return;
}
MIPS 代码:
IPtoDD: addi $sp, $sp, -20
sw $ra, ($sp)
sw $s0, 4($sp)
sw $s1, 8($sp)
sw $s2, 12($sp)
sw $s3, 16($sp)
move $s0, $a0
move $s1, $a1
li $s3, 24 #s3=shift
li $s2, 0 #s2=i
li $t5, 0 #t5=temp
li $t3, 0
move $s1, $a1 #s1=*arg1
loop: srl $t5, $s0, $s3 #t3= numChar
and $t5, $t5, 0xff #t4= (*arg1)
move $a0, $t5
move $a1, $s1
jal byteToDec
move $t3, $v0
add $s1, $s1, $t3
li $t5, '.'
sb $t5, ($a1)
addi $a1, $a1, 1
addi $s3, $s3, -8
addi $s2, $s2, 1
blt $s2, 4, loop
addi $s1, $s1, -1
sb $0, ($a1)
lw $s3, 16($sp)
ra: lw $s2, 12($sp)
lw $s1, 8($sp)
lw $s0, 4($sp)
lw $ra, ($sp)
addi $sp, $sp, 20
jr $ra
请帮帮忙。我尝试了很多但无法使其正常运行。
编辑:byteToDec 的 C++ 函数
int byteToDec(int arg0, char *arg1)
{
int temp, flag = 0, count = 0;
if (arg0==0) {
*arg1 = '0';
return 1;
}
else {
temp = arg0/100;
if (temp != 0) {
*arg1++ = (char) temp + 0x30;
count++;
flag = 1;
}
temp = (arg0 % 100) / 10;
if ((flag!=0) || (temp != 0)) {
*arg1++ = (char) temp + 0x30;
count++;
}
temp = arg0 % 10;
*arg1 = (char) temp + 0x30;
count++;
return count;
}
}
MIPS 中的 byteToDec:
byteToDec: #t0= temp
#t1= flag
#v0= count
#t3= (*arg1)
bne $a0, $0, else
li $t3, '0'
sb $t3, ($a1)
li $v0, 1
jr $ra
else: div $t0, $a0, 100
beq $t0, 0, cont
bp2: addi $t3, $t0, 0x30
sb $t3, ($a1)
addi $a1, $a1, 1
addi $v0, $v0, 1
li $t1, 1
cont: rem $t3, $a0, 100
div $t0, $t3, 10
bne $t1, 0, nxtIf
beq $t0, 0, endElse
nxtIf: addi $t3, $t0, 0x30
sb $t3, ($a1)
addi $a1, $a1, 1
addi $v0, $v0, 1
endElse:rem $t0, $a0, 10
bp1: addi $t3, $t0, 0x30
sb $t3, ($a1)
addi $v0, $v0, 1
ra1: jr $ra
最佳答案
您正在使用 t3
作为循环计数器,然后在 byteToDec
函数中丢弃 t3
。 MIPS 惯例是 t
寄存器是“临时”的,不能跨函数调用使用。你应该把你的循环变量放在 s
寄存器(一个“保存”寄存器)中,如果你的被调用函数需要重用相同的 s
寄存器,它需要保存它到堆栈或其他东西并在返回给被调用者之前恢复值。
关于c++ - MIPS : loop goes to infinity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19285732/
如果我们看一下 C 语言的委员会草案:n1570尤其是关于复杂数学函数行为的 Annex G,我们可以看到复指数在无穷大处具有以下行为: cexp(+infinity+I*infinity)=+/-i
有人可以向我解释一下这是如何工作的吗?在查找最高数方法中,每个数字都大于 -Infinity。为什么它取最高数?与最小数字查找器相同,它如何选择最小数字,所有数字都小于 Infinity。 //fin
我想测试无穷大是否等于Java中的无穷大: Double.POSITIVE_INFINITY == Double.POSITIVE_INFINITY 当结果证明是真的时,我感到很惊讶。我的问题是两个无
我正在研究 JavaScript 的数字类型系统。 我正在使用 Chrome,当我为一个数字文字计算 15-- 时,我得到了一个 ReferenceError,因为递减一个常量是没有意义的。 当我按预
如果 Infinity === Infinity >> true 和 typeOf Infinity >> "number" 那是为什么 Infinity / Infinity >>NaN 而不是 1
问题很简单: Infinity == Infinity >> true Infinity == 1/0 >> true Infinity == Infinity == 1/0 >> false 为什么
据我所知,在数学中 Infinity 和 NaN 都是模糊值。众所周知: console.log(NaN == NaN); //-> false 同时 console.log(Infinity==In
我正在尝试创建一个选择查询,并过滤一个等于“无穷大”和“-无穷大”的日期时间字段: SELECT * FROM mytable WHERE dt = OR dt = 我该怎么做? 最佳答案 SEL
在一种情况下,我们必须在 Postgres 数据库中存储 +infinity 和 -infinity 的值? 应该考虑什么是合适的值? 如果没有,请提出最合适的替代方案。 最佳答案 您实际上可以将 +
这个问题在这里已经有了答案: Why is pow(-infinity, positive non-integer) +infinity? (1 个回答) 关闭4年前。 我尝试了两种不同的方法在 Ja
C99 附件 F(IEEE 浮点支持)是这样说的: pow(−∞, y) returns +∞ for y > 0 and not an odd integer. 但是,比方说,(−∞)0.5 实际上
在数学中,2 个无穷大既不等于,也不大于或小于 then。那么是什么给了? 在 irb 中,Float::INFINITY == Float::INFINITY(在 ruby 1.9.3 中测试)
文字未呈现在应用程序的主页上,这是我遇到问题的地方。我是新手,因此是新手。希望有人可以提供一些见解,或者根据我遇到的错误调整代码。 为了进一步说明,当我启动“ flutter ”时将显示此页面。将显示
为什么会这样: 1 === 1;// true 0 === -0;// true 1/0 === 1/-0;// false 原因: 1/0=Infinite; 1/-0=-Infinite; 问题:
我一直在试验冒泡排序代码,因为我最近开始了解 C 代码。但是,我无法将 NAN 输入到代码中,以便在构建和运行它时打印出来。我在使用 INFINITY AND -INFINITY 时遇到了同样的问题。
我使用 ANSI C89(不是 C++),我想生成 NaN、-Infinity 和 +Infinity。 有没有标准的方法(例如标准宏)?或者是否有任何独立于平台和编译器的方法来生成这些数字? flo
VB6 似乎并没有让将 +infinity、-infinity 和 NaN 存储到双变量中那么容易。如果可以的话,这会有所帮助,这样我就可以在复数的上下文中与这些值进行比较。如何? 最佳答案 一些不同
使这两个函数对于值 infinity 和 -infinity 表现不同的原因可能是什么。有没有人发现这种不一致有用? parseInt(Infinity); // NaN parseFloat(Inf
npc_objects = {}; TURKEYLENGTH = (Math.max.apply(Math, Object.keys(npc_objects))) + 1; console.log
我正在尝试制作一个程序,用莱布尼兹方程作为 pi 日的属性来估计 pi,但是控制台没有打印出我想要的估计 pi 值,而是无限次打印“无穷大”,直到我终止执行。我非常非常困惑,需要帮助!代码: im
我是一名优秀的程序员,十分优秀!