问题
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?
回答1:
Yes, it checks the flags, which should become apparent when looking at the mnemonics:
SCC set on carry clear (!C)
SCS set on carry set (C)
SEQ set on equal (Z)
SGE set on greater than or equal (N.V + !N.!V)
SGT set on greater than (N.V.!Z + !N.!V.!Z)
SHI set on higher than (!C.!Z)
SLE set on less than or equal (Z + N.!V + !N.V)
SLS set on lower than or same (C + Z)
SLT set on less than (N.!V + !N.V)
SMI set on minus (i.e., negative) (N)
SNE set on not equal (!Z)
SPL set on plus (i.e., positive) (!N)
SVC set on overflow clear (!V)
SVS set on overflow set (V)
SF set on false (i.e., set never) (0)
ST set on true (i.e., set always) (1)
Taken from http://de.scribd.com/doc/418461/Easy-Motorola-68k-Reference page 51. I don't know the first thing about 68k ASM. ;-)
回答2:
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.
回答3:
S<cc>
does check the condition flags. You might appreciate this simple guide into how you can set the flags to your liking with the CMP
instruction:
CMP src, dest
dest < src LT CS src >= dest ; CS = LO
dest <= src LE LS src >= dest
dest == src EQ EQ src == dest
dest != src NE NE src != dest
dest > src GT HI src <= dest
dest >= src GE CC src <= dest ; CC = HE
signed ---^ ^--- unsigned
For example, if you want to check that the unsigned value src
is more than or equal to dest
, use CMP src,dest
then SCS
. If the values were signed, but you wanted the same test (that src >= dest
), use SLT
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)
TST dest
dest == 0 EQ
dest != 0 NE
dest < 0 MI
dest >= 0 PL
回答4:
I also want to point out that s[cc]
only affects least significant byte (e.g. if you do st 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 than 1
. On false situations it will be cleared.
来源:https://stackoverflow.com/questions/25035030/understanding-the-scc-instructions-of-68000-assembly