Question

In: Computer Science

In assembly level, a code of loop structure can be either implemented using a \branch forward"...

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

Solutions

Expert Solution

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.


Related Solutions

Can you rewrite this MATLAB code using a for loop instead of a while loop? %formatting...
Can you rewrite this MATLAB code using a for loop instead of a while loop? %formatting clc, clear, format compact; %define variables k=1; b=-2; x=-1; y=-2; %while loop initialization for k <= 3 disp([num2str(k), ' ',num2str(b),' ',num2str(x),' ',num2str(y),]); y = x^2 -3; if y< b b = y; end x = x+1; k = k+1; end
International Taxation Question A foreign corporation can structure its U.S. operations as either a branch or...
International Taxation Question A foreign corporation can structure its U.S. operations as either a branch or a subsidiary. What are the tax advantages of operating in the United States through a separately incorporated subsidiary? What are the tax advantages of operating in the United States through an unincorporated branch? What general business factors should be considered when choosing between the branch and subsidiary forms of doing business in the United States?
write mips assembly mips assembly (x+a) (bx^2+cx+d) using the pesedo- code with loop ,program should claclute...
write mips assembly mips assembly (x+a) (bx^2+cx+d) using the pesedo- code with loop ,program should claclute six T[i] and display aproper message about roots .the the program should store all T[i] as memory array a = [1, 1, 1, 1, 1, 1]; b = [1, 2, 4, 8, 16, 32]; c = [-6, -4, -2, 2, 4, 6]; d = [-1, -3, -5, -7, -9, -11]; for (i=0 ; i<=6; i++) { T[i] =-4 *b [i] * d[i] +c[i] *...
Translate the following C code into MIPS Assembly code, assuming Loop Variable k is in $s0...
Translate the following C code into MIPS Assembly code, assuming Loop Variable k is in $s0 and initially containing 0 . Also assume base of array Arr is in $s3 while ( k < = 10 ) { Arr[k] = k ; k = k + 1; }
Use Java to rewrite the following pseudo-code segment using a loop structure without goto, break, or...
Use Java to rewrite the following pseudo-code segment using a loop structure without goto, break, or any other unconditional branching statement: k = (j+13)/27; //assume i,j,k are integers properly declared. loop: if k > 10 then goto out k=k+1.2; i=3*k-1; goto loop; out: …
MIPS assembly code: procedure:                   addi $s0,$zero,0 loop:                   slt
MIPS assembly code: procedure:                   addi $s0,$zero,0 loop:                   slti $t1, $s0, 7                   beq $t1, $zero, exit                   addi $s0,$s0,1                   j loop exit:                   add $v0, $zero, $s0                   jr $ra       What is the corresponding high-level programming language code? Write a code in your preferred language. What is the result? (5 pts) Code: int add(int a, int b) {       return a+b; } int sub(int a, int b) {      ...
Write a python code which prints triangle of stars using a loop ( for loop )...
Write a python code which prints triangle of stars using a loop ( for loop ) Remember what 5 * "*" does The number of lines of output should be determined by the user. For example, if the user enters 3, your output should be: * ** *** If the user enters 6, the output should be: * ** *** **** ***** ****** You do NOT need to check for valid input in this program. You may assume the user...
Create Python Code using a "for" loop and a "while" loop. You are starting a twelve...
Create Python Code using a "for" loop and a "while" loop. You are starting a twelve week program training to compete in a triathlon. The triathlon consists of three athletic events, 1.5 k swim, 40k bike, 10k run. In order to be prepared for the competition you want to print a training schedule. Starting with week 1 you will increase the distance of each activity so that you reach the race distance by week twelve. Due to rounding, you may...
Code using assembly language Create a program using the Irvine32 procedures were the user can input...
Code using assembly language Create a program using the Irvine32 procedures were the user can input a list of 32-bit unsigned integers an “x” number of times, then display these integers to the console in reverse order. Hint: Use loops and PUSH & POP instructions. Extra Challenge: Inform the user with a message what to do; also, tell them what they are seeing.
Write an assembly program (Data and Code) that uses loop to read 10 numbers and output...
Write an assembly program (Data and Code) that uses loop to read 10 numbers and output the largest of those numbers, you can assume any length for those numbers. 80x86 assembly language
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT