![]() |
![]() |
#1 |
Registered User
Join Date: Feb 2011
Location: Italy/Rome
Posts: 2,344
|
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? |
![]() |
![]() |
#2 |
Registered User
Join Date: Jun 2016
Location: europe
Posts: 1,068
|
Code:
and.w #-1<<4,d1 ; %1111111111110000 |
![]() |
![]() |
#3 |
Registered User
Join Date: Feb 2011
Location: Italy/Rome
Posts: 2,344
|
@a/b
Soucery! How does it work? |
![]() |
![]() |
#4 |
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,643
|
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... |
![]() |
![]() |
#5 |
Registered User
Join Date: Feb 2011
Location: Italy/Rome
Posts: 2,344
|
|
![]() |
![]() |
#6 |
Total Chaos forever!
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,200
|
Except that it should be the bitwise inverse of #-1.
|
![]() |
![]() |
#7 |
Registered User
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
|
errrr...
Code:
and.w #$fff0 |
![]() |
![]() |
#8 |
move.l #$c0ff33,throat
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,865
|
Yeah, a/b's solution is completely correct!
|
![]() |
![]() |
#9 |
Registered User
Join Date: May 2018
Location: Ireland
Posts: 692
|
|
![]() |
![]() |
#10 |
Registered User
Join Date: Jun 2016
Location: europe
Posts: 1,068
|
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... |
![]() |
![]() |
#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 | |
Registered User
Join Date: Jun 2016
Location: europe
Posts: 1,068
|
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 | |
![]() |
||||
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 |
|
|