Sei sulla pagina 1di 26

COAL Program’s Theory

Prof. Adnan sahb


Program 1
org 100h

.model small
.data
.code

mov cx,5
l1:
mov dx,"//"
mov ah,02
int 21h
output: /***/***/***/***/***
mov bx,cx
mov cx,3
l2:
mov dl,"*"
mov ah,02
int 21h
loop l2

mov cx,bx
loop l1

ret
Program 1
The value of cx is 5 but the instruction of loop
l1 execute for once and then value of cx mov in
bx. At that point we provide new value to cx is 3
the instruction of l2 execute for three time
mean steric(*) print. At last the bx mov in cx and
going on loop l1 for rexecute.
Note: Remember that the value of cx do not
decrease at every iteration
Program 2
org 100h

.model small
.data
.code
Output: inc 16, dec 15
mov ax,15h
inc ax
dec ax

ret
Program 2
inc: its instruction use to add 1 in constant
register or memory location.
dec: its instruction use to sub 1 from constant
register or memory location.
Program 3
org 100h

.model small
.data
.code

mov bl,48
k: output: sahiwal 8
mov ah,01
int 21h
inc bl
cmp al,20h
je b
loop k
b:
mov dl,bl
mov ah,02
int 21h

ret
Program 3
1. 48 is the ascii code of ‘0’
2. 20h is the ascii code of space
3. Input store in al register
48 is the ascii code of zero(0) store in bl.
After increment in bl the 20h compare to al. if
input is equal to space then the control move on
b: (label), if not equal then control move on
loop k.
Program 4
org 100h

.model small
.data
.code

mov ax,12h
mov bx,13h
cmp ax,bx

ret

/*it is just syntax of cmp instruction*/


Program 4
syntax: cmp destination, source

Cmp result ZF CF
Destination<source 0 1

Destination>source 0 0

Destination=source 1 0
Program 5
org 100h

.model small
.data
var1 db "both operand equal",'$'
var2 db "both operands not equal",'$'
.code
main proc
call hello
output: both operand equal
ret
endp

hello proc
mov al,12
mov bl,12
cmp al,bl
je h

lea dx,var2
mov ah,09
int 21h
jmp exist

h:
lea dx,var1
mov ah,09
int 21h
exist:

ret
endp
Program 5
var1 db and var2 db are two variable declare in
.data directive
in coding,
cmp al to bl which are equal in given
program mean jmp equal and control move on
h: and execute instructions of var1.
if the operand not equal then execute var2.
Jmp exist is used to exit control
Program 6
org 100h

.model small
.data
k db "jump carry",'$'
k2 db "jump not carry",'$'
.code
main proc
call hello

ret

endp output: jump not carry


hello proc
mov ax,34h
mov bx,56h
cmp ax,bx
je j

lea dx,k2
mov ah,09
int 21h
jmp f

j:
lea dx,k
mov ah,09
int 21h
f:

ret
endp
Program 7
org 100h

.model small
.data
.code

main proc

mov cx,5
call hello

ret
endp

hello proc
l0:
mov ah,01
int 21h

mov bl,al
sub bl,32

mov dl,bl
mov ah,02
int 21h
mov dl,,0ah
mov ah,02
int 21h

mov dl,0dh
mov ah,02
int 21h
loop l0

ret
endp
end main

output:
aA
bB
cC
dD
eE
Program 7
The logic is that the difference between small
alphabetic and large is of 32. so by subtracting 2
we can print large(capital) letter.
Let
a= 97 (97 ascii code of a)
A=65 (65 ascii code of A)
97-65=32
And we use loop for more than one letters.
Program 8
org 100h

.model small
.data
var1 db "ax is greater than bx",'$'
var2 db "bx is greater than ax",'$'
.code

main proc
call hello

ret
endp
hello proc
mov ax,13h
mov bx,12h
cmp ax,bx
je b

lea dx,var2
mov ah,09
int 21h

jmp exist
b:
lea dx,var1
mov ah,09
int 21h

exist:
ret
endp
end main
Output:
bx is greater than ax
Program 8
JA = jmp above (operand1>operand)
JNA =jmp not above (reverse)
JB= jmp below (operand1<operand)
JNB=jmp not below (reverse)
JAE=jmp above equal (opearnd1>= 2)
JBE=jmp below equal (operand1< 2)
We store two operands in ax and bx. After cmp,
in given program ax is greater than bx therefore
the control move on var2 and execute it. If bx is
greater than ax the control move on lable b: and
execute var1.
Program 9
org 100h

.model small
.stack 100h
.data
.code
main proc

mov cx,0
call hello

ret
endp

hello proc

j:
mov ah,01
int 21h

mov bl,al
inc cx

cmp bl,0Dh
je rev

push bx
jmp j
rev:
mov dl,0Ah
mov ah,02
int 21h

l:
pop dx
mov ah,02
int 21h
loop l

ret
endp
end main

Output:
Shafqat
taqfahs
Program 9
At first in cx mov 0 when user input any word
(let a) store in al. And then al cmp to 0Dh(ascii
code of enter). If user press enter(if equal) then
jmp go on rev: , if not equal then push bx (mean
input which is in bx) again and again till the user
press ‘enter key’.
And pop instruction execute when user give 1
input again execute when input other.
Program 10
org 100h

.model small
.data
arr1 db '1','2','3','4'
.code

main proc

call hello

ret
endp

hello proc

mov ax,@data
mov ds,ax

mov si,offset arr1


mov cx,4
l1:
mov dx,[si]
mov ah,02
int 21h

inc si
loop l1

mov ah,4ch
int 21h
ret
endp
end main

Output
1234
Program 10
Array: collection of characters in sequence. Array is
defined in .data directive of program as variable.
arr1 db 1,2,3,4
Si: source index register use as pointer to access an array.
DUP(duplicate)
DUP: it provide facility to store the large number data in
easy way.
In general way,
arr1 db ‘a’, ‘a’, ‘a’,’a’
In DUP
arr db 4 DUP(‘a’)
1,2,3,4 store in array of 8 bit and then data of
array store in ax, offset value mean 1st value of
array store in Si (is a pointer) and print Si by
using loop. Loop iterate for four time and print
1,2,3,4 by increasing [Si].

Potrebbero piacerti anche