0% found this document useful (0 votes)
23 views19 pages

Lecture 6 COAL

Computer organization and assembly languages lec 6

Uploaded by

Shams AlHadi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views19 pages

Lecture 6 COAL

Computer organization and assembly languages lec 6

Uploaded by

Shams AlHadi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Computer Organization and

Assembly Language
Week 7
Lecture 06: Assembly language fundamentals
Instructor: Engr. Iqra Saleem
Email: [email protected]
UNIVERSITY OF HARIPUR
Integer constants

• Optional leading + or – sign


• Binary, decimal, hexadecimal and octal digits
• Common radix characters:
-h-hexadecimal
-d-decimal
-b-binary
Examples: 30d, 6Ah, 1101b, 42
• Hexadecimal beginning with letter: 0A5h
Reserved Words

There are different type of reserved words:


• Instruction mnemonics: such as MOV, ADD and MUL
• Register names
• Directives which tell MASM how to assemble programs
• Attributes which provide size and usage information for variables and
operands. Examples are byte and word.
• Operators used in constant expressions.
• Predefined symbols such as @data which return constant integer
values
Identifier

• Identifier is a programmer-chosen name.


• It might identify a variable, constant, procedure or a code label.
Keep the following in mind when creating identifiers:
• They may contain between 1 and 247 characters.
• They are not case sensitive
• The first character must be a letter (A….z), underscore (_). @, ? Or $.
• The @ symbol is used extensively by the assembler as a prefix for
predefined symbols, so avoid it in your own identifiers.
• An identifier cannot be the same as an assembler reserved word.
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 run time.
• Directives can define variables, macros and procedures.
• They can assign names to memory segments.
• In MASM, directives are case insensitive.
• For example it recognizes .data, .DATA, .Data equivalent.
Directives

The following example helps to show the difference between directives


and instructions
• The DWORD directive tells the assembles to reserve space in the
program for a doubleword variable.
• The MOV instruction executes at runtime, copying the contents of
myVAR to EAX register:
• myVar DWORD 26 \\ DWORD directive
• Mov eax, myVar \\ MOV instruction
Directives
Segments
• One important function of assembler directives is to defines program
sections or segments
• The .data directive identifies the area of a program containing
variables.
• The .code directive identifies the area of a program containing
executable instaructions.
• The .data directive identifies the area of a program holding the
runtime stack, setting its size.
Instructions

• An instruction is a statement that becomes executable when a program is


assembled.
• Instructions are translated by the assembler into machine language bytes, which are
loaded and executed by the CPU at runtime.
An instruction contains four basic parts:
Label (optional)
Instruction mnemonic (required)
Operands (usually reqired)
Comments (optional)
This is the basic syntax:
[label:] mnemonic [operands] [;comments]
Instructions
label
• A label is an identifier that acts as a place marker for instructions and data.
• A label place just before an instruction implies the instruction address.
• Similarly, a label place just before a variable implies the variable’s address.
• Data labels: A data label identifies the location of a variable, providing a convenient way to
reference the variable in code.
• count DWORD 100
• Code labels: A label in the code area of a program (where instructions are located) must end
with a colon (:) charcutier.
• Code labels are used as targets of jumping and looping instructions.
Target:
Mov ax, bx
…..
Jmp target
Instructions
Instruction mnemonic
• An instruction mnemonic is a short word that identifies an instruction.
• Mov: assign one value to another
• Add: add two values
• Sub: subtract two values
• Mul: multiply two values
• Jmp: jump to a new location
• Call: call a procedure
Instructions
Operands
• Assembly language instructions can have between zero and three
operands, that can be register, memory operand, constant expression,
or input-output port.
• A memory operand is specified by the name of a variable or by one or
more registers containing the address of variable
• The STC instruction, for example, has no operands, stc: set carry flag.
Instructions
Operands
• The INC instruction has one operand
Inc eax: add 1 to eax
• The mov instruction has two operands
Mov count, ebx: mov ebx to count
• In two operand instruction, the first operand is destination and the second
operand is the source,
• The IMUL instruction has 3 operands in which the first operand is the
destination and the following two operands are the source operands
Imul eax, ebx, 5
• In this case, ebx is multiplied by 5 and the product is stored in the eax register.
Datatypes

• It specifies which type of value a variable can hold.


• It allow you to allocate memory and initialize it with specific values of different sizes,
suitable for various data types and operations.
Common data types include:
• DB (Define Byte),1 byte
• DW (Define Word), 2byte
• DD (Define Doubleword), 4 byte
• DQ (Define quadword), 8 byte
• DT (Define Terabyte) ,10 byte
Important points
• V1 db 50 (stores ASCII i.e ‘2’)
• V2 db ‘50’ (stores number ‘50’)
• V3 db ‘A’
• V4 db ? (run time declaration)
• V5 db ‘hello$’ (strings always terminated by $ sign)
For working with variables in code segment:
.
code
Main proce
Mov ax,@data
Mov ds,ax
Mov dl,v1
Mov ah,2
Int 21h
Important points
Runtime declaration:
//varname datatype ?(in data section)

Mov bl,5
Mov v4,bl
For printing strings:
//V5 db ‘hello$’

Mov dx,offset v5
Mov ah,9
OR
Lea dx,v5 (load effective address)
Symbolic constants
• Symbolic constants are named values that remain constant throughout
the program, making the code more readable and easier to maintain .
• Do not use storage
• No datatype
• Can be defined in .code and .data segment
• count=500
• +,-,/,* operators with constants
Variables

• Variables are used to store data that can be accessed and change during the
program's execution.
• Variables are typically defined in the data segment and can be of various sizes,
such as bytes, words, or double words.
• Use storage
• Equal sign is not used with variables
Equal sign directive “=”

• Use to define the symbolic constants.


• Some assemblers may have specific keywords or directives for defining symbolic
constants, such as EQU or DEFINE.
• count =1 , zero=2
• Always use integer value after equal sign.
Examples of EQU keyword

• Assembly
Example 1:
NUM_BYTES EQU 1024
Defines symbolic constant NUM_BYTES with value 1024.
Example 2:
True EQU 1
False EQU 0
Define symbolic constants True and False with values 1 and 0 respectively

You might also like