Swapping of lines on VGA
org 100h
.Data
str1 db 80 dup('A')
str2 db 80 dup('B')
str3 db 80 dup('C')
str4 db 80 dup('D')
str5 db 80 dup('E')
str6 db 80 dup('F')
str7 db 80 dup('G')
str8 db 80 dup('H')
str9 db 80 dup('I')
str10 db 80 dup('J')
str11 db 80 dup('K')
str12 db 80 dup('L')
str13 db 80 dup('M')
str14 db 80 dup('N')
str15 db 80 dup('O')
str16 db 80 dup('P')
str17 db 80 dup('Q')
str18 db 80 dup('R')
str19 db 80 dup('S')
str20 db 80 dup('T')
str21 db 80 dup('U')
str22 db 80 dup('V')
str23 db 80 dup('W')
str24 db 80 dup('X')
str25 db '$'
temp1 dw 80 dup(0)
temp2 dw 80 dup(0)
count1 dw 3680
count2 dw 0
.Code
mov ah,9
LEA Dx,str1
int 21h
mov SI,0
mov DI,3840
mov Bx,0
mov ax,0xB800
mov ES,Ax
mov Cx,12
u:
mov Dx,Cx
mov Cx,160
mov Bx,0
mov SI,count2
l1:
mov ax , ES:SI
mov [temp1+Bx] , ax
add Bx,1
add SI,1
loop l1
mov Cx,159
mov DI,count1
mov SI,count2
l3:
mov ax , ES:DI
mov ES:SI , ax
add DI,1
add SI,1
loop l3
mov Cx,159
mov Bx,0
mov DI,count1
l4:
mov Ax,[temp1+Bx]
mov ES:DI , ax
add Bx,1
add DI,1
loop l4
mov Cx,160
t:
DEC count1
INC count2
loop t
mov Cx,Dx
loop u
ret
ScrollingLines on screen
org 100h
.Data
s1 db 80 DUP('A')
s2 db 80 DUP('B')
s3 db 80 DUP('C')
s4 db 80 DUP('D')
s5 db 80 DUP('E')
s6 db '$'
temp dw 80 DUP(0)
.Code
mov ah,9
LEA Dx,s1
int 21h
mov Ax,0xB800
mov SI,0
mov ES,Ax
mov Cx,160
l1:
mov Ax , ES:SI
mov [temp+SI] , Ax
INC SI
Loop l1
mov SI,0
mov DI,0
mov Cx,7
re:
mov Dx,Cx
mov Bx,0
mov Cx,80
ag:
mov Ax , ES:SI+160+Bx
mov ES:SI+Bx , al
add Bx,2
Loop ag
add SI,80
mov Cx,Dx
Loop re
add SI,80
mov DI,0
mov Cx,159
l2:
mov ax,[temp+DI]
add DI,1
mov ES:SI , ax
add SI,1
loop l2
ret
Reversing data using stack
org 100h
.DAta
.Code
XOR Cx,Cx
mov ah,1
int 21h
while:
CMP al,0DH
je Next
push ax
INC Cx
int 21h
jmp while
Next:
mov ah,2
mov Dl,0DH
int 21h
mov Dl,0Ah
int 21h
top:
pop Dx
int 21h
Loop top
ret
Array Merge Sort
org 100h
.data
A dw 1,3,5,7,9
B dw 0,2,4,6,8,10
C dw 0,0,0,0,0,0,0,0,0,0
obj dw 0
.code
mov si,0
mov di,0
mov bx,0
mov cx,10
repeat:
mov ax,A+si
mov dx,B+di
cmp ax,dx
jg greater
jl less
je equal
greater:
mov C+bx,dx
add di,2
add bx,2
jmp next
less:
mov C+bx,ax
add si,2
add bx,2
jmp next
equal:
mov C+bx,ax
add bx,2
mov C+bx,dx
add bx,2
add si,2
add di,2
jmp next
next:
loop repeat
mov si,0
mov dx,0
mov cx,10
print:
mov ah,2
mov bx,C[si]
add bx,30h
mov dl,bl
int 21h
add si,2
loop print
ret
Add numbers in 8bits Registers
org 100h
.Data
A dw 4
B dw 5
C dw 6
D dw 7
.Code
mov Ax,A
mov Bx,B
mov Cx,C
mov Dx,D
add Ax,A
add Ax,A
add Ax,A
add Bx,B
add Bx,B
add Bx,B
add Bx,B
add Cx,C
add Cx,C
add Cx,C
add Cx,C
add Cx,C
add Dx,D
add Dx,D
add Dx,D
add Dx,D
add Dx,D
add Dx,D
add Ax,Bx
sub Ax,Cx
sub Ax,Dx
ret
Sum of 16bit numbers
org 100h
.Data
sum dw 0
output db 'Sum is : $'
ask1 db 'Enter First Number : $'
ask2 db 'Enter Second Number : $'
.Code
mov ah,9
LEA Dx,ask1
int 21h
xor bx,bx
mov ah,1
int 21h
loo:
CMP al,0dh
je second
CMP al,39h
jge letter
and al,0fh
jmp shift
letter:
sub al,37h
shift:
shl bx,4
or bl,al
int 21h
jmp loo
second:
mov ah,2
mov dx,0dh
int 21h
mov dx,0ah
int 21h
mov ah,9
LEA Dx,ask2
int 21h
xor cx,cx
mov ah,1
int 21h
lo:
CMP al,0dh
je ad
CMP al,39h
jge leter
and al,0fh
jmp shft
leter:
sub al,37h
shft:
shl cx,4
or cl,al
int 21h
jmp lo
ad:
add bx,cx
mov sum,bx
add sum,30h
mov ah,2
mov dx,0dh
int 21h
mov dx,0ah
int 21h
mov ah,9
LEA Dx,output
int 21h
mov ah,2
mov Dx,sum
int 21h
ret
Inverting Bits
org 100h
.Data
.Code
mov al,0xBA
mov ah,al
shl ah,1
and ah,0xCA
mov dl,al
shr dl,1
and dl,0x55
or ah,dl
ret
Printing Right Angled Triangle
org 100h
.Data
N dw 5
M dw 1
.Code
mov Cx,5
l2:
mov Bx,Cx
mov Cx,N
l1:
mov ah,2
mov dl,' '
int 21h
loop l1
mov Cx,M
l3:
mov dl,'*'
int 21h
loop l3
INC M
mov dl,0DH
int 21h
mov dl,0AH
int 21h
DEC N
mov Cx,Bx
loop l2
ret
Reverse String
org 100h
.Data
Str db 'abcdef$'
.Code
mov ah,9
LEA Dx,str
int 21h
mov ah,2
mov dl,0DH
int 21h
mov dl,0AH
int 21h
mov ah,9
mov bl,str
mov bh,str+5
mov str+5,bl
mov str,bh
mov bl,str+1
mov bh,str+4
mov str+4,bl
mov str+1,bh
mov bl,str+2
mov bh,str+3
mov str+3,bl
mov str+2,bh
LEA Dx,str
int 21h
ret
GradeMarks using JUMP conditions
org 100h
.Data
Str1 db 'Your Grade is A$'
Str2 db 'Your Grade is B$'
Str3 db 'Your Grade is C$'
Str4 db 'Your Grade is D$'
Str5 db 'Your Grade is E$'
Str7 db 'Your Grade is F$'
Str6 db 'Wrong Input$'
A dd 96
B dw 80
C dw 70
D dw 60
E dw 50
F dw 40
.Code
mov Bx,A
CMP Bx,90
jge l1
mov Bx,B
CMP Bx,80
je l2
mov Bx,C
CMP Bx,70
je l3
mov Bx,D
CMP Bx,60
je l4
mov Bx,E
CMP Bx,50
je l5
mov Bx,F
CMP Bx,50
jl l6
mov ah,9
LEA Dx,Str6
int 21h
jmp exit
l1:
mov ah,9
LEA Dx,Str1
int 21h
mov ah,2
mov dl,0DH
int 21h
mov dl,0AH
int 21h
l2:
mov ah,9
LEA Dx,Str2
int 21h
mov ah,2
mov dl,0DH
int 21h
mov dl,0AH
int 21h
l3:
mov ah,9
LEA Dx,Str3
int 21h
mov ah,2
mov dl,0DH
int 21h
mov dl,0AH
int 21h
l4:
mov ah,9
LEA Dx,Str4
int 21h
mov ah,2
mov dl,0DH
int 21h
mov dl,0AH
int 21h
l5:
mov ah,9
LEA Dx,Str5
int 21h
mov ah,2
mov dl,0DH
int 21h
mov dl,0AH
int 21h
l6:
mov ah,9
LEA Dx,Str7
int 21h
mov ah,2
mov dl,0DH
int 21h
mov dl,0AH
int 21h
exit:
ret
Get Three Characters & Print Design
org 100h
.Data
str1 dw '***********$'
str2 dw '* *$'
str3 dw '****$'
str4 dw 'Enter Three Characters : $'
x db ?
y db ?
z db ?
.Code
mov ah,9
LEA dx,str4
int 21h
mov ah,1
int 21h
mov x,al
int 21h
mov y,al
int 21h
mov z,al
mov ah,2
mov dl,0DH
int 21h
mov dl,0AH
int 21h
mov ah,9
LEA Dx,str1
int 21h
mov ah,2
mov Dl,0DH
int 21h
mov dl,0AH
int 21h
mov Cx,4
Label1:
mov ah,9
LEA Dx,str2
int 21h
mov ah,2
mov Dl,0DH
int 21h
mov dl,0AH
int 21h
Loop Label1
mov ah,9
LEA Dx,str3
int 21h
mov ah,2
mov dl,x
int 21h
mov ah,2
mov dl,y
int 21h
mov dl,z
int 21h
mov ah,9
LEA Dx,str3
int 21h
mov Cx,4
Label2:
mov ah,2
mov dl,0DH
int 21h
mov dl,0AH
int 21h
mov ah,9
LEA Dx,str2
int 21h
Loop Label2
mov ah,2
mov dl,0DH
int 21h
mov dl,0AH
int 21h
mov ah,9
LEA Dx,str1
int 21h
ret
Using XOR operator
org 100h
.Data
A dd 0x1234
B dd 0xABCD
.Code
mov Ax,A
XOR Ax,0x1234
mov Bx,Ax
mov Ax,A
XOR Ax,0xABCD
mov Cx,Ax
mov Ax,A
XOR Ax,0xABC4
mov Dx,Ax
ret
Using OR operator
org 100h
.Data
A dd 0x1234
B dd 0xABCD
.Code
mov Ax,A
OR Ax,0x1234
mov Bx,Ax
mov Ax,A
OR Ax,0xABCD
mov Cx,Ax
mov Ax,A
OR Ax,0xABC4
mov Dx,Ax
ret
Using NOT operator
org 100h
.Data
A dd 0x01010202
.Code
mov Ax,A
mov Bx,A+2
NOT Ax
NOT Bx
mov Cx,Ax
mov Dx,Bx
ret
Hexadecimal Addition & Subtraction
org 100h
.Data
A dd 0x12345678
B dd 0xABCD9875
C dd 0x?
.Code
mov Ax,A
mov Bx,B
add Ax,Bx
mov Cx,Ax
mov Ax,A+2
mov Bx,B+2
adc Ax,Bx
adc Cx,Ax
mov Ax,A
mov Bx,B
sbb Ax,Bx
mov Dx,Ax
mov Ax,A+2
mov Bx,B+2
sbb Ax,Bx
mov Dx,Ax
ret
Using AND operator
org 100h
.Data
A dd 0x1234
B dd 0xABCD
.Code
mov Ax,A
AND Ax,0x1234
mov Bx,Ax
mov Ax,A
AND Ax,0xABCD
mov Cx,Ax
ret
Solve Equation 4a+5b-6c-7d without using MUL
org 100h
.Data
A dw 4
B dw 5
C dw 6
D dw 7
.Code
mov Ax,A
mov Bx,B
mov Cx,C
mov Dx,D
add Ax,A
add Ax,A
add Ax,A
add Bx,B
add Bx,B
add Bx,B
add Bx,B
add Cx,C
add Cx,C
add Cx,C
add Cx,C
add Cx,C
add Dx,D
add Dx,D
add Dx,D
add Dx,D
add Dx,D
add Dx,D
add Ax,Bx
sub Ax,Cx
sub Ax,Dx
ret
org 100h
.Data
str1 db 80 dup('A')
str2 db 80 dup('B')
str3 db 80 dup('C')
str4 db 80 dup('D')
str5 db 80 dup('E')
str6 db 80 dup('F')
str7 db 80 dup('G')
str8 db 80 dup('H')
str9 db 80 dup('I')
str10 db 80 dup('J')
str11 db 80 dup('K')
str12 db 80 dup('L')
str13 db 80 dup('M')
str14 db 80 dup('N')
str15 db 80 dup('O')
str16 db 80 dup('P')
str17 db 80 dup('Q')
str18 db 80 dup('R')
str19 db 80 dup('S')
str20 db 80 dup('T')
str21 db 80 dup('U')
str22 db 80 dup('V')
str23 db 80 dup('W')
str24 db 80 dup('X')
str25 db '$'
temp1 dw 80 dup(0)
temp2 dw 80 dup(0)
count1 dw 3680
count2 dw 0
.Code
mov ah,9
LEA Dx,str1
int 21h
mov SI,0
mov DI,3840
mov Bx,0
mov ax,0xB800
mov ES,Ax
mov Cx,12
u:
mov Dx,Cx
mov Cx,160
mov Bx,0
mov SI,count2
l1:
mov ax , ES:SI
mov [temp1+Bx] , ax
add Bx,1
add SI,1
loop l1
mov Cx,159
mov DI,count1
mov SI,count2
l3:
mov ax , ES:DI
mov ES:SI , ax
add DI,1
add SI,1
loop l3
mov Cx,159
mov Bx,0
mov DI,count1
l4:
mov Ax,[temp1+Bx]
mov ES:DI , ax
add Bx,1
add DI,1
loop l4
mov Cx,160
t:
DEC count1
INC count2
loop t
mov Cx,Dx
loop u
ret
ScrollingLines on screen
org 100h
.Data
s1 db 80 DUP('A')
s2 db 80 DUP('B')
s3 db 80 DUP('C')
s4 db 80 DUP('D')
s5 db 80 DUP('E')
s6 db '$'
temp dw 80 DUP(0)
.Code
mov ah,9
LEA Dx,s1
int 21h
mov Ax,0xB800
mov SI,0
mov ES,Ax
mov Cx,160
l1:
mov Ax , ES:SI
mov [temp+SI] , Ax
INC SI
Loop l1
mov SI,0
mov DI,0
mov Cx,7
re:
mov Dx,Cx
mov Bx,0
mov Cx,80
ag:
mov Ax , ES:SI+160+Bx
mov ES:SI+Bx , al
add Bx,2
Loop ag
add SI,80
mov Cx,Dx
Loop re
add SI,80
mov DI,0
mov Cx,159
l2:
mov ax,[temp+DI]
add DI,1
mov ES:SI , ax
add SI,1
loop l2
ret
Reversing data using stack
org 100h
.DAta
.Code
XOR Cx,Cx
mov ah,1
int 21h
while:
CMP al,0DH
je Next
push ax
INC Cx
int 21h
jmp while
Next:
mov ah,2
mov Dl,0DH
int 21h
mov Dl,0Ah
int 21h
top:
pop Dx
int 21h
Loop top
ret
Array Merge Sort
org 100h
.data
A dw 1,3,5,7,9
B dw 0,2,4,6,8,10
C dw 0,0,0,0,0,0,0,0,0,0
obj dw 0
.code
mov si,0
mov di,0
mov bx,0
mov cx,10
repeat:
mov ax,A+si
mov dx,B+di
cmp ax,dx
jg greater
jl less
je equal
greater:
mov C+bx,dx
add di,2
add bx,2
jmp next
less:
mov C+bx,ax
add si,2
add bx,2
jmp next
equal:
mov C+bx,ax
add bx,2
mov C+bx,dx
add bx,2
add si,2
add di,2
jmp next
next:
loop repeat
mov si,0
mov dx,0
mov cx,10
print:
mov ah,2
mov bx,C[si]
add bx,30h
mov dl,bl
int 21h
add si,2
loop print
ret
Add numbers in 8bits Registers
org 100h
.Data
A dw 4
B dw 5
C dw 6
D dw 7
.Code
mov Ax,A
mov Bx,B
mov Cx,C
mov Dx,D
add Ax,A
add Ax,A
add Ax,A
add Bx,B
add Bx,B
add Bx,B
add Bx,B
add Cx,C
add Cx,C
add Cx,C
add Cx,C
add Cx,C
add Dx,D
add Dx,D
add Dx,D
add Dx,D
add Dx,D
add Dx,D
add Ax,Bx
sub Ax,Cx
sub Ax,Dx
ret
Sum of 16bit numbers
org 100h
.Data
sum dw 0
output db 'Sum is : $'
ask1 db 'Enter First Number : $'
ask2 db 'Enter Second Number : $'
.Code
mov ah,9
LEA Dx,ask1
int 21h
xor bx,bx
mov ah,1
int 21h
loo:
CMP al,0dh
je second
CMP al,39h
jge letter
and al,0fh
jmp shift
letter:
sub al,37h
shift:
shl bx,4
or bl,al
int 21h
jmp loo
second:
mov ah,2
mov dx,0dh
int 21h
mov dx,0ah
int 21h
mov ah,9
LEA Dx,ask2
int 21h
xor cx,cx
mov ah,1
int 21h
lo:
CMP al,0dh
je ad
CMP al,39h
jge leter
and al,0fh
jmp shft
leter:
sub al,37h
shft:
shl cx,4
or cl,al
int 21h
jmp lo
ad:
add bx,cx
mov sum,bx
add sum,30h
mov ah,2
mov dx,0dh
int 21h
mov dx,0ah
int 21h
mov ah,9
LEA Dx,output
int 21h
mov ah,2
mov Dx,sum
int 21h
ret
Inverting Bits
org 100h
.Data
.Code
mov al,0xBA
mov ah,al
shl ah,1
and ah,0xCA
mov dl,al
shr dl,1
and dl,0x55
or ah,dl
ret
Printing Right Angled Triangle
org 100h
.Data
N dw 5
M dw 1
.Code
mov Cx,5
l2:
mov Bx,Cx
mov Cx,N
l1:
mov ah,2
mov dl,' '
int 21h
loop l1
mov Cx,M
l3:
mov dl,'*'
int 21h
loop l3
INC M
mov dl,0DH
int 21h
mov dl,0AH
int 21h
DEC N
mov Cx,Bx
loop l2
ret
Reverse String
org 100h
.Data
Str db 'abcdef$'
.Code
mov ah,9
LEA Dx,str
int 21h
mov ah,2
mov dl,0DH
int 21h
mov dl,0AH
int 21h
mov ah,9
mov bl,str
mov bh,str+5
mov str+5,bl
mov str,bh
mov bl,str+1
mov bh,str+4
mov str+4,bl
mov str+1,bh
mov bl,str+2
mov bh,str+3
mov str+3,bl
mov str+2,bh
LEA Dx,str
int 21h
ret
GradeMarks using JUMP conditions
org 100h
.Data
Str1 db 'Your Grade is A$'
Str2 db 'Your Grade is B$'
Str3 db 'Your Grade is C$'
Str4 db 'Your Grade is D$'
Str5 db 'Your Grade is E$'
Str7 db 'Your Grade is F$'
Str6 db 'Wrong Input$'
A dd 96
B dw 80
C dw 70
D dw 60
E dw 50
F dw 40
.Code
mov Bx,A
CMP Bx,90
jge l1
mov Bx,B
CMP Bx,80
je l2
mov Bx,C
CMP Bx,70
je l3
mov Bx,D
CMP Bx,60
je l4
mov Bx,E
CMP Bx,50
je l5
mov Bx,F
CMP Bx,50
jl l6
mov ah,9
LEA Dx,Str6
int 21h
jmp exit
l1:
mov ah,9
LEA Dx,Str1
int 21h
mov ah,2
mov dl,0DH
int 21h
mov dl,0AH
int 21h
l2:
mov ah,9
LEA Dx,Str2
int 21h
mov ah,2
mov dl,0DH
int 21h
mov dl,0AH
int 21h
l3:
mov ah,9
LEA Dx,Str3
int 21h
mov ah,2
mov dl,0DH
int 21h
mov dl,0AH
int 21h
l4:
mov ah,9
LEA Dx,Str4
int 21h
mov ah,2
mov dl,0DH
int 21h
mov dl,0AH
int 21h
l5:
mov ah,9
LEA Dx,Str5
int 21h
mov ah,2
mov dl,0DH
int 21h
mov dl,0AH
int 21h
l6:
mov ah,9
LEA Dx,Str7
int 21h
mov ah,2
mov dl,0DH
int 21h
mov dl,0AH
int 21h
exit:
ret
Get Three Characters & Print Design
org 100h
.Data
str1 dw '***********$'
str2 dw '* *$'
str3 dw '****$'
str4 dw 'Enter Three Characters : $'
x db ?
y db ?
z db ?
.Code
mov ah,9
LEA dx,str4
int 21h
mov ah,1
int 21h
mov x,al
int 21h
mov y,al
int 21h
mov z,al
mov ah,2
mov dl,0DH
int 21h
mov dl,0AH
int 21h
mov ah,9
LEA Dx,str1
int 21h
mov ah,2
mov Dl,0DH
int 21h
mov dl,0AH
int 21h
mov Cx,4
Label1:
mov ah,9
LEA Dx,str2
int 21h
mov ah,2
mov Dl,0DH
int 21h
mov dl,0AH
int 21h
Loop Label1
mov ah,9
LEA Dx,str3
int 21h
mov ah,2
mov dl,x
int 21h
mov ah,2
mov dl,y
int 21h
mov dl,z
int 21h
mov ah,9
LEA Dx,str3
int 21h
mov Cx,4
Label2:
mov ah,2
mov dl,0DH
int 21h
mov dl,0AH
int 21h
mov ah,9
LEA Dx,str2
int 21h
Loop Label2
mov ah,2
mov dl,0DH
int 21h
mov dl,0AH
int 21h
mov ah,9
LEA Dx,str1
int 21h
ret
Using XOR operator
org 100h
.Data
A dd 0x1234
B dd 0xABCD
.Code
mov Ax,A
XOR Ax,0x1234
mov Bx,Ax
mov Ax,A
XOR Ax,0xABCD
mov Cx,Ax
mov Ax,A
XOR Ax,0xABC4
mov Dx,Ax
ret
Using OR operator
org 100h
.Data
A dd 0x1234
B dd 0xABCD
.Code
mov Ax,A
OR Ax,0x1234
mov Bx,Ax
mov Ax,A
OR Ax,0xABCD
mov Cx,Ax
mov Ax,A
OR Ax,0xABC4
mov Dx,Ax
ret
Using NOT operator
org 100h
.Data
A dd 0x01010202
.Code
mov Ax,A
mov Bx,A+2
NOT Ax
NOT Bx
mov Cx,Ax
mov Dx,Bx
ret
Hexadecimal Addition & Subtraction
org 100h
.Data
A dd 0x12345678
B dd 0xABCD9875
C dd 0x?
.Code
mov Ax,A
mov Bx,B
add Ax,Bx
mov Cx,Ax
mov Ax,A+2
mov Bx,B+2
adc Ax,Bx
adc Cx,Ax
mov Ax,A
mov Bx,B
sbb Ax,Bx
mov Dx,Ax
mov Ax,A+2
mov Bx,B+2
sbb Ax,Bx
mov Dx,Ax
ret
org 100h
.Data
A dd 0x1234
B dd 0xABCD
.Code
mov Ax,A
AND Ax,0x1234
mov Bx,Ax
mov Ax,A
AND Ax,0xABCD
mov Cx,Ax
ret
Solve Equation 4a+5b-6c-7d without using MUL
org 100h
.Data
A dw 4
B dw 5
C dw 6
D dw 7
.Code
mov Ax,A
mov Bx,B
mov Cx,C
mov Dx,D
add Ax,A
add Ax,A
add Ax,A
add Bx,B
add Bx,B
add Bx,B
add Bx,B
add Cx,C
add Cx,C
add Cx,C
add Cx,C
add Cx,C
add Dx,D
add Dx,D
add Dx,D
add Dx,D
add Dx,D
add Dx,D
add Ax,Bx
sub Ax,Cx
sub Ax,Dx
ret
can you make one for merge and insertion sort as well?
ReplyDelete