Assembly Language
Assembly Language
.data
;data definition
.code
main proc
; instructions
main endp
end main
Some Instructions
MOV
Transfer data between registers, between register and a memory location or move a number
directly to a register or a memory location.
Syntax: MOV destination, source
Example: MOV AX, WORD1
ADD
To add contents of two registers, a register and a memory location, a number to a register or a
number to a memory location.
Syntax: ADD destination, source
Example: ADD WORD1, AX
SUB
To subtract the contents of two registers, a register and a memory location, a number from a
register or a number from a memory location.
Syntax: SUB destination, source
Example: SUB AX, DX
Instructions
INC
DEC
To decrement one from the contents of a register or memory location.
Syntax: DEC destination
Example: DEC BYTE1
NEG
To negate the contents of destination.
Syntax: NEG destination
Example: NEG BX
XCHG
C Assembly
A= B – 2 *A MOV AX, B
SUB AX, A
SUB AX, A
MOV A, AX
Basic input output Program
.model small
.stack 100h
.data
.code
main proc
mov ah,1 ;takes input in al
int 21h ; interrupt
mov dl,al
Labels are needed in situations where one instruction refers to another. Labels
end with a colon. Label usually placed on a line by themselves. They refer to
the instruction that follows. The JMP instruction
The JMP instruction causes an unconditional jump. JMP can be used to get around the
range restriction of a conditional jump.
Syntax: JMP destination_label
Conditional Jump
If the conditions for the jump instruction, that is the combination of status flag
settings are true, the CPU adjusts the IP to point to the destination label so that
the instruction at this label will be executed next. If the jump condition is false,
then IP is not altered. If the condition for the jump is true, the next instruction
to be executed is the one at destination_label. If the condition is false, the
instruction immediately following the jump is done next.
Syntax: JGE destination_label
Signed Conditional jump
Symbol Description
JGE/JNL
Jump if not less than or equal to
Symbol Description
Jump if above
Jump if below
Jump if equal
JE/JZ
Jump if equal to or zero
Jump if not equal
JNE/JNZ
Jump if not zero
JC Jump if carry
JO Jump if overflow
Address Content
1 A[1]
A 10
2 A[2]
A+2 20
3 A[3] A+4 30
4 A[4] A+6 40
5 A[5] A+8 50
6 A[6] A+10 60
DUP Operator
• Causes the value to be repeated the number of times specified
• Ex: gamma dw 100 dup(0)
• Dup can be nested
• Ex: line db 5,4,3 dup (2,3 dup(0),1)
• line db 5,4,2,0,0,0,1,2,0,0,0,1,2,0,0,0,1
DUP Operator
• 5,4, 3 dup (2,3 dup(0),1)
• 5,4, 3 dup (2, 0, 0, 0, 1)
• 5, 4 , 2, 0, 0, 0, 1, 2, 0, 0, 0, 1, 2, 0, 0, 0, 1
Location of Array Elements
• A is an array and S denotes the number of bytes in an element.
(S=1 for byte array, S=2 for word array)
• The position of A can be determined as follows
Position Location
1 A
2 a= 1 * S
3 a= 2 * S
. .
. .
N a= (N-1) * S
Math
• Exchange 10th and 25th elements in a word array W.
Solution:
W[10] is located at address W + 9*2 = W + 18 and
W[25] is located at address W + 24*2 = W + 48,
L1:
int 21h
mov [si],al
inc si
loop L1
Exit:
mov ah,4ch ;kind of like return 0
int 21h
main endp
end main
Output from a given array
.model small
.stack 100h
.data
arr db 'a', 'b', 'c', 'd', 'e'
.code
main proc
mov ax,@data
mov ds,ax
mov si,offset arr
mov cx,5
mov ah,2
L1:
mov dl ,[si]
int 21h
inc si
loop L1
Exit:
mov ah,4ch
int 21h
main endp
end main
Divisible by 2/Odd- Even
include 'emu8086.inc'
.model small
.stack 100h
.data
.code
main proc
mov ax,@data
mov ds,ax
mov ah,1
int 21h
sub al,48
mov bh,2
div bh
cmp ah, 00h
JZ print1
print 'Odd'
jmp Exit
print1:
print 'Even'
Exit:
mov ah,4ch
int 21h
main endp
end main
Linear Search
include 'emu8086.inc' print 'Enter the character you want to search:‘
.model small mov ah,1
.stack 100h int 21h
mov cx,5
.data
mov si,offset arr
;arr db "Nazmul"
arr db 'N', 'a', 'z', 'm', 'u', 'l' Search:
.code cmp al,[si]
main proc JZ found
mov ax,@data inc si
mov ds,ax Loop Search
JMP Exit
mov ah,2
mov si,offset arr
found:
mov cx,6 mov bh,al
mov ah,2
L1: mov dl,bh
mov dl, [si] int 21h
int 21h print 'Found'
inc si
Exit:
loop L1 mov ah,4ch
Mov ah,2 //for newline int 21h
mov dl,13 main endp
int 21h end main
mov dl,10
int 21h
THANK YOU