Showing posts with label Assembly Language. Show all posts
Showing posts with label Assembly Language. Show all posts

Saturday, June 13, 2015

Scan string using SCASB : Assembly code

include irvine32.inc

.data
source byte "my name is usman",0

msg1 byte "String to b compare : ",0


msg3 byte "Latter is Found : ",0
msg4 byte "Latter Not Found : ",0

.code
Main proc
call clrscr
call crlf
mov edx,offset msg1
call writestring
call crlf

call crlf
mov edx,offset source
call writestring
call crlf


;---------------------------

mov edi,offset source
mov al,'g'
mov ecx,lengthof source
cld
repne scasb
je L1
jne L2
;----------------------

L1:
call crlf
mov edx,offset msg3
call writestring
call crlf
jmp e

L2:
call crlf
mov edx,offset msg4
call writestring
call crlf
jmp e


e:
exit
main endp
end main

Compare string using CMPSB : Assembly Code

include irvine32.inc

.data
source byte "i my name is usman",0
dest   byte "i am not a khan....",0

msg1 byte "1st String: ",0
msg2 byte "2nd string: ",0

msg3 byte "String name Dest is Large : ",0
msg4 byte "String name Dest is Small : ",0
msg5 byte "String :both sorce & Dest are Equal : ",0

.code
Main proc
call clrscr
call crlf
mov edx,offset msg1
call writestring
call crlf

call crlf
mov edx,offset source
call writestring
call crlf

call crlf
mov edx,offset msg2
call writestring
call crlf

call crlf
mov edx,offset dest
call writestring
call crlf

mov esi,offset source
mov edi,offset dest
mov ecx,lengthof source
repe cmpsb
ja L1
jb L2
jmp L3

L1:
call crlf
mov edx,offset msg3
call writestring
call crlf
jmp e

L2:
call crlf
mov edx,offset msg4
call writestring
call crlf
jmp e

L3:
call crlf
mov edx,offset msg5
call writestring
call crlf
jmp e

e:
exit
main endp
end main


Copy using Movsb : Assembly Code

include irvine32.inc

.data
source byte "    my name is usman",0
dest   byte "    I am not a khan.",0
msg3 byte "After Copy: Copy source in dest String:  ",0
msg1 byte "String Named Source: ",0
msg2 byte "String Named Dest: ",0

.code
Main proc
call clrscr
call crlf
mov edx,offset msg1
call writestring
call crlf

call crlf
mov edx,offset source
call writestring
call crlf

call crlf
mov edx,offset msg2
call writestring
call crlf

call crlf
mov edx,offset dest
call writestring
call crlf
;-------------------------------
cld
mov esi,offset source
mov edi,offset dest
mov ecx,lengthof dest
rep movsb
;--------------------------------
call crlf
call crlf
mov edx,offset msg3
call writestring
call crlf

call crlf
mov edx,offset source
call writestring
call crlf

call crlf
mov edx,offset msg2
call writestring
call crlf

call crlf
mov edx,offset dest
call writestring
call crlf

exit
main endp
end main

Push & Pop in Assembly :: Stack

include irvine32.inc

.data

msg3 byte "Push character one by one in stack and moves ESP(32-bit-stack-pointer-register) downward:",0
msg byte "              Push: ",0
msg4 byte "Pop character one by one from stack and moves ESP(32-bit-stack-pointer-register) upward:",0
msg1 byte "              Pop: ",0
arr byte "usman siddique",0
asiz = ($-arr)-1
msg2 byte "---------------------------------------------------------------",0
msg5 byte "After perfoming the pop operation the name will print in reverse order.Now think about it, why it happens",0
msg6 byte "                      Name:  ",0
msg7 byte ".......................~~THE END~~.............................",0

.code
main proc
call clrscr
mov edx,offset msg3
call writestring
call crlf
mov ecx,asiz
mov esi,0

