How to find even odd in MIPS assembly using integer registers

我的梦境 提交于 2019-12-11 06:24:18

问题


How can I find whether the input is even or odd in MIPS? I am trying to find out using integer registers, but my program is not working. Here is the code:

li $s1,2

div $s0,$s1

mfhi $t0

xor $t1,$t0,$0

beq $t1,0,Even

j Odd

But this program shows even odd numbers as even this is because the result is in decimal like 0.3 . How can I solve this issue?


回答1:


You need to and the number which you want to check with 0x01.

This is how you use and in mips: and $d, $s, $t

If the value in target register is 1 then it is odd else even.



来源:https://stackoverflow.com/questions/13476421/how-to-find-even-odd-in-mips-assembly-using-integer-registers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!