Discussion:
sub vs. subu
(too old to reply)
p***@cpu04.student.cs.uwaterloo.ca
2004-01-15 21:20:17 UTC
Permalink
what is the difference
Qinghua Yang
2004-01-15 21:43:05 UTC
Permalink
You subtract numbers as unsign numbers.
Post by p***@cpu04.student.cs.uwaterloo.ca
what is the difference
Troy Vasiga
2004-01-15 22:09:59 UTC
Permalink
Not quite. Consider:

(1) sub $1, $2, $3 and
(2) subu $1, $2, $3.

(1) takes the numbers in $2 and $3 as signed numbers. That is,
numbers in the range -2^31...2^31-1.

(2) takes the numbers in $2 and $3 as unsigned numbers. That is,
numbers in the range 0...2^32-1.

So, first thing is, you probably don't need to worry about this
(especially for A1 of this course). However, it is worth keeping the
bit-representations of numbers in the back of your mind, since we will
be talking about bits (in much more detail) later in the course.

Troy (t.v.)

On Thu, 15 Jan 2004 16:43:05 -0500, Qinghua Yang
Post by Qinghua Yang
You subtract numbers as unsign numbers.
Post by p***@cpu04.student.cs.uwaterloo.ca
what is the difference
joolean
2004-01-18 05:58:09 UTC
Permalink
a1p4 says we have to be correct to 2^32 - 1. does that mean we DO have to
worry about unsigned numbers for this assignment?
Post by Troy Vasiga
(1) sub $1, $2, $3 and
(2) subu $1, $2, $3.
(1) takes the numbers in $2 and $3 as signed numbers. That is,
numbers in the range -2^31...2^31-1.
(2) takes the numbers in $2 and $3 as unsigned numbers. That is,
numbers in the range 0...2^32-1.
So, first thing is, you probably don't need to worry about this
(especially for A1 of this course). However, it is worth keeping the
bit-representations of numbers in the back of your mind, since we will
be talking about bits (in much more detail) later in the course.
Troy (t.v.)
On Thu, 15 Jan 2004 16:43:05 -0500, Qinghua Yang
Post by Qinghua Yang
You subtract numbers as unsign numbers.
Post by p***@cpu04.student.cs.uwaterloo.ca
what is the difference
Jui-Yi (Eric) Kao
2004-01-18 20:31:22 UTC
Permalink
I believe I have built my subroutine to work for results upto 2^32 - 1, but
because of the instructions used in the driver provided (especially trap 1,
which seems to treat integers as signed 2's complement), the result is not
being displayed correctly (turns into a negative number once i go over
2^31 - 1).
This leads to two questions.
1) is there a trap that displays unsigned 32-bit integers up to 2^32 - 1?
2) how will our subroutines be tested? will a driver directly compare the
returned value to a register containing the correct result, or will the
tests depend on the trap output? (the problem is obvious if it were the
second case)

a related question is, whether there is a verion of llo and lhi that takes
unsigned integer constants up to 2^32 - 1 (so we can test out subroutines up
to that limit)

[3|_()0|)|_!|_`/
CS 241 Tutor
2004-01-19 01:58:58 UTC
Permalink
There is a webpage linked to from the cs241 webpage that lists all the
traps used in MIPS (you can find it under the MIPS link on the main part
of the page).
Your assignment will be marked by having your return values printed out
and matched against my values.
I am not going to be testing any values of n such that it matter whether
your output is signed or unsigned.

Greg
Post by Jui-Yi (Eric) Kao
I believe I have built my subroutine to work for results upto 2^32 - 1, but
because of the instructions used in the driver provided (especially trap 1,
which seems to treat integers as signed 2's complement), the result is not
being displayed correctly (turns into a negative number once i go over
2^31 - 1).
This leads to two questions.
1) is there a trap that displays unsigned 32-bit integers up to 2^32 - 1?
2) how will our subroutines be tested? will a driver directly compare the
returned value to a register containing the correct result, or will the
tests depend on the trap output? (the problem is obvious if it were the
second case)
a related question is, whether there is a verion of llo and lhi that takes
unsigned integer constants up to 2^32 - 1 (so we can test out subroutines up
to that limit)
[3|_()0|)|_!|_`/
Jui-Yi (Eric) Kao
2004-01-19 02:07:52 UTC
Permalink
Yes, I know there is that webpage. The reason why i asked is that there does
not seem to be such a trap listed on the webpage. So if it's not listed than
it doesn't exist in our implementation of mips?

