Consider the following code. Show how it might be complied into generic assembly language assuming that the compiler unrolls the loop three times. All values are integers. Assume that register indirect with offset addressing is available, but pointers have to be explicitly updated.
for (int i = 0; i < 30; i++) {
z[i] = 3 * (x[i] + y[i]);
}
Assume that r0, r1, and r2 have been set up to point to x, y, and z, respectively. One trip round the loop might
be
Loop LDR r3,[r0] ;get x[i]
ADD r0,r0,#4 ;update pointer
LDR r4,[r1] ;get y[i]
ADD r1,r1,#4 ;update pointer
ADD r4,r4,r3 ;x[i] + y[i]
ADD r4,r4,r4,lsl #1 ;3(x[i] + y[i])
STR r4,[r2] ;store z[i]
ADD r2,r2,#4 ;update pointer
SUBS r5,r5,#1 ;dec loop counter
BNE Loop
If we unroll the loop three times, we get
Loop LDR r3,[r0] ;get x[i]
LDR r4,[r0,4] ;get x[i+1]
LDR r5,[r0,8] ;get x[i+2]
ADD r0,r0,#12 ;update pointer by 3 elements
LDR r6,[r1] ;get y[i]
LDR r7,[r1,4] ;get y[i+1]
LDR r8,[r1,4] ;get y[i+2]
ADD r1,r1,#12 ;update pointer
ADD r6,r6,r3 ;x[i] + y[i]
ADD r7,r7,r4 ;x[i+1] + y[i+1]
ADD r8,r8,r5 ;x[i+2] + y[i+2]
ADD r6,r6,r6,lsl #1 ;3(x[i] + y[i])
ADD r7,r7,r7,lsl #1 ;3(x[i+1] + y[i+1])
ADD r8,r8,r8,lsl #1 ;3(x[i+2] + y[i+2])
STR r6,[r2] ;store z[i]
STR r7,[r2,4] ;store z[i]
STR r8,[r2,8] ;store z[i]
ADD r2,r2,#12 ;update pointer
SUBS r9,r9,#3 ;decrement counter
BNE Loop
We have to increment the pointer by 3 × 4 = 12 at each trip round the loop because we have dealt with three
elements. The following snapshot gives the assembly window from the ARM debugger (using 9?element arrays).

You might also like to view...
_________ assures that data received are exactly as sent and that the purposed identity of the sender is valid.
Fill in the blank(s) with the appropriate word(s).
A(n) _________________________ ensures that servers remain working when there is a brief power outage, or that there is time to properly shut down a server during a long power outage.
Fill in the blank(s) with the appropriate word(s).
You have a Windows Server 2008 32-bit Standard edition server and you want to upgrade to Windows Server 2012 Datacenter edition. Your CPU is 32-bit. What should you do?
A. Perform a clean install of Windows Server 2012 on the same server B. Upgrade to Windows Server 2008 R2 and then to Windows Server 2012 C. First upgrade to Windows Server 2008 Datacenter edition D. Install Windows Server 2012 on a new server and migrate roles
What do component-level design patterns contribute to the design process?
What will be an ideal response?