Ассемблер хэл: Засвар хоорондын ялгаа

Content deleted Content added
Хуудас үүсгэв: "thumb|Motorola MC6800-ийн Ассемблер хэл Ассемблер хэл нь компьютер, Микр..."
 
Мөр 25:
* [[Объект хандлагат програмчлал]]ын чанарууд: [[класс]], [[объект]], [[хийсвэрлэл]], [[олон хэлбэршил]], [[удамшил]]
 
===AssemblyАссемблер languageхэл===
Ассемблер хэлээр бичигдсэн програм нь цуварсан хийсвэр командууд, тайлбар, өгөгдлөөс тогтоно.
A program written in assembly language consists of a series of (mnemonic) processor instructions and meta-statements (known variously as directives, pseudo-instructions and pseudo-ops), comments and data. Assembly language instructions usually consist of an opcode mnemonic followed by a list of data, arguments or parameters.<ref name="intel-1999">{{cite book|title=Intel Architecture Software Developer’s Manual, Volume 2: Instruction Set Reference|year=1999|publisher=INTEL CORPORATION |url=http://download.intel.com/design/PentiumII/manuals/24319102.PDF|accessdate=18 November 2010}}</ref> These are translated by an [[assembly language#Assembler|assembler]] into [[machine language]] instructions that can be loaded into memory and executed.
 
Жишээ нь: доорх команд [[x86/IA-32]] процессорт 8 битийн шууд утгыг [[регистр]]т хадгалах үйлдэл хийж байна. Энэхүү командын машин код дахь 10110-н дараах 3 бит нь регистрийг заадаг буюу 000 нь AL регистрийг илэрхийлж байна. Тиймээс дараах [[машин код]] нь AL регистрт нь 01100001 гэсэн өгөгдлийг хадгалах команд байна.
For example, the instruction below tells an [[x86]]/[[IA-32]] processor to move an [[Constant (programming)|immediate 8-bit value]] into a [[processor register|register]]. The binary code for this instruction is 10110 followed by a 3-bit identifier for which register to use. The identifier for the ''AL'' register is 000, so the following [[machine code]] loads the ''AL'' register with the data 01100001.<ref name="intel-1999-MOV">{{cite book|title=Intel Architecture Software Developer’s Manual, Volume 2: Instruction Set Reference|year=1999|publisher=INTEL CORPORATION |pages=442 and 35|url=http://download.intel.com/design/PentiumII/manuals/24319102.PDF|accessdate=18 November 2010}}</ref>
10110000 01100001
Энэ машин кодыг хүнд арай уншигдам болгохын тулд бид [[16-тын тооллын систем]] дээр дүрсэлдэг.
This binary computer code can be made more human-readable by expressing it in [[hexadecimal]] as follows
B0 61
Дээрх код нь [[2-тын тооллын систем|2-тын]] 01100001 буюу 16-тын 61 буюу [[10-тын тооллын систем|10-тын]] 94 гэсэн тоог AL регистрт хуул гэсэн утгатай болно. Intel-ийн ассемблер хэлд хуулах үйлдлийг MOV гэсэн мнемоник хэрэглэдэг бөгөөд дээр кодыг зохих ассемблер хэл уруу хөрвүүлье. Одоо илүү хялбар ойлгогдож, цээжлэгддэг болсон байна.
Here, <code>B0</code> means 'Move a copy of the following value into ''AL''', and <code>61</code> is a hexadecimal representation of the value 01100001, which is 97 in [[decimal]]. Intel assembly language provides the [[mnemonic]] [[MOV (x86 instruction)|MOV]] (an abbreviation of ''move'') for instructions such as this, so the machine code above can be written as follows in assembly language, complete with an explanatory comment if required, after the semicolon. This is much easier to read and to remember.
<source lang="asm">MOV AL, 61h ; Load AL with 97 decimal (61 hex)</source>
Зарим ассемблер хэлд ганц мнемоник тухайлбал MOV хадгалах, өгөгдөл хуулах, шууд утга хуулах, регистрт утга хуулах, санах ойгоод регистрт өгөгдөл хуулах гэх мэт олон үйлдлийг хийдэг мнемоник байдаг. Харин бусад ассемблер хэлд ялгаатай опкодыг хэрэглэдэг. Жишээ нь L - "санах ойгоос регистрт өгөгдөл хуулах", ST - "регистрийн өгөгдлийг санах ой уруу хуулах", LR - "Нэг регистрийн утгыг өөр регистр уруу хуулах", MVI - "санах ой уруу шууд утга хуулах", гэх мэт.
In some assembly languages the same mnemonic such as MOV may be used for a family of related instructions for loading, copying and moving data, whether these are immediate values, values in registers, or memory locations pointed to by values in registers. Other assemblers may use separate opcodes such as L for "move memory to register", ST for "move register to memory", LR for "move register to register", MVI for "move immediate operand to memory", etc.
 
The Intel opcode 10110000 (<code>B0</code>) copies an 8-bit value into the ''AL'' register, while 10110001 (<code>B1</code>) moves it into ''CL'' and 10110010 (<code>B2</code>) does so into ''DL''. Assembly language examples for these follow.<ref name="intel-1999-MOV"/>
<source lang="asm">
MOV AL, 1h ; Load AL with immediate value 1
MOV CL, 2h ; Load CL with immediate value 2
MOV DL, 3h ; Load DL with immediate value 3
</source>
The syntax of MOV can also be more complex as the following examples show.<ref>{{cite web|last=Evans|first=David|title=x86 Assembly Guide|url=http://www.cs.virginia.edu/~evans/cs216/guides/x86.html|publisher=University of Virginia|accessdate=18 November 2010|year=2006}}</ref>
<source lang="asm">
MOV AL, 1h ; Load AL withуруу immediate1-г value 1хуулах
MOV EAX, [EBX] ; Move the 4 bytes in memory at the address contained in EBX into EAX
MOV [ESI+EAX]CL, CL2h ; Move the contents of CL into the; byteCL atуруу address2-г ESI+EAXхуулах
MOV DL, 3h ; Load DL withуруу immediate3-г value 3хуулах
MOV EAX, [EBX] ; Санах ойн EBX дэх хаягаас 4 байтыг EAX уруу хуулах
MOV [ESI+EAX], CL ; CL-н өгөгдлийг ESI+EAX хаяг дахь 1 байтад хуулах
</source>
Тохиолдол бүрд MOV ялгаатай опкод уруу хөрвөгдөнө.
In each case, the MOV mnemonic is translated directly into an opcode in the ranges 88-8E, A0-A3, B0-B8, C6 or C7 by an assembler, and the programmer does not have to know or remember which.<ref name="intel-1999-MOV"/>
 
Transforming assembly language into machine code is the job of an assembler, and the reverse can at least partially be achieved by a [[disassembler]]. Unlike [[high-level language]]s, there is usually a [[one-to-one correspondence]] between simple assembly statements and machine language instructions. However, in some cases, an assembler may provide ''pseudoinstructions'' (essentially macros) which expand into several machine language instructions to provide commonly needed functionality. For example, for a machine that lacks a "branch if greater or equal" instruction, an assembler may provide a pseudoinstruction that expands to the machine's "set if less than" and "branch if zero (on the result of the set instruction)". Most full-featured assemblers also provide a rich [[macro (computer science)|macro]] language (discussed below) which is used by vendors and programmers to generate more complex code and data sequences.