L1:
mov edx,offset msg
call writestring
movzx eax,arr[esi]
push eax ;PUSH:  In runtime stack ESP moves in downward direction instead of moving upward
                            ;but it does not matter what the  direction is,because stack follows LIFO structure in both(downward/upward) cases.
call writechar
call delay
call delay
call delay
call delay
call crlf
inc esi
loop L1

call crlf
mov edx,offset msg2
call writestring
call crlf
mov edx,offset msg4
call writestring
call crlf
mov ecx,asiz
mov esi,0
L2:
mov edx,offset msg1
call writestring
pop eax        ;POP:   In runtime stack ESP moves in upward direction instead of moving downward
                            ;but it does not matter what the direction is,because stack follows LIFO structure in both(downward/upward) cases.
mov arr[esi],al
call delay
call delay
call delay
call delay

call writechar
call crlf
inc esi
loop L2
call crlf
mov edx,offset msg5
call writestring
call crlf
call crlf
call crlf
call waitmsg ;show a msg: Press [Enter] to continue..
mov edx,offset msg6
call writestring
mov edx,offset arr
call writestring
call crlf
call crlf
call crlf
mov edx,offset msg7
call writestring
call crlf
call crlf
exit
main endp
end main

Str_Trim Function in Assembly

include irvine32.inc

.data
source byte "my name is usman and i am not A KHAN",0
msg   byte "After Invoking Str_trim function: ",0
msg1 byte "Lenght of source = ",0

.code
Main proc
call clrscr
call crlf
mov edx,offset msg1
call writestring
call crlf

call crlf
mov edx,offset source
call writestring
call crlf


call crlf
mov edx,offset msg
call writestring
call crlf


invoke str_trim , addr source , 'N'


call crlf
mov edx,offset source
call writestring

call crlf

exit
main endp
end main


Str_Length Function in Assembly

include irvine32.inc

.data
source byte "my name is usman and i am not A KHAN",0
msg   byte "After Iviking Str_Length function: ",0
msg1 byte "Lenght of source = ",0

.code
Main proc
call clrscr
call crlf
mov edx,offset msg1
call writestring
call crlf

call crlf
mov edx,offset source
call writestring
call crlf


call crlf
mov edx,offset msg
call writestring
call crlf


invoke str_length , addr source


call crlf
mov edx,offset msg1
call writestring
call writedec
call crlf

exit
main endp
end main

U_Case Function in Assembly

include irvine32.inc

.data
source byte "my name is usman and i am not A KHAN",0
msg   byte "After Iviking U-Case function: ",0
msg1 byte "String Source is = ",0

.code
Main proc
call clrscr
call crlf
mov edx,offset msg1
call writestring
call crlf

call crlf
mov edx,offset source
call writestring
call crlf


call crlf
mov edx,offset msg
call writestring
call crlf


invoke str_ucase , addr source


call crlf
mov edx,offset source
call writestring
call crlf

exit
main endp
end main

Str_Compare Function in Assembly

include irvine32.inc

.data
source byte "i  my name is usman",0
dest   byte "i am not a khan....",0

msg1 byte "1st String: ",0
msg2 byte "2nd string: ",0

msg3 byte "String name Dest is Large : ",0
msg4 byte "String name Dest is Small : ",0
msg5 byte "String :both sorce & Dest are Equal : ",0

.code
Main proc
call clrscr
call crlf
mov edx,offset msg1
call writestring
call crlf

call crlf
mov edx,offset source
call writestring
call crlf

call crlf
mov edx,offset msg2
call writestring
call crlf

call crlf
mov edx,offset dest
call writestring
call crlf

invoke str_compare , addr source ,addr dest
ja L1
jb L2
jmp L3

L1:
call crlf
mov edx,offset msg3
call writestring
call crlf
jmp e

L2:
call crlf
mov edx,offset msg4
call writestring
call crlf
jmp e

L3:
call crlf
mov edx,offset msg5
call writestring
call crlf
jmp e

e:
exit
main endp
end main

Str_Copy Function in Assembly

include irvine32.inc

.data
source byte "my name is usman",0
dest   byte "i am not a khan.",0

