Discussion:
How Does NOR in MIPS Work?
(too old to reply)
Hien Goi
2004-07-17 04:05:18 UTC
Permalink
bash-2.03$ more test1.mips
.globl main

main: addi $1, $0, 2
addi $2, $0, 3
add $4, $0, $1
trap 1
add $4, $0, $2
trap 1
slt $3, $1, $2
slt $4, $2, $1
nor $1, $3, $4
trap 1
add $4, $3, $0
trap 1
add $4, $1, $0
trap 1
trap 10
bash-2.03$ java mips.mak test1 test1
bash-2.03$ java mips.cpu test1
2301-2bash-2.03$

Why is my final output -2? Shouldn't it be 0?
I tried this code on Ampere and Wirth, and my friend tried it on Watt and we
both get the same 2301-2 result.

Thanks,
Hien.
Danny Su
2004-07-17 07:35:09 UTC
Permalink
It should be -2, because in $3 and $4 (after slt) you have 1 and 0 stored.
so the situation is like this:

in HEX:
00000001
00000000

now, bitwise NOR the 2 registers bit by bit and you get:
FFFFFFFE

in 2's complement, this means -2

Loading...