In: Computer Science
In assembly level, a code of loop structure can be either
implemented using a \branch forward" or a \branch backward"
approach.
(a) Name the advantages and disadvantages using one versus the
other, in terms
of speed, applicability, code size and other possible relevant
factors. Clearly
explain your conclusion.
(b) For the following segment of C program, determine which
approach is applicable, and then write the most efficient DLX
assembly code for it. Assume r1 is
already assigned to x as a temporary register.
x=0;
for(i=0; i<100; i=i+3)
for(j=i; j<4*i; j++)
x=x*i+j
b)
Assembly code:
main:
        push    rbp
        mov     rbp, rsp
        mov     DWORD PTR [rbp-4], 0
        mov     DWORD PTR [rbp-8], 0
.L5:
        cmp     DWORD PTR [rbp-8], 99
        jg      .L2
        mov     eax, DWORD PTR [rbp-8]
        mov     DWORD PTR [rbp-12], eax
.L4:
        mov     eax, DWORD PTR [rbp-8]
        sal     eax, 2
        cmp     DWORD PTR [rbp-12], eax
        jge     .L3
        mov     eax, DWORD PTR [rbp-4]
        imul    eax, DWORD PTR [rbp-8]
        mov     edx, eax
        mov     eax, DWORD PTR [rbp-12]
        add     eax, edx
        mov     DWORD PTR [rbp-4], eax
        add     DWORD PTR [rbp-12], 1
        jmp     .L4
.L3:
        add     DWORD PTR [rbp-8], 3
        jmp     .L5
.L2:
        mov     eax, 0
        pop     rbp
        ret
__static_initialization_and_destruction_0(int, int):
        push    rbp
        mov     rbp, rsp
        sub     rsp, 16
        mov     DWORD PTR [rbp-4], edi
        mov     DWORD PTR [rbp-8], esi
        cmp     DWORD PTR [rbp-4], 1
        jne     .L9
        cmp     DWORD PTR [rbp-8], 65535
        jne     .L9
        mov     edi, OFFSET FLAT:_ZStL8__ioinit
        call    std::ios_base::Init::Init() [complete object constructor]
        mov     edx, OFFSET FLAT:__dso_handle
        mov     esi, OFFSET FLAT:_ZStL8__ioinit
        mov     edi, OFFSET FLAT:_ZNSt8ios_base4InitD1Ev
        call    __cxa_atexit
.L9:
        nop
        leave
        ret
_GLOBAL__sub_I_main:
        push    rbp
        mov     rbp, rsp
        mov     esi, 65535
        mov     edi, 1
        call    __static_initialization_and_destruction_0(int, int)
        pop     rbp
        ret
a) Can you please specify what exactly you want, i'm not able to identify what exactly you are looing for.