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 |
bchg #0,d0 ?
although if it doesn't matter if your "1" value is actually -1, you could use "not.w d0" for example |
Quote:
|
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: 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. |
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 Code:
move.l FRAME_COUNTER,d0 |
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. |
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. |
Quote:
|
Quote:
|
Quote:
|
@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 :) |
Quote:
Quote:
|
Quote:
Quote:
Yep, quite often you might (want to) do something like this to set a flag if d1 >= 100 Code:
moveq #0,d0 Code:
cmp.w #100,d1 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 |
All times are GMT +2. The time now is 17:36. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.