Beruflich Dokumente
Kultur Dokumente
gi
is
Microprocessor Laboratory
ps
Introduction
gi
is
10CSL48
12 Software programs
12 Hardware programs using interface kits
MASM (Microsoft Assembler)
ps
t
gi
Assembler
is
Program
.asm
Source
Program
Object file
.obj
Assemble
Assembler
link
Executable file
.exe
Obj &
Exe files
ps
ps
is
gi
gi
ALP
MOV AL, BL
is
1000100011000011
MOV
Register
mode
ps
ps
is
t
gi
Registers
gi
ps
is
gi
is
Disadvantages:
ps
gi
Numbering Systems
ps
is
Binary - Base 2
0, 1
Octal - Base 8
0, 1, 2, 7
Decimal - Base 10
0, 1, 2, , 9
Hexadecimal (Hex) - Base 16
0, 1, , 9, A, B, , F
gi
Assembler Directives
SEGMENT
ENDS
End of segment
ORG
END
DW
Define word
DB
Define byte.
EQU
Equate or equivalence
is
ps
ASSUME
t
gi
e
is
u
ps
Memory
t
gi
ps
is
Here we go!
gi
Sample Program
Problem Statement
is
ps
gi
AL
MOV AL,05
BL
MOV BL,04
AL
ADD AL,BL
05
04
is
ps
09
gi
Operands
Destination Operand Source Operand
AL
05
MOV
BL
04
ADD
AL
BL
MUL
BL
DIV
AX
ps
MOV
is
Mnemonic
BL
ps
mov ah,4ch
int 21h
code ends
end start
Assembler directives
is
assume cs:code
code segment
start:
mov al,05
mov bl,04
add al,bl
gi
ps
mov ah,4ch
int 21h
code ends
end start
e
is
assume cs:code
code segment
start:
mov al,05
mov bl,04
add al,bl
gi
gi
ps
is
Command prompt
CD\
CD MASM32
EDIT
Type the ALP & save the file with
filename.asm
ps
is
1.EDIT filename.asm
2.MASM filename;
3.LINK filename;
4.CV filename
t
gi
MASM Steps
EDIT
MASM
LINK
CV
t
gi
is
ps
Enter your
Login name and Password
gi
Step 1: EDITOR
is
ps
t
gi
Step 2: MASM
ps
is
MASM filename;
For example:
masm add;
t
gi
Step 3: LINK
ps
is
LINK filename;
For example:
link add;
t
gi
Step 4: CV
ps
is
CV filename
For example:
cv add
t
gi
Executing
ps
is
Execution Steps:
RUN ANIMATE
Or
RUN SINGLE STEP
t
gi
is
Now
ps
Your Turn
is
mov al,05
mov bl,04
add al,bl
mov al,05
ps
add al,04
t
gi
Optimize Code
ps
mov ah,4ch
int 21h
end segment
end start
e
is
assume cs:code
code segment
start:
mov al,05
mov bl,04
add al,04
gi
mov al,number1
add al,number2
mov sum,al
ps
mov ah,4ch
int 21h
end segment
end start
gi
e
is
assume cs:code,ds:data
data segment
number1 db 04
number2 db 05
sum db ?
data ends
code segment
start:
mov ax,data
mov ds,ax
t
gi
is
ps
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
MSG1 DB "ENTER YOUR NAME:$"
DATA ENDS
START:
MOV AX,DATA
MOV DS,AX
LEA DX,MSG
MOV AH,09H
INT 21H
ps
MOV AH,4CH
INT 21H
CODE ENDS
END START
is
CODE SEGMENT
gi
gi
is
DATA SEGMENT
MSG1 DB "ENTER YOUR NAME:$
MSG2 DB "WHAT IS YOUR NAME?$"
DATA ENDS
CODE SEGMENT
START:
ps
MOV AX,DATA
MOV DS,AX
gi
t
ps
MOV AH,4CH
INT 21H
CODE ENDS
END START
is
LEA DX,MSG2
MOV AH,09H
INT 21H
LEA DX,MSG1
MOV AH,09H
INT 21H
t
gi
7a Algorithm
ps
is
gi
is
ASSUME CS:CODE,DS:DATA
ps
DATA SEGMENT
MSG1 DB 0AH,0DH,"ENTER YOUR NAME:$"
MSG2 DB "WHAT IS YOUR NAME?$"
ARRAY DB 30 DUP(0)
DATA ENDS
gi
CODE SEGMENT
is
START:
MOV AX,DATA
MOV DS,AX
ASSUME
CS:CODE,DS:DATA
ps
LEA DX,MSG1
MOV AH,09H
INT 21H
1. Display message
Enter Your Name:
MOV AH,01H
INT 21H
MOV [SI],AL
INC SI
CMP AL,0DH
JZ DOWN
JMP NEXT
gi
NEXT:
is
LEA SI,ARRAY
ps
DOWN:
DEC SI
MOV BYTE PTR [SI],'$'
t
gi
MOV DH,12
MOV DL,20
MOV AH,02
INT 10H
ps
is
3. Clear screen
MOV AX,0003H
INT 10H
5. Display message
What is your
name?
LEA DX,ARRAY
MOV AH,09H
INT 21H
is
gi
LEA DX,MSG2
MOV AH,09H
INT 21H
MOV AH,4CH
INT 21H
ps
CODE ENDS
END START
t
gi
is
Writing Journal
ps
7a. asm
Displaying Name at the center of the
screen
gi
is
Software used:
ps
t
gi
Theory:
ps
is
t
gi
e
is
ps
t
gi
Algorithm:
ps
is
t
gi
Procedure:
ps
is
t
gi
Results:
ps
is
ps
is
gi
t
gi
is
2.a.
ps
gi
is
Software used:
ps
t
gi
Theory:
ps
is
Macro:
The term macro refers to a word that stands for
an entire group of instructions.
permit a group of instructions to be defined as a
single entity
with a unique given label or name called up when
needed.
We need to write two macros: one to read a single
alpha-numeral from keyboard (in2a.asm)and
another to display (out2a.asm), separately as .asm
files.
t
gi
is
ps
t
gi
Algorithm:
ps
is
t
gi
Procedure:
ps
is
t
gi
Results:
ps
is
ps
t
is
gi
Screen shots:
gi
DATA SEGMENT
is
INCLUDE IN2A.ASM
INCLUDE OUT2A.ASM
ASSUME DS:DATA,CS:CODE
ps
DATA ENDS
gi
CODE SEGMENT
START:
MOV AX,DATA
MOV DS,AX
UP:
READ
CMP AL,0DH
JZ STOP
MOV [SI],AL
ps
INC SI
INC CL
JMP UP
MOV CX,0000H
is
LEA SI,STRING
STOP:
LEA SI,STRING
ps
MOV AH,4CH
INT 21H
CODE ENDS
END START
gi
DISPLAY
INC SI
LOOP UP1
is
UP1:
MOV DL,[SI]
LEA DX,MSG
MOV AH,09H
INT 21H
;terminate interrupt
t
gi
in2a.asm
is
ps
READ MACRO
MOV AH,01H
INT 21H
ENDM
t
gi
out2a.asm
is
ps
DISPLAY MACRO
MOV AH,02H
INT 21H
ENDM
t
gi
is
1a.asm
ps
Binary Search
gi
is
Software used:
ps
t
gi
Theory:
ps
is
t
gi
Algorithm:
ps
is
lo := 0;
hi := 7; {array size: var BX : LIST [0..7] of integer}
repeat
mid := lo + (hi - lo) div 2;
if KEY > LIST[mid] then
lo := mid + 1;
else
hi := mid - 1;
until (LIST[mid] = KEY) or (lo > hi);
DATA ENDS
;auto-initialization
;of data segment
is
CODE SEGMENT
START:
MOV AX,DATA
MOV DS,AX
MOV AL,0
MOV AH,7
MOV BX,0000
;AL = 0, lo
;AH = 7, hi
; clear BX, mid
CMP AH,AL
JL NOMATCH
;compare hi & lo
;if AH < AL, go to NOMATCH
NEXT:
ps
MOV BL,AL
ADD BL,AH
SHR BL,01
;BX mid
gi
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
LIST db 10H,20H,30H,40H,50H,60H,70H,80H
KEY equ 60H
;given list
;KEY to be searched,
;change it
CMP LIST[BX],KEY
JE MATCH
JB UPPER
MOV AH,BL
DEC AH
JMP NEXT
MOV AL,BL
INC AL
JMP NEXT
MOV DX,0FFFFH
JMP LAST
gi
MOV BH,0
is
UPPER:
MATCH:
ps
NOMATCH:
MOV DX,0AAAAH ;DX AAAA on KEY not found
LAST:
MOV AH,4CH
;terminate
INT 21H
t
gi
Procedure:
ps
is
t
gi
Result:
is
Case 1:
If key found DX = FFFFF
ps
Case 2:
If key not found DX = AAAA
t
gi
is
3a.asm
ps
Bubble Sort
t
gi
list
CX
cmp al,[si]
jc down
xchg al,[si]
mov [si-1],al
;decrement counter
;if not zero, go to next
loop next1
ps
jnz next
int 21h
SI
SI+1
SI+2
SI+3
SI+4
mov ah,4ch
inc si
down: dec bx
;terminate
SI-1
;load count in BX
is
AL
mov cx,count
BX
5>1
t
gi
is
3a.asm
ps
Journal Writing
t
gi
is
Aim:
Sort a given set of n numbers in ascending
order using the Bubble Sort algorithm.
Software used:
ps
t
gi
Theory:
ps
is
t
is
CX count
BX count for inner loop
SI address of list to be sorted
AL SI pointed data
SI SI + 1
AL [SI] , C=1 if AL < [SI] else C = 0
If C = 1 jump to step 9
Else exchange the two elements
ps
1.
2.
3.
4.
5.
6.
7.
8.
gi
Algorithm:
t
gi
ps
is
10.BX BX 1
11.If BX 0 then jump to step 4
12.If CX = 0 then jump to step 2
gi
Example:
Let us take the array of numbers "5 1 4 2 8", and sort the array from lowest number to
greatest number using bubble sort algorithm. In each step, elements written in bold are
being compared.
is
First Pass:
( 5 1 4 2 8 ) ( 1 5 4 2 8 ), Here, algorithm compares the first two elements, and swaps them.
( 1 5 4 2 8 ) ( 1 4 5 2 8 ), Swap since 5 > 4
( 1 4 5 2 8 ) ( 1 4 2 5 8 ), Swap since 5 > 2
( 1 4 2 5 8 ) ( 1 4 2 5 8 ), Now, since these elements are already in order (8 > 5), algorithm
does not swap them.
ps
Second Pass:
(14258) (14258)
( 1 4 2 5 8 ) ( 1 2 4 5 8 ), Swap since 4 > 2
(12458) (12458)
(12458) (12458)
And so on,
t
gi
3a.asm ALP
;3a.asm bubble sort in ascending order
assume cs:code,ds:data
data segment
list db 5h,1h,4h,2h,8h
count equ 04
data ends
is
;goto CV
;give command d ds:0000
;observe DS dump to see unsorted and sorted, on partially and fully execution of program,
;by F8 key twice and ALT+R+A commands, respectively.
mov ax,data
mov ds,ax
ps
start:
code segment
next1:
gi
mov cx,count
mov bx,cx
mov si,offset list
;load count in BX
;point to list with SI
mov al,[si]
inc si
cmp al,[si]
jc down
xchg al,[si]
mov [si-1],al
dec bx
jnz next
loop next1
;decrement counter
;if not zero, go to next
;if zero, go to next1
is
next:
down:
ps
mov ah,4ch
int 21h
code ends
end start
;terminate
t
gi
Procedure:
ps
is
t
gi
Result:
is
51248
ps
12458
is
gi
ps
t
gi
e
is
u
ps
t
gi
is
11a.asm
ps
Moving cursor
t
gi
Aim:
is
Software Used:
ps
t
gi
Theory:
ps
is
t
gi
Algorithm:
ps
is
t
gi
11a.asm ALP
DATA SEGMENT
is
x db 20
y db 40
;row - 0 to 24
;column - 0 to 79
DATA ENDS
ps
CODE SEGMENT
START:
MOV AX,DATA
MOV DS,AX
;data segment
;auto-initialization
;DH = row
;DL = column
;BH = 0, new page / clear screen
;function # 02 in AH
;int 10h, places cursor
gi
MOV DH,x
MOV DL,y
MOV BH,00
MOV AH,02
INT 10H
is
LOOP2:
MOV DL,0FFH
MOV AH,06H
MOV AH,4CH
INT 21H
; terminate
; interrupt
ps
CODE ENDS
END START
INT 21H
CMP AL,00H
JE LOOP2
t
gi
Procedure:
ps
is
t
gi
Result:
ps
is
gi
ps
is
t
gi
is
5a.asm
Palindrome - Reverse a string
ps
Journal writing
t
gi
Aim:
is
Software Used:
ps
gi
Theory:
ps
is
ps
e
is
gi
ps
t
is
gi
Algorithm:
gi
5a.asm ALP
is
assume ds:data,cs:code
;5a.asm - palindrome
;DX=FFFF means string is palindrome
;DX=AAAA means string is not palindrome
;check result in CV in register DX
;use command D DS:0000 to see Data Segment dump in CV
ps
data segment
givenstring db "liril"
n dw $-givenstring ;no. of characters is
;calculated by"$-givenstring"
reversedstring db 10 dup(0)
data ends
gi
code segment
start:
mov ax,data
mov ds,ax
;auto initialization of
;data segment
;reversing begins
mov si,0
mov di,0
is
mov cx,n
add si,cx
dec si
mov al,givenstring[si]
mov reversedstring[di],al
ps
loop1:
loop loop1
;reversing is complete here
;update SI
;update DI
gi
dec si
inc di
is
mov si,0
mov cx,n
loop2:
mov al,givenstring[si]
cmp al,reversedstring[si]
ps
je loop3
gi
mov dx,0aaaah
mov ah,4ch
int 21h
loop3:
mov ah,4ch
int 21h
ps
code ends
end start
;update SI
;next character
;given string is a palindrome, if
;DX=FFFF
is
inc si
loop loop2
mov dx,0ffffh
t
gi
Procedure:
ps
is
t
gi
Result:
ps
is
is
gi
5a Screen shots
ps
Givenstring = liril
Reversedstring = liril
palindrome, DX = FFFFh
gi
Givenstring = lirila
Reversedstring = aliril
ps
is
t
gi
is
8a.asm - nCr
ps
Journal Writing
t
gi
Aim:
is
Software Used:
ps
t
gi
Theory:
ps
is
gi
is
ps
1.
2.
3.
4.
5.
6.
7.
Algorithm:
gi
8a.asm ALP
ps
is
assume cs:code,ds:data
data segment
n dw 0006h
r dw 0003h
numerator dw ?
denimonator1 dw ?
denominator2 dw ?
denominator dw ?
data ends
code segment
; 8a.asm - nCr
; NOTE: use n & r up to 6, AVOID (n-r) = 1
; Execution Steps:
; MASM, LINK & CV filename
; result is in AX in Hex form, refer table at the end for sample nCr values
start:
gi
mov ax,data
mov ds,ax
;--n!
mov bx,ax
mov cx,ax
dec cx
is
mov ax,n
ps
up1: dec bx
; always n x (n-1)
mul bx
loop up1
mov numerator,ax
;AX = n!
;(n-r) is calculated in ax
is
up2:
;mov ax,03h
mov bx,ax
mov cx,ax
dec cx
dec bx
mul bx
loop up2
mov denominator1,ax
;--r!
ps
mov ax,r
mov bx,ax
mov cx,ax
dec cx
gi
mov ax,n
mov bx,r
sub ax,bx
;--(n-r)!
gi
is
;--denom=(n-r)1 x r!
mov ax,denominator1
mov bx,denominator2
mul bx
mov denominator,ax
dec bx
mul bx
loop up3
mov denominator2,ax
up3:
ps
int 03h
code ends
end start
t
gi
Procedure:
ps
is
t
gi
Results:
nCr Hexadecimal
4C2
06
5C2
10
0A
5C3
10
6C2
15
0F
6C3
20
14
6C4
15
0F
ps
is
nCr Decimal
nCr
0A
ps
is
t
gi
is
gi
Screen shots:
ps
t
gi
is
ps
Journal Writing
t
gi
Aim:
is
Software Used:
ps
gi
4a.asm ALP
code segment
is
assume cs:code
start:
;read character in AL
ps
mov ah,01h
int 21h
mov bl,al
mov dl,bl
and dl,0f0h
mov cl,04
shr dl,cl
cmp dl,10
jl down1
add dl,07
gi
down1:
mov ah,02h
int 21h
is
add dl,30h
ps
mov dl,bl
and dl,0fh
cmp dl,10
jl down2
add dl,07
t
;if less than 10, add 30 to make it ASCII
;display service: 02h function, int 21h
;displays single character, when DL ? ASCII
;of the character
is
mov ah,02h
int 21h
gi
down2:
add dl,30h
ps
code ends
end start
mov ah,4ch
int 21h
;terminate
Theory:
gi
is
ps
t
gi
Algorithm:
ps
is
t
gi
Procedure:
ps
is
t
gi
Result:
ASCII
a
A
1
9
61H
41H
31H
39H
0DH
is
Alphanumeral
ps
(ENTER key)
ps
is
gi
ps
t
is
gi
Screen Shots:
t
gi
is
12a1.asm
12a2.asm
ps
file creation
and
file deletion
t
gi
Aim:
is
Software Used:
ps
t
gi
Int 21H creates a new file if not already exists, when supplied
following parameters:
is
ps
t
gi
ps
is
gi
ASSUME CS:CODE,DS:DATA
is
DATA SEGMENT
filename DB "c:\newfile.txt"
DATA ENDS
ps
CODE SEGMENT
START:
MOV AX,DATA
MOV DS,AX
is
ps
MOV AH,4CH
INT 21H
CODE ENDS
END START
t
gi
t
gi
is
ps
t
gi
ps
is
gi
is
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
filename DB "c:\newfile.txt"
DATA ENDS
ps
CODE SEGMENT
START:
gi
MOV AX,DATA
MOV DS,AX
is
ps
MOV AH,4CH
INT 21H
CODE ENDS
END START
t
gi
Procedure:
ps
is
ps
is
gi
ps
is
gi
t
gi
is
9a.asm
ps
Time display
t
gi
Aim:
is
Software Used:
ps
t
gi
Theory:
ps
is
t
gi
e
ps
is
t
is
ps
1.
2.
3.
4.
5.
6.
7.
8.
9.
gi
Algorithm:
t
gi
9a.asm ALP:
assume cs:code,ds:data
lea dx,msg1
mov ah,09h
int 21h
ps
mov ah,2ch
int 21h
is
code segment
start:
mov ax,data
mov ds,ax
data segment
msg1 db 0ah,0dh,"The current time is: $"
data ends
t
gi
Procedure:
ps
is
is
mov dl,':'
mov ah,02h
int 21h
mov al,cl
add al,00
daa
call display
ps
mov dl,':'
mov ah,02h
int 21h
t
gi
mov al,ch
add al,00
daa
call display
gi
mov al,dh
add al,00
daa
call display
is
mov dl,'.'
mov ah,02h
int 21h
mov al,dl
add al,00
daa
call display
ps
mov ah,4ch
int 21h
gi
is
mov bl,al
and al,0f0h
mov cl,04h
shr al,cl
add al,30h
ps
mov dl,al
mov ah,02h
int 21h
mov al,bl
and al,0fh
add al,30h
t
gi
is
pop dx
pop cx
mov dl,al
mov ah,02h
int 21h
ret
display endp
ps
code ends
end start
t
gi
Result:
ps
is
HH:MM:SS.XX
ps
is
gi
Output Screen:
t
gi
is
10a.asm
ps
Decimal Up-counter
t
gi
Aim:
is
Software Used:
ps
t
gi
Theory:
ps
is
1.
2.
3.
gi
6.
7.
ps
8.
9.
10.
11.
12.
13.
14.
is
4.
5.
Algorithm:
ps
is
t
gi
Algorithm: Illustrated
ps
e
is
gi
t
gi
10a.asm ALP:
assume cs:code
mov al,30h
loop2: mov dl,al
mov ah,02h
int 21h
ps
push ax
mov bl,30h
is
start:
code segment
t
gi
mov ah,03h
int 10h
ps
mov ah,02h
mov dl,01h
int 10h
is
call delay
inc bl
t
gi
cmp bl,39h
is
mov ah,02h
mov dl,00h
int 10h
jle loop1
pop ax
inc al
cmp al,39h
jle loop2
ps
mov ah,4ch
int 21h
t
gi
e
is
delay proc
push cx
push bx
mov cx,0ffh
n3:
mov bx,0ffffh
n4:
dec bx
jnz n4
loop n3
pop bx
pop cx
ret
delay endp
ps
code ends
end start
t
gi
Procedure:
ps
is
t
gi
Result:
ps
is
ps
is
gi
Output Screen:
t
gi
is
6a.asm
ps
Strings Compare
t
gi
Aim:
is
Software Used:
ps
t
gi
Theory:
ps
is
t
gi
Algorithm:
For String comparison:
4.
is
3.
Two strings are read and stored in memory str1 & str2.
In successive loops, by comparing each character
with$ both strings lengths are counted (BL & BH).
If lengths of both are equal, then only they are
compared character by character.
Display strings equal or not along with their length.
ps
1.
2.
t
gi
6a.asm ALP:
is
;-----------displaymsg macro------
;-----------displaylen macro------
ps
gi
assume cs:code,ds:data
data segment
str1 db 20 dup(0)
str2 db 20 dup(0)
is
ps
data ends
code segment
gi
start:
mov ax,data
mov ds,ax
displaymsg msg1
is
lea si,str1
call read
displaymsg msg1
lea si,str2
call read
ps
displaymsg msg2
displaymsg str1
displaymsg msg3
displaymsg str2
gi
call check
mov ah,4ch
int 21h
int 21h
cmp al,0dh
jz last
mov [si],al
inc si
is
;-----------read procedure------begin
jmp up
last:
ps
ps
gi
e
is
;-----------check procedure------begin
ps
is
gi
next2:
displaymsg msg6
displaylen bl
;bl=lentgh of string 1
displaymsg msg7
;bh=lentgh of string 2
displaylen bh
cmp bl,bh
jnz fail
lea si,str1
lea di,str2
up2:
cmp byte ptr[si],'$'
jz final
mov al,[si]
cmp al,[di]
;if lengths are equal, compare each
characters in loop
jnz fail
;length times
inc si
inc di
jmp up2
displaymsg msg4
ret
fail:
is
check endp
displaymsg msg5
ret
;-----------check procedure------ends
ps
code ends
end start
gi
final:
t
gi
Procedure:
ps
is
t
gi
Result:
ps
is
ps
is
gi
Output Screen:
t
gi
e
is
ps
EXTRA INFO.
t
gi
ps
is
masm/tasm/fasm/nasm/goasm/hla
MOV AL, 1h ; Load AL with immediate value 1
MOV AL, 61h ; Load AL with 97 decimal (61 hex)
10110000 01100001
B0 61
ps
is
gi
BACK
ps
BACK
is
gi
ps
e
is
gi
is
gi
Binary &
Hexadecimal
Numbers
ps
BACK
gi
mov al,number1
add al,number2
mov sum,al
ps
mov ah,4ch
int 21h
code ends
end start
is
assume cs:code,ds:data
data segment
number1 db 04
number2 db 05
sum db ?
data ends
code segment
start:
mov ax,data
mov ds,ax
t
gi
EXE File
ps
is
EXE file
BACK
(Data Transfer)
is
ps
CBW
CWD
IN
LAHF
LDS
LEA
LES
LODS
MOV
MOVS
OUT
POP
POPF
PUSH
PUSHF
SAHF
STOS
XCHG
XLAT
gi
(Arithmetic/Logical)
is
ps
AAA
AAD
AAM
AAS
ADC
ADD
AND
CMC
CMP
CMPS
DAA
DAS
DEC
DIV
IDIV
MUL
IMUL
INC
gi
Cont.)
ps
;Negate
;Logical NOT
;Logical inclusive OR
;Rotate through Carry Left
;Rotate through Carry Right
;Rotate Left
;Rotate Right
;Shift Arithmetic Right
;Subtract with Borrow
;Scan memory at DI compared to AX
;Shift logical/Arithmetic Left
;Shift logical Right
;Subtract
;AND function to flags
;Translate byte to AL
;Logical Exclusive OR
is
NEG
NOT
OR
RCL
RCR
ROL
ROR
SAR
SBB
SCAS
SHL/SAL
SHR
SUB
TEST
XLAT
XOR
gi
(Control/Branch Cont.)
ps
;Call
;Clear Carry
;Clear Direction
;Clear Interrupt
;Escape (to external device)
;Halt
;Interrupt
;Interrupt on Overflow
;Interrupt Return
;Jump on Below/Not Above or Equal
;Jump on Below or Equal/Not Above
;Jump on CX Zero
;Jump on Equal/Zero
;Jump on Less/Not Greater or Equal
;Jump on Less or Equal/Not Greater
;Unconditional Jump
;Jump on Not Below/Above or Equal
;Jump on Not Below or Equal/Above
;Jump on Not Equal/Not Zero
;Jump on Not Less/Greater or Equal
is
CALL
CLC
CLD
CLI
ESC
HLT
INT
INTO
IRET
JB/JNAE
JBE/JNA
JCXZ
JE/JZ
JL/JNGE
JLE/JNG
JMP
JNB/JAE
JNBE/JA
JNE/JNZ
JNL/JGE
gi
(Control/Branch)
ps
is
JNLE/JG
JNO
JNP/JPO
JNS
JO
JP/JPE
JS
LOCK
LOOP
LOOPNZ/LOOPNE
LOOPZ/LOOPE
NOP
REP/REPNE/REPNZ
REPE/REPZ
RET
SEG
STC
STD
STI
TEST
WAIT
gi
gi
Assembler Directives
proc far|near
endp
end of procedure
page
title
.code
.data
.stack
ps
is
end label
t
gi
Memory
Memory
Memory Content
Number1
4000H
04
Number2
4001H
05
msg1
4002H
msg2
4003H
4005H
ps
is
Memory Location
Address Label
BACK
t
gi
Procedure:
ps
is
Boot up Windows XP, goto command prompt change the directory to MASM32
Invoke MS DOS editor, type the ALP, save the
program with filename.asm
Link the program to create filename.obj
Load filename.obj in CodeView
debugger(loader)
Execute the program
Observe the results
t
gi
list
CX
BX
AL
SI-1
CARRY
SI
SI+1
SI+2
SI+3
SI+4
mov cx,count
inc si
cmp al,[si]
jc down
xchg al,[si]
mov [si-1],al
;decrement counter
jnz next
loop next1
mov ah,4ch
down: dec bx
ps
int 21h
;terminate
;load count in BX
is
5>1
t
gi
list
CX BX AL SI-1
4
mov cx,count
down: dec bx
jnz next
loop next1
;decrement counter
;if not zero, go to next
;if zero, go to next1
is
;terminate
ps
mov ah,4ch
int 21h
5 1 4 2 8
SI SI+1 SI+2 SI+3 SI+4
5>1 0
1
5
1
5
5
4
4
2
2
8
8
t
gi
list
CX
SI-1
SI
SI+1
SI+2
SI+3
SI+4
;load count in BX
inc si
cmp al,[si]
jc down
xchg al,[si]
mov [si-1],al
jnz next
ps
loop next1
mov ah,4ch
int 21h
;decrement counter
down: dec bx
;terminate
is
AL
mov cx,count
next1: mov bx,cx
BX
5>1
ps
7a
11a
9a
2a
5a
4a
8a
gi
Plan sequence
is
1. 7a
2. 1a
3. 3a
4. 2a
5. 11a
6. 5a
7. 8a
8. 4a
9. 12a
10.9a
11.10a
12.6a
t
gi
4A
0A
04
10
34
65
ps
40
is
65
30
10
ADD 37 48+10+7