msg1 byte "1st String: ",0
msg2 byte "2nd string: ",0
msg3 byte "after Copy :: copy source string into dest : ",0

.code
Main proc
call clrscr
call crlf
mov edx,offset msg1
call writestring
call crlf

call crlf
mov edx,offset source
call writestring
call crlf

call crlf
mov edx,offset msg2
call writestring
call crlf

call crlf
mov edx,offset dest
call writestring
call crlf

call crlf
mov edx,offset msg3
call writestring
call crlf

invoke str_copy , addr source ,addr dest
;copy source string into dest

call crlf
mov edx,offset dest
call writestring
call crlf

exit
main endp
end main


Friday, May 22, 2015

Shift And Rotate Instructions in Assembly Language

Shift And Rotate Instructions in Assembly Language ...

Code by Programming SeekerzZZZ...
Using Commands SHL ,SHR ,SAL ,SAR ,ROR ,ROL ,RCR ,RCL




include irvine32.inc
.data
msg byte  "  Actual No is:                             ",0
msg1 byte " No After 2 Arthmatic Right Shift (SAR):    ",0,13h,10h
msg2 byte " No After 2 Arthmatic Left Shift  (SAL):    ",0

msg3 byte " No After 2 Logical Left Shift:  (SHL)      ",0
msg4 byte " No After 2 Logical Right Shift: (SHR)      ",0

msg5 byte " No After 2 Left Rotations:  (ROL)          ",0
msg6 byte " No After 2 Right Rotations: (ROR)          ",0

msg7 byte " No After 2 Left RCL  (Rotate Carry Left):  ",0
msg8 byte " No After 2 Right RCR (Rotate Carry Right): ",0


num byte 11110001b

.code
main proc
call clrscr
call crlf

;------------------SAR---------------
mov edx,offset msg
call writestring
call crlf
mov al,num
call writebin
SAR al,2
call crlf

mov edx,offset msg1
call writestring
call crlf
call writebin
call crlf
;------------------SAL----------------
call crlf
mov edx,offset msg
call writestring
call crlf
mov al,num
call writebin
SAL al,2
call crlf

mov edx,offset msg2
call writestring
call crlf
call writebin
call crlf
;---------------ROL-----------------
call crlf
mov edx,offset msg
call writestring
call crlf
mov al,num
call writebin
ROL al,2
call crlf

mov edx,offset msg5
call writestring
call crlf
call writebin
call crlf
;-----------------ROR---------------
call crlf
mov edx,offset msg
call writestring
call crlf
mov al,num
call writebin
ROR al,2
call crlf

mov edx,offset msg6
call writestring
call crlf
call writebin
call crlf
;-----------SHR------------------
call crlf
mov edx,offset msg
call writestring
call crlf
mov al,num
call writebin
SHR al,2
call crlf

mov edx,offset msg4
call writestring
call crlf
call writebin
call crlf
;------------SHL------------------
call crlf
mov edx,offset msg
call writestring
call crlf
mov al,num
call writebin
SHL al,2
call crlf

mov edx,offset msg3
call writestring
call crlf
call writebin
call crlf
;----------------RCR----------------
call crlf
mov edx,offset msg
call writestring
call crlf
mov al,num
call writebin
RCR al,2
call crlf

mov edx,offset msg8
call writestring
call crlf
call writebin
call crlf
;-----------------RCL----------------
call crlf
mov edx,offset msg
call writestring
call crlf
mov al,num
call writebin
RCL al,2
call crlf

mov edx,offset msg7
call writestring
call crlf
call writebin
call crlf


exit
main endp
end main


Sunday, May 17, 2015

Merge Sorting in Assembly Language

This Program Take 2 Sorted Array merge them so that the final array will also be sorted ..Assembly Program by Programming Seekerz

include irvine32.inc

