1.2 struct mnemonic

A mnemonic (real or synthetic instruction) has the following structure:
 
struct mnemonic {
        Mnemonic_Type mnm_type;
        int format;
        union {
                struct register_info *reg;
                struct expression *exp;
        } u[3];
};

mnm_type

This member specifies the type of the mnemonic. Table 1.2.1 shows its values.
format
This member specifies the format of the mnemonic. Table 1.2.2 shows its values. One mnemonic type can take a number of formats. Table 1.2.3 shows the formats associated with each type (those with * are not required in this assignment).
u[3]
This member is an array of three elements representing for, in maximum, three operands in the mnemonic. Each operand can be either a register or an expression. Therefore each element in the array is a union of two pointers, one to a register structure (see section 1.3) and the other to an expression structure (see section 1.4). Which pointer of each element is active depends on the value of format. Table 1.2.2 shows the rule.

Table 1.2.1 Mnemonic Types

Value
Real Instruction
Value
Real Instruction
ADD
add rs1,op2,rd
STB
stb rd,[rs1+op2]
ADDCC
addcc rs1,op2,rd
STH
sth rd,[rs1+op2]
ADDX
addx rs1,op2,rd
ST
st rd,[rs1+op2]
ADDXCC
addxcc rs1,op2,rd
STD
std rd,[rs1+op2]
SUB
sub rs1,op2,rd
SWAP
swap [rs1+op2],rd
SUBCC
subcc rs1,op2,rd
BA
ba label
SUBX
 subx rs1,op2,rd
BN
bn label
 SUBXCC
subxcc rs1,op2,rd
BE
be label
MULSCC
mulscc rs1,op2,rd
BNE
bne label
AND
and rs1,op2,rd
BL
bl label
 ANDCC
andcc rs1,op2,rd
BLE
ble label
 ANDN
andn rs1,op2,rd 
BGE
bge label
ANDNCC 
andncc rs1,op2,rd 
BG
bg label
 OR
or rs1,op2,rd 
BLU
blu label
 ORCC
orcc rs1,op2,rd
BLEU
bleu label
 ORN
orn rs1,op2,rd
BGEU
bgeu label
 ORNCC
orncc rs1,op2,rd
BGU
bgu label
 XOR
xor rs1,op2,rd 
BPOS
bpos label
 XORCC
xorcc rs1,op2,rd 
BNEG
bneg label
XNOR
xnor rs1,op2,rd
BCS
bcs label
XNORCC
xnorcc rs1,op2,rd
BCC
bcc label
 SLL
sll rs1,op2,rd
BVS
bvs label
SRL
srl rs1,op2,rd
BVC
bvc label
 SRA
sra rs1,op2,rd
TA
ta address
LDUB
ldub [rs1+op2],rd
CALL
call label
LDSB
ldsb [rs1+op2],rd
JMPL
jmpl address,rd
LDUH
lduh [rs1+op2],rd
RETT
rett address
LDSH
ldsh [rs1+op2],rd
SETHI
sethi const22,rd 
LD
ld [rs1+op2],rd
SAVE
save rs1,op2,rd 
LDD
ldd [rs1+op2],rd
RESTORE
restore rs1,op2,rd

 
Value
Synthetic Instruction
Value
Synthetic Instruction
CMP
cmp reg,reg_or_imm
TST
tst reg
RET
ret
MOV
mov reg_or_imm,reg
NOP
nop (machine code: 0x10000000)
   
NOT
not reg,reg
not reg
NEG
neg reg,reg
neg reg
INC
inc reg
inc const13,reg
INCCC
inccc re
inccc const13,reg
DEC
dec reg
dec const13,reg
DECCC
deccc reg
deccc const13,reg

Table 1.2.2 Mnemonic Formats

Value
Format
Active Members in Unions
0
reg, reg, reg
u[0].reg
u[1].reg
u[2].reg
1
reg, exp, reg
u[0].reg
u[1].exp
u[2].reg
2
[reg + reg], reg
u[0].reg
u[1].reg
u[2].reg
3
[reg + exp], reg
u[0].reg
u[1].exp
u[2].reg
4
[reg - exp], reg
u[0].reg
u[1].exp
u[2].reg
5
[exp + reg], reg
u[0].exp
u[1].reg
u[2].reg
6
[reg], reg
u[0].reg
u[1].reg
7
[exp], reg
u[0].exp
u[1].reg
8
reg, [reg + reg]
u[0].reg
u[1].reg
u[2].reg
9
reg, [reg + exp]
u[0].reg
u[1].reg
u[2].exp
10
reg, [reg - exp]
u[0].reg
u[1].reg
u[2].exp
11
reg, [exp + reg]
u[0].reg
u[1].exp
u[2].reg
12
reg, [reg]
u[0].reg
u[1].reg
13
reg, [exp]
u[0].reg
u[1].exp
14
reg + reg
u[0].reg
u[1].reg
15
reg + exp
u[0].reg
u[1].exp
16
reg - exp
u[0].reg
u[1].exp
17
exp + reg
u[0].exp
u[1].reg
18
reg
u[0].reg
19
exp
u[0].exp
20
reg + reg,  reg
u[0].reg
u[1].reg
u[2].reg
21
reg + exp,  reg
u[0].reg
u[1].exp
u[2].reg
22
reg - exp,  reg
u[0].reg
u[1].exp
u[2].reg
23
exp + reg,  reg
u[0].exp
u[1].reg
u[2].reg
24
reg, reg
u[0].reg
u[1].reg
25
exp, reg
u[0].exp
u[1].reg
26
reg, exp
u[0].reg
u[1].exp
27
 
 

Table 1.2.3 Mnemonic Type/Format Combinations

Mnemonic Types
Mnemonic Formats
ADD,ADDCC,ADDX,ADDXCC,SUB,SUBCC,SUBX,SUBXCC,MULSCC,
AND,ANDCC,ANDN,ANDNCC,OR,ORCC,ORN,ORNCC,
XOR,XORCC,XNOR,XNORCC,SLL,SRL,SRA,SAVE,RESTORE 
0,1
LDUB,LDSB,LDUH,LDSH,LD,LDD,SWAP
2,3,4,5*,6,7*
STB,STH,ST,STD 
8,9,10,11*,12,13*
TA,RETT
14,15,16,17*,18,19*
BA,BN,BE,BNE,BL,BLE,BGE,BG,BLU,BLEU,BGEU,BGU,
BPOS,BNEG,BCS,BCC,BVS,BVC
19 
exp only has one symbol
CALL
19 
exp only has one symbol
JMPL 
20,21,22,23*,24,25*
SETHI
25
CMP
24,26
TST
18
RET, NOP
27
NOT,NEG
18,24
INC,INCCC,DEC,DECCC
18,25
MOV
24,25

table of content