12 August 2020, 10:46 | #1 |
Registered User
Join Date: Feb 2011
Location: Italy/Rome
Posts: 2,299
|
Need Help to round number
I'm using this shitty way to round number:
lsr.w #4,d1 lsl.w #4,d1 Is there a fast way beside table? |
12 August 2020, 11:30 | #2 |
Registered User
Join Date: Jun 2016
Location: europe
Posts: 1,039
|
Code:
and.w #-1<<4,d1 ; %1111111111110000 |
12 August 2020, 14:28 | #3 |
Registered User
Join Date: Feb 2011
Location: Italy/Rome
Posts: 2,299
|
@a/b
Soucery! How does it work? |
12 August 2020, 15:54 | #4 |
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
|
your shifting exercise does nothing but clear the lower 4 bits ;-)
edit: well, it also sets some status flags which you aren't using anyway, so... |
12 August 2020, 16:03 | #5 |
Registered User
Join Date: Feb 2011
Location: Italy/Rome
Posts: 2,299
|
|
12 August 2020, 16:39 | #6 |
Total Chaos forever!
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,187
|
Except that it should be the bitwise inverse of #-1.
|
12 August 2020, 17:30 | #7 |
Registered User
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
|
errrr...
Code:
and.w #$fff0 |
12 August 2020, 18:02 | #8 |
move.l #$c0ff33,throat
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
|
Yeah, a/b's solution is completely correct!
|
12 August 2020, 18:48 | #9 |
Registered User
Join Date: May 2018
Location: Ireland
Posts: 678
|
|
12 August 2020, 20:02 | #10 |
Registered User
Join Date: Jun 2016
Location: europe
Posts: 1,039
|
The idea behind -1 is that it works with any size, it's automagically expanded to $ff, $ffff, or $ffffffff by assembler.
If you want to be strict, you could go with ~(1<<N-1), where N is the number of bits you want to clear, and get the same size-independent expression but -1 is just so simple and I personally don't find it confusing. No big deal either way... |
12 August 2020, 20:44 | #11 | |
Registered User
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
|
Quote:
I use the bit shift stuff alot in VASM. Consider the BLTSIZE register: Code:
move.w #(32<<6)+(32/16),BLTSIZE Using the OR directive is equally useful. Code:
BIT15: equ $8000 BIT14: equ $4000 or.w #(BIT15|BIT14),d0 Code:
move.w #(DMAF_SETCLR!DMAF_MASTER!DMAF_COPPER!DMAF_RASTER!DMAF_BLITTER),DMACON(a5) |
|
12 August 2020, 21:32 | #12 | |
Registered User
Join Date: Jun 2016
Location: europe
Posts: 1,039
|
Quote:
And when I do hardcode something related to a 'global parameter', the reason typically being optimizations, I add an assert (simple macro) that stop the assember and I don't have to deal with the code exploding during run-time. |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
EAB/Lemon Super League 2019 Round 7: Mystery Round Nominations | john4p | EAB's competition | 4 | 28 April 2019 13:00 |
EAB/Lemon Super League 2018: Round 7 - Mystery Round Nominations | john4p | EAB's competition | 4 | 29 April 2018 01:09 |
EAB/Lemon Super League 2017: Round 7 - Mystery Round Nominations | Graham Humphrey | EAB's competition | 4 | 21 May 2017 09:02 |
HELP! A600 number 2 down! :( | Snowy | support.Other | 5 | 04 December 2011 22:12 |
Your wii number? | T_hairy_bootson | Retrogaming General Discussion | 21 | 26 January 2007 18:35 |
|
|