.data
arr1 byte 10 DUP(?)
arr2 byte 10 DUP(?)
arr3 byte 20 DUP(?)
len1 dword ?
len2 dword ?
len3 dword ?
msg1 byte " Enter 10 Numbers in Array 1: ",0
msg2 byte " Enter 10 numbers in Array 2: ",0
msg3 byte " After Soritng:  ",0
msg4 byte "     ",0

.code
Main Proc
call clrscr
call crlf
mov edx,offset msg1
call writestring
call crlf
mov edx,offset arr1
mov ecx,lengthof arr1
mov esi,0
L1:
call readint
mov arr1[esi],al
inc esi
loop L1

call crlf
mov edx,offset msg2
call writestring
call crlf
mov edx,offset arr2
mov ecx,lengthof arr2
mov esi,0
L2:
call readint
mov arr2[esi],al
inc esi
loop L2

mov ebx,0
mov ecx,0
mov edi,0
mov len1,10
mov len2,10
mov len3,20
.while edi < len3

.if ebx < len1 &&  ecx < len2

mov al,arr2[ecx]

.if arr1[ebx] < al
mov al,arr1[ebx]
mov arr3[edi],al
inc ebx

.else
mov al,arr2[ecx]
mov arr3[edi],al
inc ecx

.endif
inc edi

.elseif ebx == len1

.while edi < len3
mov al,arr2[ecx]
mov arr3[edi],al
inc edi
inc ecx
.endw

.else


.while edi< len3
mov al,arr1[ebx]
mov arr3[edi],al
inc edi
inc ebx
.endw
.endif

.endw

mov edx,offset msg3
call writestring
call crlf
mov edx,offset arr3
mov ecx,lengthof arr3
mov esi,0

L3:
mov edx,offset msg4
call writestring

mov al,arr3[esi]
call writedec
inc esi
loop L3

exit
main endp
end main


Bubble Sort in Assembly Language

include irvine32.inc

.data
array byte 10 DUP(?)
swap byte 0
msg byte " Enter 10 NUmber: ",0
msg1 byte " After Sorting : ",0
msg2 byte "   ",0

.code
main proc
call clrscr
call crlf
mov edx,offset msg
call writestring
call crlf
mov edx,offset array
mov ecx,lengthof array
mov esi,0

L1:
call readint
mov array[esi],al
inc esi
loop L1

mov bx,1
mov ax,8

mov edx,offset array

.while bx > 0
mov bx,0
mov si,0



.while si <= ax

mov al,array[si+1]
.if array[si] > al




mov al,array[si]
xchg al,array[si+1]
mov array[si],al

mov bx,si

.endif
inc si

.endw
mov ax,bx


.endw

mov edx,offset array
mov ecx,lengthof array
mov esi,0
mov edx,offset msg1
call writestring
L2:
mov al,array[esi]
call writedec
mov edx,offset msg2
call writestring
inc esi
loop L2

exit
main endp
end main


Program to check No is Palindrome in Assembly

This Program Take a No from User Reverse it to check that it is Palindrome or Not Assembly Language Code From Programming SeekerzzZZ


include irvine32.inc

.data
num word 0
key word 0
temp word 0
i word 0
reverse word 0
msg byte "Enter the number: ",0
msg1 byte " No is Palindrome ",0
msg2 byte " Not  a Palindrome ",0

.code
Main proc
call crlf
call clrscr
mov edx,offset msg
call writestring
call readint
mov temp,ax
mov key,ax

.while temp > 0

mov dx,0
mov ax,temp
mov bx,10

div bx
mov temp,ax

mov num,dx
mov ax,num

mov ax,10
mov bx,reverse
mul bx

add ax,num
mov reverse,ax

call crlf
.endw

mov ax,key
.if reverse != ax
call crlf
mov edx,offset msg2
call writestring
.else
call crlf
mov edx,offset msg1
call writestring
.endif

exit
main endp
end main




Saturday, May 16, 2015

Binary Search Code in Assembly Language

Binary Search Code in Assembly Language ... Compiler Masm615 

include irvine32.inc

