Browse Definitions :

primitive (programming)

What is a primitive in computer programming?

In computer programming, a primitive is one of a set of fundamental language elements that serve as the foundation for a programming language. Each language supports a core set of primitives that provide the basic building blocks for instructing a processor on how to carry out specific operations. Primitives vary between languages and platforms based on factors such as processor architecture, programming language, and the programmatic level (e.g., machine code versus a high-level language such as Java).

How are primitives used in programming?

Computer processors do not understand source code, whether an assembly language or high-level programming language. They can only understand machine language (binary code consisting of 0s and 1s), and the machine code must conform to the processor's instruction set architecture (ISA), which is part of the processor's microarchitecture. The ISA defines the primitives that are supported by the processor, as well as how to build instructions for that processor. In effect, the primitives indicate what the processor is capable of doing, such as adding data or loading it into a specific location in memory.

Each primitive is associated with a specific operation code (opcode). An opcode is the binary equivalent of the primitive that tells the processor what operation to carry out. The opcode is typically accompanied by operands, which represent the data to be manipulated by the primitive. Operands are defined as part of an instruction in which primitives serve as the operator. As with ISAs, opcodes are specific to the processor architecture. For example, an add primitive might translate to an operand such as 0011, 0100, 0110 or another set of bits, depending on the underlying architecture.

Primitives also have their counterparts in assembly languages, which are also specific to the processor architecture. An assembly language is a type of source code that, like high-level programming languages, is written in plain text and is human readable.

Assembly languages and primitives

An assembly language uses mnemonics to represent an ISA's primitives. Mnemonics are short descriptive words that serve as a foundation for building instructions for the processor. In the x86 assembly language, for example, the term add is a mnemonic that means add, while sub means subtract and inc means increase by one. An assembler translates the mnemonic-based instructions to machine code, according to the ISA's specifications.

Microcode and primitives

Some processors use microcode to carry out their operations. Microcode is integrated into the microarchitecture and is considered an even lower-level language than machine code. As such, it might break down primitive operations defined in the machine code into smaller instructions. Some sources consider these smaller instructions to be microcode primitives. However, there is no real consensus as to whether these operations qualify as their own types of primitives. As with many aspects of technology, the term primitive is sometimes used in different ways to describe similar or dissimilar concepts.

High-level programming languages and primitives

High-level programming languages are sometimes discussed in terms of having their own primitives. In this case, primitives represent the smallest units of programming logic available to a specific language. The term primitive in this context is usually discussed in relationship to data types. For example, the Java data types int, char and Boolean are all considered primitive types. Other Java types are built on the primitive types.

Table showing Java's primitive types
Table highlighting Java's primitive types in order of descending upper range limit.

The term primitive might also be used in other ways in a high-level programming language. For example, it might refer to operators, expressions, procedures or other language elements. Regardless of how it's used, a primitive in a high-level language does not necessarily have a direct counterpart in machine language. For example, adding two numbers in a high-level language might represent a single primitive operation in that language, but when translated to machine code, that operation will likely require multiple lower-level primitive operations.

The term primitive is also used in computer graphics to refer to an image element -- such as an arc, a square or a cone -- from which more complicated images can be constructed.

Learn about in-demand programming languages developers should get to know.

This was last updated in April 2023

Continue Reading About primitive (programming)

  • Telnet

    Telnet is a network protocol used to virtually access a computer and provide a two-way, collaborative and text-based ...

  • big-endian and little-endian

    The term endianness describes the order in which computer memory stores a sequence of bytes.

  • Address Resolution Protocol (ARP)

    Address Resolution Protocol (ARP) is a protocol that maps dynamic IP addresses to permanent physical machine addresses in a local...

  • Mitre ATT&CK framework

    The Mitre ATT&CK (pronounced miter attack) framework is a free, globally accessible knowledge base that describes the latest ...

  • timing attack

    A timing attack is a type of side-channel attack that exploits the amount of time a computer process runs to gain knowledge about...

  • privileged identity management (PIM)

    Privileged identity management (PIM) is the monitoring and protection of superuser accounts that hold expanded access to an ...

  • employee resource group (ERG)

    An employee resource group is a workplace club or more formally realized affinity group organized around a shared interest or ...

  • employee training and development

    Employee training and development is a set of activities and programs designed to enhance the knowledge, skills and abilities of ...

  • employee sentiment analysis

    Employee sentiment analysis is the use of natural language processing and other AI techniques to automatically analyze employee ...

Customer Experience
  • customer profiling

    Customer profiling is the detailed and systematic process of constructing a clear portrait of a company's ideal customer by ...

  • customer insight (consumer insight)

    Customer insight, also known as consumer insight, is the understanding and interpretation of customer data, behaviors and ...

  • buyer persona

    A buyer persona is a composite representation of a specific type of customer in a market segment.