The primary function of an assembler in computer science is to translate assembly language, a low-level programming language, into machine language that can be directly executed by the computer's hardware. It essentially converts human-readable code into computer-readable instructions.