
Adnan M.
asked 01/28/21Write a subroutine in an assembly language program which divides an array of 20 elements into two halves. It rotates left the first half and rotates right the second half 5 times.
Write a subroutine in an assembly language program which divides an array of 20 elements into two halves. It rotates left the first half and rotates right the second half 5 times.
1 Expert Answer

Patrick B. answered 01/28/21
Math and computer tutor/teacher
I'm sorry I do not have any assembler, and even if I did, it would probably not match
the assembler you have, as there are so many dialects. The best I can offer you is C (mid-level);
The C compiler, by setting some command line or compiler switches, can generate assembler code for you automatically, though it may not match your dialect. It is quite a challenge to write this in C, let alone assembler.
The source code is uploaded in the resources section under this link if you want it.
//******************************************************************************************//
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
ArrayRotateLeft(void * base,int numRecs, int recSize)
{
int iLoop;
char * A = (char*)base; //points at the first
char * last = A+(numRecs-1)*recSize; //points at the last
char * temp = (char*) malloc(recSize); //temp storage
//stores the first in temporary memory location
memcpy(temp,base,recSize);
//moves every element one position to the left
for (iLoop=0; iLoop<numRecs-1; iLoop++)
{
memcpy(A+iLoop*recSize,A+(iLoop+1)*recSize,recSize);
}
//copies what was the first, stored in temp, into the last position
memcpy(last,temp,recSize);
free(temp);
}
ArrayRotateRight(void * base, int numRecs, int recSize)
{
int iLoop;
char * A = (char*)base; //points at the first
char * last = A+(numRecs-1)*recSize; //points at the last
char * temp = (char*) malloc(recSize); //temp storage
//stores the LAST in temporary memory location
memcpy(temp,last,recSize);
//moves every element one position to the right
for (iLoop=numRecs-1; iLoop>0; iLoop--)
{
memcpy(A+iLoop*recSize,A+(iLoop-1)*recSize,recSize);
}
//copies what was the last, stored in temp, into the first position
memcpy(A,temp,recSize);
free(temp);
}
int main()
{
int iLoop;
int intNums[]={15,20,5,10,3,8,1,6,2,7,
4,9,11,13,19,16,18,17,14,12};
double amounts[] = {3.142, 2.723, 7.50, 7.53, 7.05, 35.42, 42.35, 9.88, 7.24, 6.25,
33.33, 3.33, 1.23, 3.45, 4.32, 5.34, 4.55, 1.11, 2.31, 2.89 };
char strs[20][10];
strcpy(strs[0],"alpha ");
strcpy(strs[1],"beta ");
strcpy(strs[2],"delta ");
strcpy(strs[3],"epsilon ");
strcpy(strs[4],"gamma ");
strcpy(strs[5],"iota ");
strcpy(strs[6],"kappa ");
strcpy(strs[7],"lambda ");
strcpy(strs[8],"mu ");
strcpy(strs[9],"nu ");
strcpy(strs[10],"omicron ");
strcpy(strs[11],"phi ");
strcpy(strs[12],"pi ");
strcpy(strs[13],"rho ");
strcpy(strs[14],"sigma ");
strcpy(strs[15],"thi ");
strcpy(strs[16],"upsilon ");
strcpy(strs[17],"omega ");
strcpy(strs[18],"zeta ");
strcpy(strs[19],"theta ");
for (iLoop=0; iLoop<5; iLoop++)
{
ArrayRotateLeft(intNums,10,sizeof(int));
ArrayRotateRight(&intNums[10],10,sizeof(int));
}
for (iLoop=0; iLoop<5; iLoop++)
{
ArrayRotateLeft(amounts,10,sizeof(double));
ArrayRotateRight(&amounts[10],10,sizeof(double));
}
for (iLoop=0; iLoop<5; iLoop++)
{
ArrayRotateLeft(strs,10,10);
ArrayRotateRight(&strs[10],10,10);
}
for (iLoop=0; iLoop<20; iLoop++) { printf("%d \n",intNums[iLoop]); }
for ( iLoop=0; iLoop<20; iLoop++) { printf("%lf \n",amounts[iLoop]); }
for ( iLoop=0; iLoop<20; iLoop++) { printf("%s \n",strs[iLoop]); }
}
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Patrick B.
at the very least, you can borrow the logic from the C code and translate to assembler01/28/21