|
Instruction for the day |
|
adrianl (12:19 24/8/2006) VincceH (07:31 25/8/2006) Phlamethrower (09:48 25/8/2006) VincceH (19:34 25/8/2006) adrianl (11:38 25/8/2006) Phlamethrower (11:42 25/8/2006) adrianl (12:21 25/8/2006) ninj (13:11 25/8/2006) Phlamethrower (14:22 25/8/2006) ninj (14:35 25/8/2006) adrianl (14:42 25/8/2006)
|
|
Adrian Lees |
Message #79141, posted by adrianl at 12:19, 24/8/2006 |
Member
Posts: 1637
|
BIC R0,R0,R0,ASR #31 |
|
[ Log in to reply ] |
|
VinceH |
Message #79179, posted by VincceH at 07:31, 25/8/2006, in reply to message #79141 |
Lowering the tone since the dawn of time
Posts: 1600
|
My ARM assembler was never very good, but with the aid of google to remind myself what BIC and ASR actually do... (before I look, I think BIC is a pen - I mean, bit clear, and ASR is probably arithmetic shift right)
(Yup)
So...
Shift the contents of R0 right by 31 bits - so either every bit is 1 or 0 depending if the MSB was 1 or 0 - then use the result to perform a bit clear on R0.
Result: If the MSB is set (ie the contents are a -ve number) R0 will finish up containing zero. If the MSB is clear (ie the contents are a +ve number) R0 will finish up contianing that number.
What's my prize? |
|
[ Log in to reply ] |
|
Jeffrey Lee |
Message #79184, posted by Phlamethrower at 09:48, 25/8/2006, in reply to message #79179 |
Hot Hot Hot Hot Hot Hot Hot Hot Hot Hot Hot Hot Hot stuff
Posts: 15100
|
What's my prize? A single instruction to ensure a number is >= 0? |
|
[ Log in to reply ] |
|
Adrian Lees |
Message #79188, posted by adrianl at 11:38, 25/8/2006, in reply to message #79141 |
Member
Posts: 1637
|
TEQ R0,R0,ROR #1 |
|
[ Log in to reply ] |
|
Jeffrey Lee |
Message #79189, posted by Phlamethrower at 11:42, 25/8/2006, in reply to message #79188 |
Hot Hot Hot Hot Hot Hot Hot Hot Hot Hot Hot Hot Hot stuff
Posts: 15100
|
Check if a number is 0 or -1? |
|
[ Log in to reply ] |
|
Adrian Lees |
Message #79191, posted by adrianl at 12:21, 25/8/2006, in reply to message #79189 |
Member
Posts: 1637
|
Uh huh |
|
[ Log in to reply ] |
|
ninjah |
Message #79193, posted by ninj at 13:11, 25/8/2006, in reply to message #79189 |
Member
Posts: 288
|
Check if a number is 0 or -1? EOR R0, R0, R0 ASR #31 ? |
|
[ Log in to reply ] |
|
Jeffrey Lee |
Message #79194, posted by Phlamethrower at 14:22, 25/8/2006, in reply to message #79193 |
Hot Hot Hot Hot Hot Hot Hot Hot Hot Hot Hot Hot Hot stuff
Posts: 15100
|
Check if a number is 0 or -1? EOR R0, R0, R0 ASR #31 ? No, that sets a number to zero if it's -1 |
|
[ Log in to reply ] |
|
ninjah |
Message #79195, posted by ninj at 14:35, 25/8/2006, in reply to message #79194 |
Member
Posts: 288
|
Check if a number is 0 or -1? EOR R0, R0, R0 ASR #31 ? No, that sets a number to zero if it's -1 Or if it's already 0. And not otherwise. |
|
[ Log in to reply ] |
|
Adrian Lees |
Message #79196, posted by adrianl at 14:42, 25/8/2006, in reply to message #79195 |
Member
Posts: 1637
|
if (a < 0) a = -(a + 1)
ie. it's actually ABS(a) if a is in one's complement. which nobody uses
[Edited by adrianl at 15:49, 25/8/2006] |
|
[ Log in to reply ] |
|
VinceH |
Message #79203, posted by VincceH at 19:34, 25/8/2006, in reply to message #79184 |
Lowering the tone since the dawn of time
Posts: 1600
|
What's my prize? A single instruction to ensure a number is >= 0? As long as it comes with a free Iyonix, that's fine. |
|
[ Log in to reply ] |
|
|