Part II: Assembly Fundamentals
-
Upload
ahmed-m-abed -
Category
Technology
-
view
156 -
download
0
description
Transcript of Part II: Assembly Fundamentals
![Page 1: Part II: Assembly Fundamentals](https://reader034.fdocuments.net/reader034/viewer/2022051411/547557a4b4af9fbe0a8b5b5e/html5/thumbnails/1.jpg)
ASSEMBLY FUNDAMENTALSAHMED M. ABED
TEACHING ASSISTANT – ISLAMIC UNIVERSITY OF GAZA
![Page 2: Part II: Assembly Fundamentals](https://reader034.fdocuments.net/reader034/viewer/2022051411/547557a4b4af9fbe0a8b5b5e/html5/thumbnails/2.jpg)
AGENDA
• Fast Review
• Basic Elements of Assembly
![Page 3: Part II: Assembly Fundamentals](https://reader034.fdocuments.net/reader034/viewer/2022051411/547557a4b4af9fbe0a8b5b5e/html5/thumbnails/3.jpg)
INTRODUCTION
![Page 4: Part II: Assembly Fundamentals](https://reader034.fdocuments.net/reader034/viewer/2022051411/547557a4b4af9fbe0a8b5b5e/html5/thumbnails/4.jpg)
BASIC ELEMENTS OF ASSEMBLY
• Integer Constants
• Integer Expression
• Real Number Constants
• Character Constants
• String Constants
• Reserved Words
• Identifiers
• Directives
• Instructions
![Page 5: Part II: Assembly Fundamentals](https://reader034.fdocuments.net/reader034/viewer/2022051411/547557a4b4af9fbe0a8b5b5e/html5/thumbnails/5.jpg)
INTEGER CONSTANTS
• one or more digits, and an optional suffix character (called a radix) indicating the number’s base
[{+| −}] digits [radix]
• If no radix is given, the integer constant is assumed to be decimal
![Page 6: Part II: Assembly Fundamentals](https://reader034.fdocuments.net/reader034/viewer/2022051411/547557a4b4af9fbe0a8b5b5e/html5/thumbnails/6.jpg)
RADIX
• Radix may be one of the following (uppercase or lowercase):
Radix Type Radix Type
H Hexadecimal R Real
q/o Octal T Decimal
D Decimal Y Binary
B Binary
![Page 7: Part II: Assembly Fundamentals](https://reader034.fdocuments.net/reader034/viewer/2022051411/547557a4b4af9fbe0a8b5b5e/html5/thumbnails/7.jpg)
INTEGER EXPRESSION
• An integer expression is a mathematical expression involving integer values and arithmetic operators.
![Page 8: Part II: Assembly Fundamentals](https://reader034.fdocuments.net/reader034/viewer/2022051411/547557a4b4af9fbe0a8b5b5e/html5/thumbnails/8.jpg)
REAL NUMBER CONSTANTS
• Real number constants are represented as decimal reals or encoded (hexadecimal) reals.
• A decimal real contains an optional sign followed by an integer
• A decimal point, an optional integer that expresses a fraction, and an optional exponent
![Page 9: Part II: Assembly Fundamentals](https://reader034.fdocuments.net/reader034/viewer/2022051411/547557a4b4af9fbe0a8b5b5e/html5/thumbnails/9.jpg)
CHARACTER AND STRING CONSTANTS
• A character constant is a single character enclosed in single or double quotes.
• ‘A’
• “A”
• A string constant is a sequence of characters (including spaces) enclosed in single or double quotes
• ‘Hi All’
• “Welcome”
![Page 10: Part II: Assembly Fundamentals](https://reader034.fdocuments.net/reader034/viewer/2022051411/547557a4b4af9fbe0a8b5b5e/html5/thumbnails/10.jpg)
RESERVED WORDS
• Reserved words have special meaning Assembly and can only be used in their correct context.
• Instruction mnemonics (MOV, ADD, SUB)
• Register names
• Directives
• Attributes, which provide size and usage information for variables and operands
• Operators, used in constant expressions
• Predefined symbols (@)
![Page 11: Part II: Assembly Fundamentals](https://reader034.fdocuments.net/reader034/viewer/2022051411/547557a4b4af9fbe0a8b5b5e/html5/thumbnails/11.jpg)
IDENTIFIERS
• An identifier is a programmer-chosen name. It might identify a variable, a constant, a procedure, or a code label.
![Page 12: Part II: Assembly Fundamentals](https://reader034.fdocuments.net/reader034/viewer/2022051411/547557a4b4af9fbe0a8b5b5e/html5/thumbnails/12.jpg)
DIRECTIVES
• A directive is a command embedded in the source code that is recognized and acted upon by the assembler.
• Directives do not execute at runtime.
• The .DATA directive identifies the area of a program containing variables
• The .CODE directive identifies the area of a program containing executable instructions
![Page 13: Part II: Assembly Fundamentals](https://reader034.fdocuments.net/reader034/viewer/2022051411/547557a4b4af9fbe0a8b5b5e/html5/thumbnails/13.jpg)
INSTRUCTIONS
• An instruction is a statement that becomes executable when a program is assembled.
• Instructions are translated by the assembler into machine language bytes.
• Then loaded and executed by the CPU at runtime.
![Page 14: Part II: Assembly Fundamentals](https://reader034.fdocuments.net/reader034/viewer/2022051411/547557a4b4af9fbe0a8b5b5e/html5/thumbnails/14.jpg)
INSTRUCTIONS
• Instruction have four parts:
• Label (optional)
• Instruction mnemonic (required)
• Operand(s) (usually required)
• Comment (optional)
[label:] mnemonic [operands] [;comment]
![Page 15: Part II: Assembly Fundamentals](https://reader034.fdocuments.net/reader034/viewer/2022051411/547557a4b4af9fbe0a8b5b5e/html5/thumbnails/15.jpg)
INSTRUCTIONS - LABEL
• A label is an identifier that acts as a place marker for instructions and data.
• Data Labels A data label identifies the location of a variable, providing a convenient way to reference the variable in code.
• count DWORD 100
• The assembler assigns a numeric address to each label
![Page 16: Part II: Assembly Fundamentals](https://reader034.fdocuments.net/reader034/viewer/2022051411/547557a4b4af9fbe0a8b5b5e/html5/thumbnails/16.jpg)
INSTRUCTIONS - LABEL
• Code Labels A label in the code area of a program (where instructions are located) must end with a colon (:) character.
• Code labels are used as targets of jumping and looping instructions.
• target:
• mov ax,bx
• ...
• jmp target
![Page 17: Part II: Assembly Fundamentals](https://reader034.fdocuments.net/reader034/viewer/2022051411/547557a4b4af9fbe0a8b5b5e/html5/thumbnails/17.jpg)
INSTRUCTION - INSTRUCTION MNEMONIC
• An instruction mnemonic is a short word that identifies an instruction.
Mnemonic Description
MOVMove (assign) one value to another
ADD Add two values
SUBSubtract one value from another
MUL Multiply two values
JMP Jump to a new location
CALL Call a procedure
![Page 18: Part II: Assembly Fundamentals](https://reader034.fdocuments.net/reader034/viewer/2022051411/547557a4b4af9fbe0a8b5b5e/html5/thumbnails/18.jpg)
INSTRUCTION - OPERANDS
• Assembly language instructions can have between zero and three operands.
• Each of which can be a register, memory operand, constant expression, or input-output port.
![Page 19: Part II: Assembly Fundamentals](https://reader034.fdocuments.net/reader034/viewer/2022051411/547557a4b4af9fbe0a8b5b5e/html5/thumbnails/19.jpg)
INSTRUCTION - OPERANDS
• The INC instruction has one operand:
inc eax ; add 1 to EAX
• The MOV instruction has two operands:
mov count,ebx ; move EBX to count
![Page 20: Part II: Assembly Fundamentals](https://reader034.fdocuments.net/reader034/viewer/2022051411/547557a4b4af9fbe0a8b5b5e/html5/thumbnails/20.jpg)
INSTRUCTION - COMMENTS
• Comments are an important way for the writer of a program to communicate information about the program’s design to a person reading the source code.
• The following information is typically included at the top of a program listing:
• Description of the program’s purpose
• Names of persons who created and/or revised the program
• Program creation and revision dates
• Technical notes about the program’s implementation
![Page 21: Part II: Assembly Fundamentals](https://reader034.fdocuments.net/reader034/viewer/2022051411/547557a4b4af9fbe0a8b5b5e/html5/thumbnails/21.jpg)
INSTRUCTION - COMMENTS
• Comments can be specified in two ways:
• Single-line comments, beginning with a semicolon character (;).
• Block comments, beginning with the COMMENT directive and a user-specified symbol
COMMENT !
This line is a comment.
This line is also a comment.
!
![Page 22: Part II: Assembly Fundamentals](https://reader034.fdocuments.net/reader034/viewer/2022051411/547557a4b4af9fbe0a8b5b5e/html5/thumbnails/22.jpg)
INSTRUCTION EXECUTION
• Fetch:
• The control unit fetches the next instruction from the instruction queue and increments the instruction pointer (IP).
• Decode:
• The control unit decodes the instruction’s function to determine what the instruction will do.
• Fetch operands:
• If the instruction uses an input operand located in memory, the control unit uses a read operation to retrieve the operand and copy it into internal registers
![Page 23: Part II: Assembly Fundamentals](https://reader034.fdocuments.net/reader034/viewer/2022051411/547557a4b4af9fbe0a8b5b5e/html5/thumbnails/23.jpg)
INSTRUCTION EXECUTION
• Execute:
• The ALU executes the instruction using the named registers and internal registers as operands and sends the output to named registers and/or memory
• Store output operand:
• If the output operand is in memory, the control unit uses a write operation to store the data.
![Page 24: Part II: Assembly Fundamentals](https://reader034.fdocuments.net/reader034/viewer/2022051411/547557a4b4af9fbe0a8b5b5e/html5/thumbnails/24.jpg)
INSTRUCTION EXECUTION
loop
fetch next instruction
advance the instruction pointer (IP)
decode the instruction
if memory operand needed, read value from memory
execute the instruction
if result is memory operand, write result to memory
continue loop