Lankide:Markel Galarraga/Proba orria

Wikipedia, Entziklopedia askea

For code that is completely internal to some CPUs and normally inaccessible to programmers, see microcode.

Machine code is a computer program written in machine language instructions that can be executed directly by a computer's central processing unit (CPU). Each instruction causes the CPU to perform a very specific task, such as a load, a jump, or an ALU operation on a unit of data in a CPU register or memory.

Machine code is a strictly numerical language which is intended to run as fast as possible, and may be regarded as the lowest-level representation of a compiled or assembled computer program or as a primitive and hardware-dependent programming language. While it is possible to write programs directly in machine code, it is tedious and error prone to manage individual bits and calculate numerical addresses and constants manually. For this reason, programs are very rarely written directly in machine code in modern contexts, but may be done for low level debugging, program patching, and assembly language disassembly.

The overwhelming majority of practical programs today are written in higher-level languages or assembly language. The source code is then translated to executable machine code by utilities such as compilers, assemblers, and linkers, with the important exception of interpreted programs,[1] which are not translated into machine code. However, the interpreter itself, which may be seen as an executor or processor, performing the instructions of the source code, typically consists of directly executable machine code (generated from assembly or high-level language source code).

Machine code is by definition the lowest level of programming detail visible to the programmer, but internally many processors use microcode or optimise and transform machine code instructions into sequences of micro-ops, this is not generally considered to be a machine code per se.

Every processor or processor family has its own instruction set. Instructions are patterns of bits that by physical design correspond to different commands to the machine. Thus, the instruction set is specific to a class of processors using (mostly) the same architecture. Successor or derivative processor designs often include all the instructions of a predecessor and may add additional instructions. Occasionally, a successor design will discontinue or alter the meaning of some instruction code (typically because it is needed for new purposes), affecting code compatibility to some extent; even nearly completely compatible processors may show slightly different behavior for some instructions, but this is rarely a problem. Systems may also differ in other details, such as memory arrangement, operating systems, or peripheral devices. Because a program normally relies on such factors, different systems will typically not run the same machine code, even when the same type of processor is used.

A processor's instruction set may have all instructions of the same length, or it may have variable-length instructions. How the patterns are organized varies strongly with the particular architecture and often also with the type of instruction. Most instructions have one or more opcode fields which specifies the basic instruction type (such as arithmetic, logical, jump, etc.) and the actual operation (such as add or compare) and other fields that may give the type of the operand(s), the addressing mode(s), the addressing offset(s) or index, or the actual value itself (such constant operands contained in an instruction are called immediates).[2]

CPUentzat guztiz internoa eta programatzaileentzat iragangaitza den kodearentzat, ikusi mikrokode.

Makina-lengoaia, makina-kodea idazteko erabiltzen den lengoaia da. Makina-kodea konputagailu-programa bat da, zuzenean prozesatzeko unitate zentralean (PUZean) exekutatu daitekena. Agindu bakoitzarekin PUZak eragiketa jakin bat exekutatuko du; adibidez, load bat, jauzi bat, edo unitate aritmetiko-logikoaren eragiketa bat, erregisto edo memoriako informazio-unitate batean.

Makina-kodea guztiz zenbakizkoa da, ahal den azkarren exekutatu dadin prestatua; eta ondorengoen maila baxueneko irudikapen gisa ikus daiteke: konpilatu edo mihiztatutako konputagailu-programa, edo primitiboa eta hardware-mendekoa den programazio lengoaia. Konputagailu-programak zuzenean idatzi daitezke makina-lengoaian, baina lan unagarria da, eta erraza da erroreak gauzatzea bit bakoitza eta memoria helbideen kalkulua eskuz kontrolatu behar direnean. Horregatik, orokorrean, programak ez dira zuzenean makina-lengoaian idazten, baina lengoaia hau bai erabili daitekeela behe-mailako arazketan, programen adabakiketan, eta mihiztadura-lengoaiaren desmuntaian. Gaur egun, goi-mailako lengoia edo mihiztadura-lengoaian idazten dira konputagailu-programak. Ondoren, iturburu kodea exekutagarria den makina-kodera eraldatzen da; konpiladore, mihiztatzaile edo estekatzaile baten laguntzaz; programa interpretatuak salbu[1], ez baitira makina-kodera eraldatzen. Hala eta guztiz ere, iturburu kodeko aginduak banan-bana gauzatzen dituen interpretatzailea bera, exekutatzaile bezala ikus daitekeena, zuzenean exekutagarria den makina-kodea da orokorrean (goi-mailako edo mihiztadura-lengoaian idatzitako iturburu kode batetik sortua).


Makina-kodea, definizioz, programatzailearentzat ikusgarria den maila baxueneko programazio xehetasuna da, baina, barnean, prozesu askok mikrokodea erabiltzen dute, edo makina-kodea mikro-operazio segidetara eraldatu. Teknika hauek erabiltzen badira, sortutako kodea ez da makina-kodetzat jotzen.

Agindu-multzoa[aldatu | aldatu iturburu kodea]

Mikroprozesadore edo mikroprozesadore-familia bakoitzak bere agindu-multzoa dauka. Aginduak bit segidak dira, diseinu fisikoari esker makinako komando jakin batekin kointziditzen dutenak. Agindu-multzoa, beraz, berariazkoa da, normalean, arkitektura bereko mikroprozesadore-klase bakoitzarentzat. Oinordeko mikroprozesadore edo prozesadore-eratorrien diseinuak, orokorrean, arbasoren baten agindu guztiak bereganatzen dituzte, batzuetan agindu berriak gehitzeaz gain. Noizean behin, oinordeko diseinu batek jatorrizko aginduren bat ezabatuko du, edo horren esanahia aldatu (helburu berri baterako behar delako), kodearen bateragarritasuna deuseztatuz. Batzuetan, ia guztiz bateragarriak diren prozesagailuek jatorrizko agindu batzuekiko portaera zertxobait desberdina daukate, baina orokorrean hori ez da arazo bat. Sistemak beste xehetasunetan ere desberdintasunak eduki ditzakete: memoriaren antolaketan, sistema eragilean, edo periferikoetan, besteak beste. Konputagailu-programak faktore horien menpe daudenez, sistema desberdinetan exekutatzen den makina-kodea desberdina izango da, nahiz eta mota bereko mikroprozesagailua erabili. Mikroprozesagailu baten agindu-multozoko agindu guztiak luzera berekoak izan daitezke, edo luzera-aldakorrekoak. Segiden antolaketa oso desberdina da arkitektura jakin bakoitzarentzat, eta baita agindu motarentzat ere. Agindu gehienek atal bat edo gehiago dituzte, mota (aritmetikoa, logikoa, jauzia, etab.) eta aginduaren eragiketa bera (gehiketa edo konparaketa, adibidez) adierazteko. Gainera, beste zati batzuei esker informazio gehiago adierazten da: eragingaien mota, helbideratze modua, helbidetatze orekaketa edo indexazioa, eta eragingaiaren balioa bera (agindu batean horrelako eragingaiak aurkitzen direnean berehalakoak deitzen dira)[2].

Kanpo loturak[aldatu | aldatu iturburu kodea]

  1. BASIC-en bertsio asko bezala, goiztiarrak batez ere; Smalltalk, MATLAB, Perl, Python, Ruby eta beste helburu bereziko script lengoaietaz gain.
  2. (Ingelesez) org, Bradley Kjell; kjell at ieee dot. «Immediate Operand» programmedlessons.org (Noiz kontsultatua: 2018-09-27).