1) Write an assembly language program in MIPS32 assembly language to
a) Input two one-dimensional arrays of size L and M.
b) Compute the convolution of the above entered arrays.
c) Print the answer y and plot the graphs of x, h and y
Given:
1) Discrete Convolution of two functions x and h is given by the following formula
|
Where N = L + M -1
2) L=4 and M = 5
3) Choose any integer values for array elements
# Write an assembly language program in MIPS32 assembly language to find
# Discrete Convolution of two functions x and h
# Author - Sunil Doiphode
.data # data declaration section
funx: .word 0 : 8 # array one address x()
funh: .word 0 : 8 # array two address h()
funy: .word 0 : 8 # array two address y()
sizex: .word 4 # Size of array 1 (L)
sizeh: .word 5 # size of array 2 (M)
sizey: .word 9 # size of resulting array (N)
.text # program steps starts
#read First Array X(n)
la $t0,funx # load array xn address
la $t5,sizex # load size of array address
lw $t4,0($t5) # load array size number to tmp counter
lw $t5, 0($t5) # load array size
loop1: li $v0,5 # set readint instruction
syscall # call the system call
sw $v0, 0($t0) # store the read value
addi $t0, $t0, 4 # increment the array address to the next location
addi $t4, $t4, -1 # decrement the counter
bgtz $t4, loop1 # loop1
# Read Second array h(n)
la $t0,funh # load array hn address
la $t6, sizeh # load size of array address
lw $t4, 0($t6) # load array size number to tmp variable
lw $t6, 0($t6) # load array size number
loop2: li $v0,5 # set readint instruction
syscall # call the system call
sw $v0, 0($t0) # store the read value
addi $t0, $t0, 4 # increment the array address to the next location
addi $t4, $t4, -1 # decrement the counter
bgtz $t4, loop2 # loop2
# N = L + M -1
add $t4,$t5,$t6 # N = L + M
addi $t3,$t4,-1 # N = L + M -1 (Hold value) -- N --- t3
# t7 = x(k) & t8 = h(n-k)
sub $t4,$t4,$t4 # (Counter yn initialised to zero --- t4
la $t0,sizey # load array size address
lw $s4,0($t0) # load yn array size to tmp ynloopcount
lw $t5,0($t0) # load yn array size
la $s7,funy #---------------------------yaddress -- t7
loop3: la $t7,funx #---------------------------xaddress -- t7
la $t8,funh #-------------------------- haddress -- t8
li $t9, 0 # summation count k =0------------- k --t9
addi $s0,$t3,0 # summation loopcount = N
li $s3,0 # summation amt -------summation amt ---s3
# nested loop loop4
loop4: sub $s1,$t4, $t9 # s1 = ----------------------- n-k --- s1
# (n-k) should be greater than 0 if less than zero jump to skip
li $s5, 0
slt $s6, $s5, $s1 # slt d,s,t if s < t d <-- 1 else d <-- 0
blez $s6, skip
li $s2,4
mul $s1,$s2,$s1
add $s6, $t8, $s1 # address of n-kth location
lw $s6, 0($s6) # s6 = x(n-k)
multu $s2,$t9
mflo $s1
add $s5,$t7, $s1
lw $s5, 0($s5) # s5 = h(k)
multu $s6,$s5
mflo $s1 # s1= h(k)*x(n-k)
add $s3,$s3,$s1 # Add the result to summation
skip: addi $t9,$t9,1 # increment the index counter
addi $s0,$s0,-1 # decrement the loop counter
bgtz $s0, loop4 # End of summation loop4
# store the yn values in the array
li $s2,4
multu $t4,$s2
mflo $s1
add $s1,$s7, $s1
sw $s3, 0($s1)
addi $t4, $t4, 1
addi $s4, $s4, -1
bgtz $s4, loop3 # End of loop3
# print y(n)
la $t0,funy # load array xn address
la $t5, sizey # load size of array address
lw $t4, 0($t5) # load array size number to tmp counter
lw $t5, 0($t5) # load array size
loop5: lw $a0, 0($t0)
li $v0,1 # set writeint instruction
syscall # call the system call
addi $t0, $t0, 4 # increment the array address to the next location
addi $t4, $t4, -1 # decrement the counter
bgtz $t4, loop5 # End of printing loop5
Input1 X=2,2,2,2
H=2,2,2,2,2
Y= 0,4,8,12,16,12,8,4,0
Input2 X=1,2,3,4
H=1,2,3,4,5
Y= 0,2,7,16,30,34,31,20,0
Input3 X=4,3,2,1
H=5,4,3,2,1
Y= 0,16,24,25,20,10,4,1,0