Computer Organization and Assembly Language

Download Computer Organization and Assembly Language

Preview text

Computer Organization and Assembly Language
Lecture 3 – Assembly Language Fundamentals
Basic Elements of Assembly Language
An assembly language program is composed of : • Constants • Expressions • Literals • Reserved Words • Mnemonics • Identifiers • Directives • Instructions • Comments

Integer Constants

• Integer constants can be written in decimal, hexadecimal, octal or binary, by adding a radix (or number base) suffix to the end .

• Radix Suffices:


decimal (the default)



– q or o




Examples of Integer Constants

• 26 • 1Ah • 1101b • 36q • 2Bh • 42Q • 36D • 47d

Decimal Hexadecimal Binary Octal Hexadecimal Octal Decimal Decimal

Integer Expressions

• An integer expressions is a mathematical expressions involving integer values and integer operators.

• The expressions must be one that can be stored in 32 bits (or less).

• The precedence:

– ()

Expressions in Parentheses

– +, -

Unary Plus and minus

– *, /, Mod Multiply, Divide, Modulus

– +, -

Add, Subtract

Examples of Integer Expressions

16 / 5 - (3 + 4) * (6 – 1) -3 + 4 * 6 – 1 4 + 5 * 2 -5 + 2 12 – 1 MOD 5 (4 + 2) * 6

3 -35 20

Real Number Constants
• There are two types of real number constants: – Decimal reals, which contain a sign followed by a number with decimal fraction and an exponent:
[sign] integer.[integer][exponent]
2. +3.0 -44.2E+05 26.E5
– Encoded reals, which are represented exactly as they are stored:
Characters Constants
• A character constant is a single character enclosed in single or double quotation marks.
• The assembler converts it to the equivalent value in the binary code ASCII:
‘A’ “d”

String Constants
• A string constant is a string of characters enclosed in single or double quotation marks:
‘ABC’ “x” “Goodnight, Gracie” ‘4096’ “This isn’t a test” ‘Say “Goodnight, ” Gracie’
Reserved Words
• Reserved words have a special meaning to the assembler and cannot be used for anything other than their specified purpose.
• They include: – Instruction mnemonics – Directives – Operators in constant expressions – Predefined symbols such as @data which return constant values at assembly time.

• Identifiers are names that the programmer chooses to represent variables, constants, procedures or labels.
• Identifiers: – can have 1 to 247 characters – are not case-sensitive – begin with a letter , underscore, @ or $ and can also contain digits after the first character. – cannot be reserved words

Examples of Identifiers

var1 _main @@myfile Count xVal

open_file _12345 $first MAX

• Directives are commands for the assembler, telling it how to assemble the program.
• Directives have a syntax similar to assembly language but do not correspond to Intel processor instructions.
• Directives are also case-insensitive: • Examples
.data .code name PROC
• An instruction in Assembly language consists of a name (or label), an instruction mnemonic, operands and a comment
• The general form is: [name] [mnemonic] [operands] [; comment]
• Statements are free-form; i.e, they can be written in any column with any number of spaces between in each operand as long as they are on one line and do not pass column 128.

• Labels are identifiers that serve as place markers within the program for either code or data.
• These are replaces in the machine-language version of the program with numeric addresses.
• We use them because they are more readable: mov ax, [9020] vs. mov ax, MyVariable

Code Labels

• Code labels mark a particular point within

the program’s code.

• Code labels appear at the beginning and are

immediately followed by a colon:



ax, bx

… …

jmp target

Data Labels
• Labels that appear in the operand field of an instruction:
mov first, ax
• Data labels must first be declared in the data section of the program:
first BYTE 10
Instruction Mnemonics
• Instruction mnemonics are abbreviations that identify the operation carried out by the instruction:
mov - move a value to another location add - add two values sub - subtract a value from another jmp - jump to a new location in the program mul - multiply two values call - call a procedure


• Operands in an assembly language

instruction can be:

– constants


– constant expressions 2 + 4

– registers


– memory locations


Operands and Instructions

• All instructions have a predetermined number of operands.

• Some instructions use no operands:


; set the Carry Flag

• Some instructions use one operand:


ax ; add 1 to AX

• Some instructions use two operands:


count, bx ; add BX to count

Preparing to load PDF file. please wait...

0 of 0
Computer Organization and Assembly Language