Professional Documents
Culture Documents
Lecture 5
Lecture 5
• We also call it an opcode that stands for operation code – i.e., the code which
specifies the operation to be performed.
• Certain instructions have only one operand mentioned which is either the
destination or the source. These can be register or memory operands, but not
immediate data.
• Branch Instructions
• Arithmetic Instructions
• Logical Instructions
• String Instructions
• I/O Instructions
Data Transfer Instructions
We will come back to these later
• MOV – Move
• Usage: MOV Destination, Source
• MOV AX, 100H
• MOV AX, CX
• MOV AL, AH
• MOV AX, [BX]
• MOV COST, DX
• MOV AL, ‘W’
Arithmetic Instructions
• Conditional Jump
JNZ Label
JNC Label
Simple Program 1
• Store two numbers in registers and put their sum in a third register.
Simple Program 2
• Add two numbers. If the sum is greater than some X, make register
CX=0, else make CX=1.
How to use Memory Locations-Assembly Process,
Instructions and Directives, Memory Models
• When we want to write and execute an ALP, we first type it using an editor. Then
we assemble, link and run it.
• An assembler translates this symbolic language to machine code which the
processor will understand.
• An assembly language program contains pseudo-instructions (directives) along
with instructions.
• Instructions get translated to machine codes, but directives do not. i.e.,
instructions produce executable code, but directives do not. They direct the
assembler to perform in certain ways that we would like it to.
• The directives perform as ‘help’ for the assembler for deciding certain
other aspects of the assembly process
• Different popular assemblers are NASM, FASM, MASM, TASM and HLA.
Memory Models
• To write programs, we know we have to define segments, which means that the
segment registers must be initialized.
• Assemblers offer shortcuts which help to make programming simple. These are
called the dot models. They have the format:
.MODEL MODEL_NAME
• The different models tell the assembler how to use segments and to provide
sufficient space for the object code.
• The simplest of these are the tiny model and the small model.
• The tiny model is used when code, data and stack will all fit into one segment
with a maximum size of 64 K.
• The small model can have one data segment and one code segment
each of which has a maximum size of 64 K.
The Tiny Model
• Let us understand this model with the help of a code snippet. First without memory variables
The Assembler inserts instructions to initialize the segment registers except CS which is done by OS
The DUP Directive
• This directive is used to replicate a given number of characters.