.data
array byte 10 DUP(?)
num byte ?
first byte 0
middle byte 0
last byte 0
msg1 byte " Enter 10 Number in Array : ",0
msg2 byte " Enter Number to Find: ",0
msg3 byte " Found ",0
msg4 byte " Not Found ",0

.code
main proc
call clrscr

call crlf
mov edx,offset msg1
call writestring
call crlf
mov edx,offset array
mov ecx,lengthof array
mov esi,0
L1:
call readint
mov array[esi],al
inc esi
loop L1

call crlf
mov edx,offset msg2
call writestring
call readint
mov num,al

mov al,lengthof array
add al,first
mov bl,2
div bl
mov middle,al
mov bl,first
.while bl <= last
movzx si,middle
mov al,num
.if array[si] < al
mov al,middle
add al,1
mov first,al
mov al,num

.elseif array[si] == al
mov edx,offset msg3
call writestring
call crlf
jmp e

.else

mov al,middle
sub al,1
mov last,al
add al,first
mov bl,2
div bl
mov middle,al
.endif
.endw


mov edx,offset msg4
call writestring
call crlf


e:
exit
main endp

end main


Thursday, May 14, 2015

.IF statement in Assembly Language

Write an assembly program that take age of 50 people and count the number of people lives in the age group given below ? Also print the age
 20 - 30 years
 40 - 50 years
 35 - 45 years
 25 - 45 years

include irvine32.inc

.data
msg byte ":  Enter a No: ",0
msg2 byte " Sory Range Not Found ",0
r1 byte "  --Range 20 - 30 years--  ",0
r2 byte "  --Range 40 - 50 years--  ",0
r3 byte "  --Range 35 - 45 years--  ",0
r4 byte "  --Range 25 - 45 years--  ",0

rr1 dword 0
rr2 dword 0
rr3 dword 0
rr4 dword 0

num dword 0
i dword 0

.code
Main proc
call clrscr
call crlf

.while i != 50
call crlf
call crlf

mov eax,i
call writedec
mov edx,offset msg
call writestring
call readint
mov num,eax

.if eax < 20 || eax > 50
call crlf
mov edx,offset msg2
call writestring
.endif

.if eax >= 20 && eax <=30
inc rr1
call crlf
mov edx,offset r1
call writestring

.endif

.if eax >= 40 && eax <= 50
inc rr2
call crlf
mov edx,offset r2
call writestring

.endif

.if eax >= 35 && eax <= 45
inc rr3
call crlf
mov edx,offset r3
call writestring

.endif

.if eax >= 25 && eax <= 45
inc rr4
call crlf
mov edx,offset r4
call writestring

.endif
inc i
.endw

call crlf
call crlf
mov edx,offset r1
call writestring
mov eax,rr1
call writedec
call crlf

mov edx,offset r2
call writestring
mov eax,rr2
call writedec
call crlf

mov edx,offset r3
call writestring
mov eax,rr3
call writedec
call crlf

mov edx,offset r3
call writestring
mov eax,rr3
call writedec
call crlf
exit
main endp
end main


Friday, May 8, 2015

Program to generate 20 Even no and then saved and display them by after making Odd

Program to generate 20  Even no and then saved and display them by after making Odd
Assembly Language 

include irvine32.inc

.data
arr dword 20 DUP(?)
msg byte " Even NO: ",0,13h,10h
msg1 byte " After converting it into ODD: ",0,13h,10h
count dword 0
num dword 0
divied dword 0

.code
main proc
call clrscr
call crlf

mov esi,0
.while count != 20
;call randomize
call random32

mov eax,100
call randomrange

mov num,eax
mov edx,0
mov ebx,2
div ebx

.IF edx == 0
.IF num < 42

call crlf
mov edx,offset msg
call writestring

call settextcolor
mov eax,100
call delay

mov eax,num
call writedec
mov arr[esi],eax
add esi,4
inc count

.endif
.endif
.endw

mov esi,0
mov count,0

call crlf

.repeat
call crlf
mov edx,offset msg1
call writestring

