Professional Documents
Culture Documents
1.
Syntax of Assembly Language Statements:-
The fields in the square brackets are optional. A basic instruction has two parts, the
first one is the name of the instruction (or the mnemonic), which is to be executed,
and the second are the operands or the parameters of the command.
3.
Three Categories of Instructions:
The instruction set is a collection of instructions each representing a CPU
operation. In assembly language, the instructions are represented by the
mnimonics and the operands (or their addresses) involved in the operation.
1. Data manipulation:-
Arithmetic manipulation:
add, sub, mult, div, etc.
Logic and bit manipulation:
and, or, nor, xor, etc.
Shift and rotation (to right or left):
sll, srl, sra, rol, ror, etc.
Note: Instruction srl (shift right logical) shifts a 0 into the vacated bit (the sign bit),
while instruction sra (shift right arithmetic) repeats the sign bit (sign extension for
signed 2's complement).
2. Data transfer:-
transfer data between MM and CPU:
lw (load word), la (load address), lb (load byte),sw (store word), sb
(store byte), etc.
transfer data between registers in RF:
move, mfhi, mflo, mthi, mtlo,
3. Iteration Control Instruction:-
branch to instruction other than the one following the current one
conditionally or unconditionally (based on comparison between
two operands or between one operand and zero):
b, beq, bne, bgt, blt, bge, ble, beqz, bnez, bgez, bgtz,
jump to different segments of the program (functions, subroutines,
etc.) j, jal, jalr, jr, etc.
4. Interrupt Instructions
5. Logical Instructions
6. Stack Instructions
7. I/O Instructions
4.
I. Data Transfer Instructions:-
These instructions are used to transfer the data from the source operand
to the destination operand. Following are the list of instructions under
this group –
MOV − Used to copy the byte or word from the provided source to
the provided destination.
PPUSH − Used to put a word at the top of the stack.
POP − Used to get a word from the top of the stack to the provided
location.
PUSHA − Used to put all the registers into the stack.
POPA − Used to get words from the stack to all registers.
XCHG − Used to exchange the data from two locations.
XLAT − Used to translate a byte in AL using a table in the memory.
IN − Used to read a byte or word from the provided port to the accumulator.
OUT − Used to send out a byte or word from the accumulator to the
provided port.
LEA − Used to load the address of operand into the provided register.
LDS − Used to load DS register and other provided register from the
memory
LES − Used to load ES register and other provided register from the
memory.
5.
Instructions to transfer flag registers :-
LAHF − Used to load AH with the low byte of the flag register.
SAHF − Used to store AH register to low byte of the flag register.
PUSHF − Used to copy the flag register at the top of the stack.
POPF − Used to copy a word at the top of the stack to the flag register.
7.
Instructions to perform division:-
DIV − Used to divide the unsigned word by byte or unsigned double word
by word.
IDIV − Used to divide the signed word by byte or signed double word by
word.
AAD − Used to adjust ASCII codes after division.
CBW − Used to fill the upper byte of the word with the copies of sign bit of
the lower byte.
CWD − Used to fill the upper word of the double word with the sign bit of
the lower word.
These instructions are used to perform operations where data bits are involved, i.e.
operations like logical, shift, etc. Following is the list of instructions under this
group −
Instructions to perform logical operation:-
NOT − Used to invert each bit of a byte or word.
AND − Used for adding each bit in a byte/word with the corresponding bit
in another byte/word.
OR − Used to multiply each bit in a byte/word with the corresponding bit in
another byte/word.
XOR − Used to perform Exclusive-OR operation over each bit in a
byte/word with the corresponding bit in another byte/word.
TEST − Used to add operands to update flags, without affecting operands.
SHL/SAL − Used to shift bits of a byte/word towards left and put zero(S) in
LSBs.
SHR − Used to shift bits of a byte/word towards the right and put zero(S) in
MSBs.
SAR − Used to shift bits of a byte/word towards the right and copy the old
MSB into the new MSB.
8.
Instructions to perform rotate operations :-
ROL − Used to rotate bits of byte/word towards the left, i.e. MSB to LSB
and to Carry Flag [CF].
ROR − Used to rotate bits of byte/word towards the right, i.e. LSB to MSB
and to Carry Flag [CF].
RCR − Used to rotate bits of byte/word towards the right, i.e. LSB to CF
and CF to MSB.
RCL − Used to rotate bits of byte/word towards the left, i.e. MSB to CF and
CF to LSB.
9.
V. Logical Instruction
The processor instruction set provides the instructions AND, OR, XOR, TEST, and
NOT Boolean logic, which tests, sets, and clears the bits according to the need of
the program. The format for these instructions
The first operand in all the cases could be either in register or in memory. The
second operand could be either in register/memory or an immediate (constant)
value.
The OR Instruction :-
The XOR instruction implements the bitwise XOR operation. The XOR operation
sets the resultant bit to 1, if and only if the bits from the operands are different. If
the bits from the operands are same (both 0 or both 1), the resultant bit is cleared to
0.
For example,
Operand1: 0101
Operand2: 0011
----------------------------
After XOR -> Operand1: 0110
XORing an operand with itself changes the operand to 0. This is used to clear a
register.
XOR EAX, EAX
11.
The TEST Instruction:-
The TEST instruction works same as the AND operation, but unlike AND
instruction, it does not change the first operand. So, if we need to check whether a
number in a register is even or odd, we can also do this using the TEST instruction
without changing the original number.
TEST AL, 01H
JZ EVEN_NUMBER
12.
DATA SEGMENT REGISTER
MOV AX,NUM1 ;MOV NUM1 INTO ACCUMULATOR AX
REGISTER
MOV BX,NUM2 ;MOV NUM2 INTO BASE BX REGISTER
ADD AX,BX ;ADDING THE CONTENTS OF AX AND BX.
RESULT IS STILL IN ACCUMULATOR
MOV RESULT,AX ;MOVE THE RESULT FROM AX INTO RESULT
VARIABLE
MOV AH,4CH ;END OF THE CODE
INT 21H ;END OF THE CODE
CODE ENDS ;END OF CODE SEGMENT
END START ;END OF START
; INPUT :
; NUM1 – 4537H
; NUM2 – 2222H
; OUTPUT :
; RESULT – 6759H
---------------------************----------------------
13.