Вы находитесь на странице: 1из 4

VLSI ARCHITECTURE

VAX PROGRAMMING
FOR SORT

Submitted to:

Submitted by:

Dr. Vinay Kumar

Ashima Gupta

ECED

601562006
M.Tech (VLSI)

THAPAR UNIVERSITY, PATIALA

BUBBLE STORING PROGRAM IN VAX


The two parameters of procedure sort, v, n and temp, are found in the stack in location
4(ap) , 8(ap) and C(ap), respectively. These variables are assigned to registers i to r6 and j
to r4.

The C programming for the bubble sort is


Sort (int v[ ] ,int n , int temp)
{
Int i, j ;
for(i = 0; i< n; i++)
{
for(j = i+1; j< n+1; j++)
{
if(v[i+1]< v[i])
temp = v[i];
v[i] = v[i+1];
v[i+1] = temp;
}
}
}

In VAX machine code sorting program is


sort : .word^m<r9,r8,r7,r6,r5,r4,r3>
moval r8 , C(ap)

;move address of temp into r8

moval r7 , 8(ap)

;move address of n into r7

moval r5 , 4(ap)

;move address of v into r5

VAX code for outer loop


for(i = 0; i< n; i++)
clrl r6

; Clear i.e. i=0

subl3 r9,r7,#1

;Subtract long word with three operands i.e. r9=n-1

loop1 cmpl r6,(r9)

;Compare long words i.e. i:n-1

bgeq exit 1

;Branch greater then equal to i.e. i>n-1

VAX code for inner loop


for(j = i+1; j< n+1; j++)
addl3 r4,r6,#1

;Add long word with three operands i.e. j = i+1

loop2 cmpl r4,(r7)

;Compare long words i.e. j:n

bgeq exit2

; Branch greater then equal to i.e. j>n

Now code define for an array


movl r3,(r5)

;Move long word i.e. r3=MEM[r5]

Code for comparison loop


cmpl r3[r6],r3[r4]

;Compare long words i.e. v[i]:v[i+1]

bleq exit3

;Branch greater then equal to i.e. v[i]<v[i+1]

Code for swapping the values


movl r8,(r5)[r6]

;Move long word i.e. temp=v[i]

addl3 r4, r6,#1

;Add long word i.e. r4=i+1

movl (r5)[r6],(r5)[r4]

;Move long word i.e. v[i]=v[i+1]

movl (r5)[r4],r8

;Move long word i.e. v[i+1]=temp

exit2 incl r4

; increment the values of r4

brb loop2

;branch for test for inner loop

exit1 incl r6

; increment the values of r4

brb loop1

; branch for test for outer loop

exit3 ret

; return the values

Вам также может понравиться