mov eax,arr[esi]
add eax,1
call writeint
add esi,4
inc count

.until count == 20

exit
main endp

end main


Saturday, May 2, 2015

Using AND convert lower alphabets into upper ~ Assembly Programs

This Program Use AND operator to Convert lower alphabets into upper
x   y   x^y
1   0    0
0   0    0  
1   1    1
0   1    0


include irvine32.inc
.data

  alp byte ?
  msg byte "Please Enter an Alphabet to Make it in upper latter: ",0,13h,10h
  msg1 byte "In upper Latter:  ",0,13h,10h
  msg2 byte "Latter is :  ",0,13h,10h
  msg3 byte "Binary is :   ",0,13h,10h
  msg4 byte "ASCII is  : ",0,13h,10h

.code
  main proc
call clrscr
call crlf
     mov edx,offset msg
     call writestring
call crlf
call crlf
     mov edx,offset msg2
     call writestring
     mov edx,offset alp
     call readchar

     call writechar
call crlf
     mov edx,offset msg3
     call writestring
     call writebin
call crlf
     mov edx,offset msg4
     call writestring
     call writedec

call crlf
AND al,11011111b
call crlf
mov edx,offset msg1
     call writestring
call crlf
     mov edx,offset msg3
     call writestring

call writebin
call crlf
     mov edx,offset msg2
     call writestring
call writechar
call crlf
     mov edx,offset msg4
     call writestring
     call writedec

      exit
     main endp
   end main

Friday, May 1, 2015

check parity of 8-bit number Assembly Program

See Also: Check Parity of 32-bit Number Assembly Program
                 Check Parity of 16-bit Number Assembly Program
                 Check Parity of 8  -bit Number Assembly Program


include irvine32.inc
.data
   
num byte 122
msg  byte "Parity Flag is set   : PF=EVEN ",0,13h,10h
msg1 byte "Parity flag is clear : PF=ODD  ",0,13h,10h

.code
main proc
call clrscr
call crlf
mov al,num
call writebin

XOR al,0
cmp al,0
JP L1
JNP L2
L2:
call crlf
mov edx,offset msg1
call writestring
jmp e

L1:
call crlf
mov edx,offset msg
call writestring
jmp e
e:
exit
main endp
end main

Check parity of 16-bit number Assembly Program

See Also: Check Parity of 32-bit Number Assembly Program
                 Check Parity of 16-bit Number Assembly Program
                 Check Parity of 8  -bit Number Assembly Program


include irvine32.inc
.data
   
num word 39263
msg  byte "Parity Flag is set   : PF=EVEN ",0,13h,10h
msg1 byte "Parity flag is clear : PF=ODD  ",0,13h,10h

.code
main proc
call clrscr
call crlf
mov ax,num
call writebin
mov ax,num
XOR al,ah
cmp al,0
JP L1
JNP L2
L2:
call crlf
mov edx,offset msg1
call writestring
jmp e

L1:
call crlf
mov edx,offset msg
call writestring
jmp e
e:
exit
main endp
end main

Check Parity of 32-bit Number Assembly Program

See Also: Check Parity of 32-bit Number Assembly Program
                 Check Parity of 16-bit Number Assembly Program
                 Check Parity of 8  -bit Number Assembly Program


include irvine32.inc
.data
   
num dword 3043274211
msg  byte "Parity Flag is set   : PF=EVEN ",0,13h,10h
msg1 byte "Parity flag is clear : PF=ODD  ",0,13h,10h

.code
main proc
call clrscr
call crlf
mov eax,num
call writebin
mov al,byte ptr num
mov ah,byte ptr num+1
XOR al,ah
mov ah,byte ptr num+2
XOR al,ah
mov ah,byte ptr num+3
XOR al,ah
cmp al,0
JP L1
JNP L2
L2:
call crlf
mov edx,offset msg1
call writestring
jmp e

L1:
call crlf
mov edx,offset msg
call writestring
jmp e
e:
exit
main endp
end main