Instruction parsing identifies a mnemonic and checks the shape of its operands before encoding. ivss describes accepted forms in an instruction table. Its entry for add is:
{ "add", I_ADD, ALU_ADD, 2, I_ARGS_REG_REG },
The fields select the instruction kind, arithmetic operation, expected argument count, and operand format. For the source statement:
add %r2, %r1
The parser splits the arguments at the comma and interprets them as source and destination registers. The destination is also an input to the addition, so the statement means %r1 = %r1 + %r2.
The outer line parser separates an optional label from a directive or instruction. Operand-specific functions then distinguish registers, literals, symbols, and memory forms. For example, the ld entry accepts a data operand followed by a register, rather than the two-register form required here.
Parsing establishes which operation was requested. Encoding turns that operation into bytes, and expansion may produce several machine instructions for one accepted statement.
Source: asembler.c.