Download Instructions, Directives and Macros-Assembly Language-Lecture Handout and more Exercises Assembly Language Programming in PDF only on Docsity! Source code file has statements of assembly language. There are three types of functional assembly language statements: 1. Instructions 2. Directives 3. Macros. An instruction is translated by the assembler into one or more bytes of object code (machine code), which will be executed at run time. Each instruction corresponds to one of the operations that can be executed by the 80×86 CPU. The instruction add eax, 158 A directive tells the assembler to take some action. Such an action does not result in machine instructions and often has no effect on the object code. A macro is "shorthand" for a sequence of other statements, be they instructions, directives, or even other macros. The assembler expands a macro to the statements it represents and then assembles these new statements. A statement that is more than just a comment almost always contains a mnemonic that identifies the purpose of the statement, and may have three other fields: name, operand, and comment. These components must be in the following order: name mnemonic operand(s) ;comment For example, a program might contain the statement ZeroCount: mov ecx, 0 ; initialize count to zero The name field always ends with a colon (:) when used with an instruction. When used with a directive, the name field has no colon. The mnemonic in a statement indicates a specific instruction, directive, or macro. Some statements have no operand, others have one, others have more. If there is more than one operand, they are separated by commas; spaces can also be added. Sometimes a single operand has several components with spaces between them, making it look like more than one operand. In the instruction add eax, 158 the mnemonic is add and the operands are eax and 158. The assembler recognizes add as a mnemonic for an instruction that will perform some sort of addition. The operands docsity.com provide the rest of the information that the assembler needs. The first operand eax tells the assembler that the doubleword in the EAX register is to be one of the values added, and that the EAX register will be the destination of the sum. Since the second operand is a number (as opposed to another register designation or a memory designation), the assembler knows that it is the actual value to be added to the doubleword in the EAX register. The resulting object code is 05 00 00 00 9E, where 05 stands for "add the doubleword immediately following this byte in memory to the doubleword already in EAX." The assembler takes care of converting the decimal number 158 to its doubleword length 2's complement representation 0000009E. Comments: Start with ; Basic Instructions: Copying Data: With 80×86 machine language, this copying job is done by mov (move) instructions. Each mov instruction has the form mov destination, source and copies a byte, word, or doubleword value from the source operand location to the destination operand location. The value stored at the source location is not changed. The destination location must be the same size as the source. No mov instruction changes any flag. Exercise: Allocate two DWORD named number1, number2. Give them suitable values. Add them and move the result to another register. Use debugger to view the effect on registers. Jump Instructions: Unconditional Jumps As coded in assembly language, jmp usually has the form jmp StatementLabel where StatementLabel corresponds to the name field of some other assembly language statement. docsity.com