Opcode: Difference between revisions

Content deleted Content added
Pearle (talk | contribs)
m Changing {{cleanup}} to {{cleanup-date|June 2005}}
Morven (talk | contribs)
Wholly rewritten. I felt the example was incomprehensible to anyone needing the help, so I removed it. Perhaps a better one can be created?
Line 1:
{{cleanup-date|June 2005}}
 
In [[computer science]], an '''Opcode''' is the portion of a [[machine language]] [[instruction]] that specifies the operation to be performed. The term is an abbreviation of '''Op'''eration '''Code'''. Their specification and format will be laid out in the [[instruction set architecture]] (ISA) of the [[computer hardware]] component in question—normally a [[central processing unit|CPU]], but possibly a more specialised unit. A complete machine language instruction contains an opcode and, optionally, the specification of one or more [[operand]]s—what data the operation should act upon. Some operations have ''implicit'' operands, or indeed none. Some ISAs have instructions with defined fields for opcodes and operands, while others (e.g. the [[Intel x86]] architecture) have a more complicated and ad-hoc structure.
Opcode stands for '''Op'''eration '''Code'''. Opcodes operate on [[processor register|registers]], values in [[memory]], values stored on the [[Stack (computing)|stack]], [[I/O]] ports, the [[Computer bus|bus]], etc. They are used to perform arithmetic operations and move and change values. [[Operands]] are the things that opcodes operate on. [[Microprocessors]] perform operations using binary [[bit|bits]]. A [[bit]] is either on (1) or off (0). Eight [[bit|bits]] is equal to a [[byte]] (on most modern processors), and two bytes is equal to a word.
 
The operands upon which opcodes operate on may, depending on CPU architecture, consist of [[processor register|registers]], values in [[memory]], values stored on the [[Stack (computing)|stack]], [[I/O]] ports, the [[Computer bus|bus]], etc. The operations an opcode may specify can include arithmetic, data copying, logical operations, and program control.
Another term for opcodes is [[Byte code]]. Byte code is used especially to describe higher level constructs as is the case with the [[Java programming language|Java Language]]'s JVM ([[Java Virtual Machine]]). For instance, byte code 1A might be the "iconst_2" instruction which pushes the number 2 on the stack. This is a slightly higher level of abstraction than opcodes, which might need to load the number 2 into a register, and then push the register's value on the stack.
 
Opcodes can also be found in [[byte code]]s interpreted by a byte code interpreter (or [[virtual machine]], in one sense of that term). In these, an instruction set architecture is created to be interpreted by software, rather than a hardware device. Often, byte code interpreters work with higher-level data types and operations than a hardware instruction set, but are constructed along similar lines. Examples include the [[Java programming language]]'s [[Java Virtual Machine]] (JVM), the byte code used in [[GNU Emacs]] for compiled [[LISP]] code, and many others.
As an example let's design a crude 4-bit [[microprocessor]].
*First: All registers, ALUs, counters, and addresses must have a data path of 4-bits.
*Second: All of our instructions must fit in a 3-bit address.
Below is a diagram of the opcodes of the micorprocessor:
op-codes mnemonic operations explanation
000 ADD add A to B and store in b
001 mov move A to B and store in b
010 Jmp jump value in A
011 xorA xor A with next op-code store in b
100 clrA clear A
101 return return to pointer
110 counter counter value
111 end end program
 
Machine language is tedious and difficult for humans to program in directly, so if the abstraction given by a higher-level [[programming language]] is not desired, an [[assembly language]] is used. Here, [[mnemonic]] instructions are used that correspond to the opcode and operand specifications of the machine language instructions generated. This gives a greater level of readability and comprehensibility than working with machine language operations directly, while still giving accurate control of the machine language generated. A program called an [[assembler]] transforms assembly language into machine code.
When the op-code values are active at the decoders logic inputs,
the desired operations are performed. <!-- This is a better explanation then whats below..cleanUpLater.. -->
Each of these operations is assigned a numeric code, this is the '''opcode'''. To assist in the use of these numeric codes, [[mnemonic]]s are used as textual abbreviations. It's much easier to remember ADD than 05, for example.
 
==See also==
* [[Machine language]]
 
[[Category:Computing]]