Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Laboratory Work No 05 Syntax of Assembly Objectives: In this experiment you will learn: 1. Format of instructions and macroinstructions. 2. Syntax of operands in Assembly. 3. Syntax of operators in Assembly. Pre Lab Work Part I 1. Review the material related to Syntax of Assembly (assLect5): . Basic Elements of Assembly Language Microsoft syntax notation o Elements within square brackets [ ] are optional o Elements within { …| …|…} requires a choice of the enclosed elements o Elements in italics denote items which have known definitions or descriptions o Example: [{+ | -}] digits [radix] Integer constants (integer literal) o Syntax: [{+ | -}] digits [radix] o Optional leading + or – sign o binary, decimal, hexadecimal, or octal digits o Common radix characters: h – hexadecimal d – decimal b – binary r – encoded real o Examples: 30d, 6Ah, 42, 1101b o Hexadecimal beginning with letter must have leading 0: 0A5h o If no radix is given, the integer constant is assumed to be decimal Integer expressions o A mathematical expression involving integer value and arithmetic operators o Operators and precedence levels: o Examples: 12 – 1 MOD 5, -3 + 4 *6 - 1 Real Number Constants o Syntax: [sign] integer.[integer][exponent] sign {+ | -} exponent E[{+ | -}]integer o Examples: 2., +3.0, -44.26E+05, 26.E-5 o Note: At the very least, there must be a digital or a decimal point Character and String Constants o Enclose character in single or double quotes 'A', "x" ASCII character = 1 byte o Enclose strings in single or double quotes "ABC" 'xyz' Each character occupies a single byte o Embedded quotes: 'Say "Goodnight," Gracie' Reserved Words and Identifiers o Reserved words cannot be used as identifiers Instruction mnemonics, directives, type attributes, operators, predefined symbols See MASM reference in Appendix A o Identifiers – a programmer-choice name 1-247 characters, including digits not case sensitive first character must be a letter, _, @, ?, or $ Directives o Commands that are recognized and acted upon by the assembler Not part of the Intel instruction set Used to declare code, data areas, select memory model, declare procedures, etc. not case sensitive o Different assemblers have different directives NASM not the same as MASM See MASM reference in Appendix D Instructions o Assembled into machine code by assembler o Executed at runtime by the CPU o We use the Intel IA-32 instruction set o An instruction contains: Labels (optional) Act as place markers marks the address (offset) of code and data Follow identifier rules Data label - must be unique - example: myArray (not followed by colon) Code label - target of jump and loop instructions - example: L1: (followed by colon) Mnemonics (required) Instruction Mnemonics memory aid examples: MOV, ADD, SUB, MUL, INC, DEC Operands (depends on the instruction) constant constant expression register memory (data label) Constants and constant expressions are often called immediate values Comments (optional) Comments are good! - explain the program's purpose - when it was written, and by whom - revision information - tricky coding techniques - application-specific explanations Single-line comments - begin with semicolon (;) Multi-line comments - begin with COMMENT directive and a programmer-chosen character - end with the same programmer-chosen character - Example: COMMENT & This is a comment. This line is also a comment. & This line is also a comment. o Instruction Format Examples No operands stc ; set Carry flag One operand inc eax ; register inc myByte ; memory Two operands add ebx,ecx ; register, register sub myByte,25 ; memory, constant add eax,36 * 25 ; register, constant-expression Lab Work Part I 1.UseTASM for analyzing elements of Assembly syntax: For example for MOV Instruction It copies the second operand (source) to the first operand (destination). The source operand can be an immediate value, general-purpose register or memory location. The destination register can be a general-purpose register, or memory location. Both operands must be the same size, which can be a byte or a word. These types of operands are supported: MOV REG, memory MOV memory, REG MOV REG, REG MOV memory, immediate MOV REG, immediate For segment registers only these types of MOV are supported: MOV SREG, memory MOV memory, SREG MOV REG, SREG MOV SREG, REG NOTE: The MOV instruction cannot be used to set the value of the CS and IP registers. Here is a short program that demonstrates the use of MOV instruction: MOV AX, 0B800h ; set AX to hexadecimal value of B800h. MOV DS, AX ; copy value of AX to DS. MOV CL, 'A' ; set CL to ASCII code of 'A', it is 41h. MOV CH, 1101_1111b ; set CH to binary value. MOV BX, 15Eh ; set BX to 15Eh. MOV [BX], CX ; copy contents of CX to memory at B800:015E Instruction RET ; returns to operating system. 2.UseTASM for analyzing elements of Assembly operators syntax: Arithmetic operators, Shift operators, Index operator [ ] , Operator of segment redeclaration ’:’ (colon), Operator of obtaining offset of expression offset, Operator of redeclaration (redefinition) of the ptr. Make comment for sentences with these operands and operators.