10 November 2021, 18:33 | #1 |
Registered User
Join Date: Feb 2018
Location: Northumberland, UK
Posts: 272
|
Fast switch between '1' and '0'
Hey!
Quick, probably easy for you lot, question that I can't figure out. I would I write a quick switch between 1 and 0 in ASM? In a higher level language like C I would write something like: Code:
x = 1 - x |
10 November 2021, 18:34 | #2 |
Lemon. / Core Design
Join Date: Mar 2016
Location: Tier 5
Posts: 1,212
|
bchg #0,d0 ?
although if it doesn't matter if your "1" value is actually -1, you could use "not.w d0" for example |
10 November 2021, 18:43 | #3 |
Registered User
Join Date: Feb 2018
Location: Northumberland, UK
Posts: 272
|
|
10 November 2021, 20:20 | #4 |
Registered User
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
|
I would probably have used eor.b #1,d0
As an aside I tend to have to do this a lot in my stuff, so I always opt to use a frame counter when doing it. Code:
loop: WAIT_FOR_FRAME addq.l #1,FRAME_COUNTER move.l FRAME_COUNTER,d0 and.l #1,d0 beq do_something bra do_something else bra loop I really would look to learn the inner workings of 68k. When I was younger I didn't pay any attention to status flags, I also didn't pay attention to detail on not, neg and particularly the effects of ext. The set instructions are all useful too. Last edited by mcgeezer; 10 November 2021 at 22:47. Reason: thanks jotd for pointing out silly code error |
10 November 2021, 21:41 | #5 |
This cat is no more
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,233
|
status flags are useful to save cycles. Careful with to-memory operations, as they don't set the status flags. Operations to data registers (not address) do set the status flags.
bclr #0,d0 also sets D0 value before bit is cleared. Can be useful at times. In doubt: RTFM note: in C, x ^= 1; (in-place xclusive or) is probably faster that x = 1 - x; but optimizers can detect such patterns and change the expression to the fastest one. @mcgeezer your snippet has issues Code:
addq.l #1,FRAME_COUNTER move.l FRAME_COUNTER,d0 ; no "#" there!!! and.l #1,d0 Code:
move.l FRAME_COUNTER,d0 addq.l #1,d0 move.l D0,FRAME_COUNTER and.b #1,d0 Last edited by jotd; 10 November 2021 at 21:50. |
10 November 2021, 22:57 | #6 | |
Registered User
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
|
Quote:
Indeed, thanks for pointer that error out. You're right about the byte op on "and" too but I guess I used longs for completeness. |
|
11 November 2021, 00:59 | #7 |
Registered User
Join Date: Feb 2018
Location: Northumberland, UK
Posts: 272
|
Yeah, this is exactly the sort of direction I need from you pros. I'm probably so stuck in all of the high-level stuff that I do every day for my job that I tend to forget about all the low-level instructions such as not etc that make everything work.
I usually have a week of 68k coding, and then a week of iOS coding but lately I've just done 4 or 5 weeks of 68k as I'm so into it at the minute that I just want to keep cracking on in my spare time. There's probably TONS of stuff I could optimise in my code, but I guess you learn as you go on. Thanks for all of the help lads, it's very much appreciated. |
11 November 2021, 08:07 | #8 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
|
11 November 2021, 10:34 | #9 |
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
|
|
11 November 2021, 10:39 | #10 |
Registered User
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
|
|
11 November 2021, 10:43 | #11 |
This cat is no more
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,233
|
@meynaf correct. I was wrong. conditions codes aren't set for move to address registers, that's all.
@hooverphonique setting # loads the address, so # must be removed. Adressing mode error (mistaking immediate for direct or reverse) that's a deadly mistake that happens to every one of us |
11 November 2021, 15:50 | #12 | |
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
|
Quote:
|
|
12 November 2021, 15:54 | #13 | |
Lemon. / Core Design
Join Date: Mar 2016
Location: Tier 5
Posts: 1,212
|
Quote:
Yep, quite often you might (want to) do something like this to set a flag if d1 >= 100 Code:
moveq #0,d0 cmp.w #100,d1 blt.s .LessThan moveq #1,d0 .LessThan Code:
cmp.w #100,d1 sge d0 You have all these "set" instructions: SCC set on carry clear SCS set on carry set SEQ set on equal SGE set on greater than or equal SGT set on greater than SHI set on higher than SLE set on less than or equal SLS set on lower than or same SLT set on less than SMI set on minus (i.e., negative) SNE set on not equal SPL set on plus (i.e., positive) SVC set on overflow clear SVS set on overflow set SF set on false (i.e., set never) ST set on true (i.e., set always) But yeah, get yourself a good reference guide for 68000 There's a few online.. this one is fine for most purposes: http://wpage.unina.it/rcanonic/didat...docs/68000.pdf |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Fast switch statement code | Jobbo | Coders. Asm / Hardware | 10 | 22 October 2021 19:13 |
Switch off / revert back VBR Move to fast | alexh | support.AmigaOS | 9 | 05 September 2021 21:21 |
CD32 - Is NTSC/PAL switch and 50/60 switch possible? | missyrelm | Hardware mods | 71 | 13 January 2019 05:21 |
Fast switch Port 1 mouse/ gamepad? | jimmy2x2x | support.WinUAE | 3 | 04 January 2015 09:11 |
Use of 4MB PCMCIA Fast Flash Memory as Fast RAM in A1200 | nkarytia | support.Hardware | 10 | 16 September 2011 13:37 |
|
|