[3|_()0|)|_!|_`/
Troy Vasiga
2004-01-19 16:24:50 UTC
Permalink
There isn't a trap which prints out the unsigned value: you can only
print out the value as a 2's complement number.

Troy (t.v.)

On Sun, 18 Jan 2004 21:07:52 -0500, "Jui-Yi \(Eric\) Kao"
Post by Jui-Yi (Eric) Kao
Yes, I know there is that webpage. The reason why i asked is that there does
not seem to be such a trap listed on the webpage. So if it's not listed than
it doesn't exist in our implementation of mips?
[3|_()0|)|_!|_`/
Anand
2004-01-19 18:18:28 UTC
Permalink
You could always write a subroutine to do this. If the number is positive,
then print it. If it's negative, print a minus sign then the absolute value
of the number.

So, if you have 0xFFFFFFFF (-1), then print '-' and |0xFFFFFFFF| = 1 You
end up with -1
--
Unix users - When all else fails, type:
'rm -R /'
Post by Troy Vasiga
There isn't a trap which prints out the unsigned value: you can only
print out the value as a 2's complement number.
Troy (t.v.)
On Sun, 18 Jan 2004 21:07:52 -0500, "Jui-Yi \(Eric\) Kao"
Post by Jui-Yi (Eric) Kao
Yes, I know there is that webpage. The reason why i asked is that there does
not seem to be such a trap listed on the webpage. So if it's not listed than
it doesn't exist in our implementation of mips?
[3|_()0|)|_!|_`/
CS 241 Tutor
2004-01-19 18:31:40 UTC
Permalink
This won't work. You will still be be printing out a negative number.
There is no easy way of taking a number like 0xFFFFFFFF (stored in a
register) and printing it out as a positive number.

Greg
Post by Anand
You could always write a subroutine to do this. If the number is positive,
then print it. If it's negative, print a minus sign then the absolute value
of the number.
So, if you have 0xFFFFFFFF (-1), then print '-' and |0xFFFFFFFF| = 1 You
end up with -1
--
'rm -R /'
Post by Troy Vasiga
There isn't a trap which prints out the unsigned value: you can only
print out the value as a 2's complement number.
Troy (t.v.)
On Sun, 18 Jan 2004 21:07:52 -0500, "Jui-Yi \(Eric\) Kao"
Post by Jui-Yi (Eric) Kao
Yes, I know there is that webpage. The reason why i asked is that there
does
Post by Troy Vasiga
Post by Jui-Yi (Eric) Kao
not seem to be such a trap listed on the webpage. So if it's not listed
than
Post by Troy Vasiga
Post by Jui-Yi (Eric) Kao
it doesn't exist in our implementation of mips?
[3|_()0|)|_!|_`/
Anand
2004-01-19 18:45:40 UTC
Permalink
Oh, sh*t. I read the newsgroup wrong. My bad.

--
Unix users - When all else fails, type:
'rm -R /'
Post by CS 241 Tutor
This won't work. You will still be be printing out a negative number.
There is no easy way of taking a number like 0xFFFFFFFF (stored in a
register) and printing it out as a positive number.
Greg
Post by Anand
You could always write a subroutine to do this. If the number is positive,
then print it. If it's negative, print a minus sign then the absolute value
of the number.
So, if you have 0xFFFFFFFF (-1), then print '-' and |0xFFFFFFFF| = 1
You
Post by CS 241 Tutor
Post by Anand
end up with -1
--
'rm -R /'
Post by Troy Vasiga
There isn't a trap which prints out the unsigned value: you can only
print out the value as a 2's complement number.
Troy (t.v.)
On Sun, 18 Jan 2004 21:07:52 -0500, "Jui-Yi \(Eric\) Kao"
Post by Jui-Yi (Eric) Kao
Yes, I know there is that webpage. The reason why i asked is that there
does
Post by Troy Vasiga
Post by Jui-Yi (Eric) Kao
not seem to be such a trap listed on the webpage. So if it's not listed
than
Post by Troy Vasiga
Post by Jui-Yi (Eric) Kao
it doesn't exist in our implementation of mips?
[3|_()0|)|_!|_`/
Loading...