Assembler basic question : translation to machine code
Actually it the 'conversion' between the user-typed text file and the actual (binary) assembly/executable code is done by a special program, called an assembler.

It is a text parser, that parses all text in pieces (e.g. first 'MOV', than its operands/arguments. One by one it is translated (and items may be stored if needed).

Parses are based on rules, so e.g. if 'M', 'O', 'V' is found in a text file, it knows it has to be translated to e.g. opcode 0x40. And also it knows what to expect afterwards (arguments). If these are correct those arguments will be translated, otherwise an error message will be shown.

Also optimization is done within the assembler, and other settings affecting the binary code.

Update (according comment):

Steps:


The user creates with a text editor the assembly code in text form (e.g. with commands as text like MOV 1, A, SUB ...
This is saved to disk to a file, e.g. program.a
The user runs an assembler program
This program reads file program.a to memory.
It translates word by word and operand by operand the text using a parser. The text is translated into opcodes and operands.
Mostly there is an optimization step that removes unnecessary opcodes or changes them into better/faster ones.
These opcodes and operands are stored in another file, e.g. program.exe (the executable). 
When running the program, the program.exe file is read into memory.
The computer/microcontroller executes the code in memory.