I'm trying to understand the "S[cc]" set of instructions in 68000 assembly.
The format of the instruction is this:
S[cc] reg
[cc]
is a condition code (for example, SEQ
means "set if equals"). If the condition specified by [cc]
is true, the register is set to all 1
s. Otherwise, the register is set to all 0
s.
There's one thing I don't understand: where does the S[cc]
operation look to check if the condition is true? Does it check the flags?
If so, than if I want register D0
to hold the result of the expression D0 = D1
, this is what I need to do:
CMP D0,D1 ; this sets the flags according to the result
SEQ D0 ; sets D0 to true if the flags indicate the condition is true. else, sets it to false.
Is this correct? Or do I not understand this operation correctly?
Yes, it checks the flags, which should become apparent when looking at the mnemonics:
Taken from http://de.scribd.com/doc/418461/Easy-Motorola-68k-Reference page 51. I don't know the first thing about 68k ASM. ;-)
I also want to point out that
s[cc]
only affects least significant byte (e.g. if you dost d0
,d0
will be$xxxxxxFF
,xx
meaning this will be whatever used to be on the register). Furthermore on situations where the condition is true, the byte will be set to$FF
rather than1
. On false situations it will be cleared.S<cc>
does check the condition flags. You might appreciate this simple guide into how you can set the flags to your liking with theCMP
instruction:For example, if you want to check that the unsigned value
src
is more than or equal todest
, useCMP src,dest
thenSCS
. If the values were signed, but you wanted the same test (thatsrc >= dest
), useSLT
You can use the
TST
instruction for comparing a value to zero, although in many cases this is done automatically (e.g.MOVE
will also do a test at the same time)Take a look at Motorola's 68K Programmer's Reference Manual (1992)
Table
3-23
gives you the answer: The condition code checks for the bits in the status register. The status register is set not only by compare operations. See the other mnemonics for details on how they influence the status register.