mplab
Experiment: 01
a). Write an Assembly language program to define data of different data type and perform data transfer operations on the data:-
code....
.section .data
value:
.int 2
.section .text
.globl _start
_start:
movl %100, %eax
movl %eax,%ebx
movl $1,%eax
movl $0,%ebx
int $0x80
LAB 2:
a). Develop an Assembly language program to perform all arithmetic operations:
CODE:
section .data
a:
.int 2
C:
.int 2
d:
.int 5
e:
.int 0
.section .text
.globl _start
_start:
/* a=(b+c)/d */
/* a=2,b=8,c=2,d=5 */
movl %8, %ebx|
movl $2,%eax
addl %ebx,%eax
movl $5,%ecx
movl %eax, a
/* a=(b*c)-d */
movl $8,%esi
movl $2,%eax
mull %esi,%eax
movl $5,%ecx
subl %eax.%ecx
movl %eax,a
/* e=(((a*b)/c)*d) */
movl $2,%eax
movl $8,%ebx
mull %ebx
movl $2,%ecx
divl %ecx
movl $5,%edx
mull %edx
movl %eax,e
movl $1,%eax
movl $0,%ebx
int $0x80
LAB 22:
CODE:
.section .data
a:
.int 2
b:
.int 8
C:
.int 2
d:
.int 5
e:
.int p
.section .text
.globl_start
_start:
/* a=(b+c)/d */
/* a=2,b=8,c=2,d=5 */
movl b,%ebx
movl c, %eax
addl %ebx,%eax
movl d,%ecx
divl %ecx
movl %eax,a
/* e=(b*c)-d */
movl b,%esi
movl c,%eax
mull %esi
movl d,%ecx
subl %eax,%ecx
movl %ecx, a
movl $1,%eax
movl $0,%ebx
int $
LAB 23:
CODE:
.section .data
a:
.int 0
b:
.int 10
C:
.int 20
d:
.int 30
.section .text
.globl_start
_start:
/* boolean functions */
/* a=(b XOR C) OR d */
/* b=10,c=20,d=30 */
Movl $10,%eax
movl $20,%ebx
movl $30,%ecx
xorl eax,%ebx
orl %ebx,%ecx
movl %ecx,a
/* boolean functions */ */ /* a=(b and c) xor d */
/* b=10,c=20,d=30 */
movl $10.%eax
movl $20,%ebx
movl $30,%ecx
andl %eax,%ebx
xorl %ebx,%ecx
movl %ecx, a
/* boolean functions */
/* a=(b XOR C) OR d */
/* b,c are in registers and a,d are in the memory (a=2,d=5) */
movl $4,%eax
movl $9,%ebx
xorl eax,%ebx
movl d,%edi
orl %ebx,%edi
movl %edi, a
/* boolean functions */ /* a=(b and c) XOR d */
/* b,c are in registers and a,d are in the memory (a=2,d=5) */
movl $40,%edx
movl $55,%ebx
andl %edx,%ebx
movl d.%eax
/* boolean functions */
/* a=(b and c) XOR d */
/* b,c are in registers and a,d are in the memory
movl $40,%edx
movl $55,%ebx
andl %edx,%ebx
movl d, %eax
xorl %ebx,%eax
movl %eax,a
movl $1,%eax
movl $0,%ebx
int $0x80
C). Write an Assembly language program to perform control flow operations using conditional instructions:-
1.
Create an array of 10 elements and initialized the array elements with random values :
•
Assign array[5]=0 and array[8]=0
•
Perform the computation :(value is a memory variable):
Value = array[3]+array[6]
Array[7]=value +array[7]
•
Compare arrya[5] with arrya[8] show whether both the values are equal or not
•
Read the 7th element of the array and check whether its odd or even number.
•
To findthe given triangle is whether equalatral or isosceles or scalar triangle .
CODE:
.section .data
value:
.int 2
a:
.int 12,24,36,48,60,75,82,90,95,100
.section .text
.globl_start
_start:
movl $3,%ebx
movl $6,%ecx
movl a(,%ebx,4),%ebx
movl a(,%ecx,4),%eax
addl %ebx,%eax
movl %eax, value
movl $1,%eax
movl $0,%ebx
int $0x80
Lab32:
Code:
.section .data
side1:
.int 32
side2:
.int 40
side3:
.int 62
.section .text
.globl_start
_start:
/* to find the type of the triangle */
/* case 1 when it is a equilateral triangle */
movl side1,%edx
movl side2,%edi
movl side3,%esi
cmp %edx,%edi
je qual
jne unequal
equal:
cmp %edi,%esi
je equal1
jne notequal1
equal1:
movl $111,%eax
notequal1:
movl $121,%eax
notequal:
movl $121,%eax
notequal:
cmp %edi,%esi
je equal2
jne notequal2
equal2:
movl $121,%eax
notequal2:
cmp %edx,%esi je equal3
jne notequal3
equal3:
movl $121,%eax
notequal3:
movl $123,%eaх
movl $1,%eax
movl $0,%ebx
int $0x80
d).
•
to create in uninitialized array and print “n” natural numbers in the created array.
•
Develop an assembly language program to insert a given element in an array at a specific position. Input array:10,20,30,40,50
Element to be inserted :60
Position:3
Output array:10,20,30,60,40,50
•
Develop an assembly language program to remove an element in an array. Input array:10,20,30,40,50
Element to be removed :30
Output array:10,20,40,50
•
Develop an assembly language program to filter out even numbers in the given array
Input array:5,10,15,25,30,35
Output array:10,30
Lab 41:
Code:
.section .bss
.lcomm output_arгау,40
section .text
.globl_start
_start:
movl $0,%ecx
loop:
movl %ecx,output_array(,%ecx,4)
addl $1,%ecx
cmpl $10,%ecx
jne loop
movl $1,%eax
movl $0,%ebx
int $0x80
Lb42:
Code:
.section .data
input_aггау:
.int 10,20,30,40,50
output_array:
.int 0,0,0,0,0,0
pos: .int 3
section text
.globl_start
_start:
movl $0,%ecx
movl $0,%edx
loop:
cmpl pos,%ecx
jne update_loop_index
movl %60,output_array(,%edx,4)
addl $1,%edx
jmp update_loop_index
update_loop_index:
movl input_array(,%ecx,4),%eax
movl %eax,output_array(,%edx,4)
addl $1,%ecx
addl $1,%edx
jmp loop_bound_checking
loop_bound_checking:
cmp $5,%ecx
ine loop
movl $1,%eax
movl $0,%ebx
int $0x80
LAB43:
CODE:
.section .data
input_array:
.int 10,20,30,40,50
output_array:
.int 0,0,0,0,0
.int 30
elem:
.section .text
.globl _start
_start:
Movl $0,%ecx
movl $0,%edx
movl elem,%esi
movl input_array(,%ecx,4),%eax
loop:
cmpl %eax,%esi
je loop1
movl %eax,output_array(,%edx,4)
addl $1,%ecx
addl $1,%edx
jmp loop_bound_checking
loop1:
addl $1,%ecx
jmp loop
loop_bound_checking:
cmp $5,%ecx
jne loop
movl $1,%eax
movl $0,%ebx
int $0x80
LAB44:
CODE:
.section data
input:
.int 5,10,15,25,30,35
.section .bss
.lcomm output, 24
.section .text
.globl_start
_start:
movl $0,%ecx
movl $0,%esi
loop:
movl input(,%ecx,4),%eax
movl $2,%ebx
movl $0,%edx
divl %ebx
cmpl $0,%edx
je update
addl $1,%ecx
cmpl $6,%ecx
jne loop
movl $1,%eax|
movl $0,%ebx
int $0x80
movl input(,%ecx,4),%eax
movl %eax,output(,%esi,4)
addl $1.%esi
update :
movl input(,%ecx,4),%eax
movl %eax,output(,%esi,4)
addl $1,%esi
addl $1,%ecx
cmpl $6,%ecx
jne loop
movl $1,%eax
movl $0,%ebx
int $0x80
LAB45
Code:
.section .data
fib:
.int 8
.section .bss
.lcomm output, 32
.section .text
.globl_start
_start:
movl $0,%esi
movl $0,%edi
movl $0,%eax
movl fib,%edx
subl $2,%edx
movl %eax,output(,%edi,4)
movl $1,%ecx
addl $1,%edi
movl %ecx,output(,%edi,4)
movl $1,%ebx|
addl $1,%edi
loop:
addl %ebx,%eax
movl %ebx,%ecx
movl %eax, output(,%edi,4)
movl %eax,%ebx
addl $1,%esi
addl $1,%edi
cmpl %esi.%edx
jne loop
movl $1,%eax
movl $0,%ebx
int $0x80
Lab 5
e)Develop an assembly language program for the following:
•
Copy the contents of MSG1 TO MSG2
•
Copy the contents of MSG1 TO MSG2 in reverse order
•
Develop an ALP to count the number of vowels in the given string
Input: Hi welcome
Output: 4
•
Develop an ALP to compare the new string display the message accordingly
•
Develop an ALP to compare two strings and display accordingly
LAB51:
section .data
input_string:
.ascii "Hi Welcome"
section .bss
.lcomm output_string,10
.section .text
.globl _start
_start:
movt $0,%ecx
loop:
movb input_string(,%ecx,1),%al
movb %al,output_string(,%ecx,1)
addl $1,%ecx
cmpl $10,%ecx
jne loop
movl $1,%eax
movl $0,%ebx
int $0x80
LAB52:
Code:
.section .data
input_string:
.ascii "Welcome to the university"
.section .bss
.lcomm output,25
.section .text
.globl_start
_start:
movl $0,%ebx
movl $0,%ecx
mocl $24,%esi
loop:
movb input_string(,%esi,1),%al
movb %al,output(,%ebx,1)
addl $1,%ebx
addl $1,%ecx
subl $1,%esi
cmpl $25,%ecx
jne loop
movl $1,%eac
movl $0,ebx
int $0x80
LAB53:
Code:
.section .data
str:
.asciz "Hi Welcom"
vovels:
.ascii "aeiou"
count:
.int 0
.section .text
.globl _start
_start:
movl $0,%esi
movl $0,%edi
movl $0,%ebx
movl $0,%eax
loop:
movb str(,%esi,1),%al
addl $1,%esi
cmpl $11,%esi
jl checkvowel
jmp exit
checkvowel:
movb vovels(,%edi,1),%bl
cmpb %al,%bl
je vowelfound
addl $1,%edi
cmpl $5,%edi
jl checkvowel
movl $0,%edi
jmp loop
vowelfound:
addl $1,count
jmp loop
exit:
movl $1,%eax
movl $0,%ebx
int $0x80
LAB54:
Code:
.section .data
string1:
.asciz "hi elcome"
equal_result:
.asciz "string are equal"
NE_Result:
.asciz "string are not equal"
string2:
asciz "hi welcome"
.section .text
.globl_start
_start:
movl $0,%ecx
loop:
movb string1(,%ecx,1),%a1
movb string2(,%ecx,1),%b1
cmpb %a1,%b1
je increment_loop_index
Leal NE_Result,%esi
jmp exit
increment_loop_index:
addl $1,%ecx
cmpl $10,%ecx
jne loop
Leal equal_result,%esi
exit:
movl $1.%eac
movl $0, ebx
int $0x80
LAB54:
Code:
.section .data
string1:
.asciz "hi elcome"
equal_result:
.asciz "string are equal"
NE_Result:
.asciz "string are not equal"
string2:
asciz "hi welcome"
.section .text
.globl_start
_start:
movl $0,%ecx
loop:
movb string1(,%ecx,1),%a1
movb string2(,%ecx,1),%b1
cmpb %a1,%b1
je increment_loop_index
Leal NE_Result,%esi
jmp exit
increment_loop_index:
addl $1,%ecx
cmpl $10,%ecx
jne loop
Leal equal_result,%esi
exit:
movl $1.%eac
movl $0, ebx
int $0x80
LAB55:
Code:
.section .data
input:
.asciz "hello everyone welcome"
tocmp:
.asciz “ ”
count:
.int 17
.section .bss
.lcomm output, 19
.section .text
.globl_start
_start:
movl $1,%ecx
movl $0, edx
movl $0,%ebx
loop:
movb input(,%ecx,1),%al
cmpb %al, tocmp
jne nloop
movb input(,%ecx,1),%al
movb %al, output(,%edx,1)
addl $2,%ecx
addl $1,%edx
movb input(,%ecx,1),%al
movb %al,output(,%edx,1)
addl $2,%ecx
addl $1.%edx
movb input(,%ecx,1),%al
movb %al, output(,%edx,1)
addl $2,%ecx
addl $1,%edx
movb input(,%ecx,1),%al
movb %al, output(,%edx,1)
addl $1,%ecx
addl $1,%edx
cmpl %ebx,count
jne loop
movl $1,%eac
movl $0,ebx
int $0x80
nloop:
movb input(,%ecx,1),%al
movb %al, output(,%edx,1)
addl $1,%ecx
addl $1,%edx
addl $1,%ebx
cmpl %ebx,count
jne loop
movl $1,%eax
movl $0,%ebx
int $0x80
Lab 6
•
Develop an ALP to compute the second smallest number in the given array.
•
Develop an ALP to search a given element input_string and print its specified position.
•
Using ALP to find the given key in the input data and output the position of it.
•
Develop an ALP to sort all the elements in the given array (ascending order)
LAB61:
Code:
.section .data
input:
key:
.int 10,20,30,40,50
.int 60
section .bss
.lcomm pos,4
section text
.globl _start
_start:
movl $0,%esi
loop:
movl input(,%esi,4),%eax
cmpl key,%eax
jne loop1
movl %esi,pos
movl $1,%eax
movl $0,%ebx
int $0x80
loop1:
addl $1,%esi
cmpl $5,%edx
jne loop
movl $1,%eax
movl $0,%ebx
int $0x80
OUPUT:
LAB62:
Code:
.section .data
input:
asciz "hi welcome"
key:
.asciz "w"
.section .bss
.lcomm pos ,4
section .text
.globl_start
_start:
movl $0,%esi
loop:
movb input(,%esi,1),%al
cmpb key %al
jne loop1
movl %esi,pos
movl $1,%eax
movl $0,%ebx
int $0x80
loop1:
addl $1,%esi
cmpl $10,%esi
jne loop
movl $1,%eax
movl $0,%ebx
int $0x80
output:
LAB63:
Code:
section .data
input:
.int 20,5,44,10,70,50
temp:
.int 2
.section .text
.globl_start
_start:
movl $0,%edx
movl $1,%esi
loop:
movl input(,%edx,4),%eax
movl input(,%esi,4),%ebx
cmpl %eax,%ebx
jl loop1
addl $1,%edx
addl $1,%esi
cmpl $5,%edx
jne loop
subl $1, temp
movl $0,%edx
movl $1,%esi
cmpl $0, temp
jne loop
movl input(,%edi,4),%ecx
movl $1,%eax
movl $0.%ebx
int $0x80
loop1:
movl %ebx,input(,%edx,4
movl %ebx, input(,%esi,4)
addl $1,%edx
addl $1,%esi
cmpl $5,%edx
jne loop
subl $1, temp
movl $0,%edx
movl $1,%esi
cmpl $0, temp
jne loop
movl input(,%edi,4),%ecx
movl $1,%eax
movl $0,%ebx
int $0x80
OUTPUT:
LAB64:
Code:
section .data
input:
.int 20,5,44,10,70,50
temp:
.int 2
.section .text
.globl_start
_start:
movl $0,%edx
movl $1,%esi
loop:
movl input(,%edx,4),%eax
movl input(,%esi,4),%ebx
cmpl %eax,%ebx
jl loop1
addl $1,%edx
addl $1,%esi
cmpl $5,%edx
jne loop
subl $1, temp
movl $0,%edx
movl $1,%esi
cmpl $0, temp
jne loop
movl input(,%edi,4),%ecx
movl $1,%eax
movl $0.%ebx
int $0x80
loop1:
movl %ebx,input(,%edx,4
movl %ebx, input(,%esi,4)
addl $1,%edx
addl $1,%esi
cmpl $5,%edx
jne loop
subl $1, temp
movl $0,%edx
movl $1,%esi
cmpl $0, temp
jne loop
movl input(,%edi,4),%ecx
movl $1,%eax
movl $0,%ebx
int $0x80
Lab 7
•
Write ALP to write GCD and LCM
•
Write an ALP program to swap two numbers using logical instruction
•
Write an ALP to compute factorial of a number.
LB71:
Code:
section.data
n1:
.int 70
n2:
.int 10
section .bss
lcomm gcd 4
.lcomm lcm 4
.section .text
.globl _start
_start:
Movl $0,%esi
movl n1,%eax
movl n2,%ebx
cmp %esi,ebx
jne loop
movl $1,%eax
movl $0,%ebx
int $0x80
loop:
movl $0,%edx
divl %ebx
movl %ebx,%eax
movl %edx,%ebx
cmpl %esi,%edx
jne loop
movl %eax,gcd
movl n1,%eax
movl n2,%ebx
mull %ebx
movl $0,%edx
divl gcd
movl %eax,lcm
movl $1,%eax
movl $0,%ebx
int $0x80
OUTPUT:
LB72:
Code:
.section .data
n1:
.int 10
n2:
.int 20
.section .text:
.globl_start
_start:
movl n1,%eax
movl n2,%ebx
xorl %eax,%ebx
xorl %ebx,%eax
xorl %eax,%ebx
movl %eax,n1
movl %ebx,n2
movl $1,%eax
movl $0,%ebx
int $0x80
OUTPUT:
LB73:
Code:
section.data
input:
.int 5
output:
.int 0
.section .text
.globl_start
_start:
movl input,%eax
cmp $0,%eax
jne loop1
movl %eax, output
movl $1,%eax
movl $0,%ebx
int $0x80
loop1:
cmp $1,%eax
jne loop
movl $1,%eax
movl $1,%eax
movl $0,%ebx
int $0x80
loop:
subl $1, input
movl input,%ebx
mull %ebx
cmpl $1,input
jne loop
movl %eax, output
movl $1,%eax
movl $0,%ebx
int $0x80
output

Comments
Post a Comment