Question

In: Computer Science

6.) Write the assembly code for the following piece of code. Note: r,g,y,z correlate with the...

6.) Write the assembly code for the following piece of code. Note: r,g,y,z correlate with the w4, w8, w11, and w15.

if (g * y > 25) || (y == z / 8) && (y * 4 < z - g))
        y = r / 32;
else
        g = 8 * (r - z);

Solutions

Expert Solution

      ##Intel asm Syntax    Compiler:x86-64 gcc 10.2
        
  ## if (g * y > 25) || (y == z / 8) && (y * 4 < z - g))
        mov     eax, DWORD PTR [rbp-4] 
        imul    eax, DWORD PTR [rbp-8]          
        mov     eax, DWORD PTR [rbp-12]          
        lea     edx, [rax+7]
        test    eax, eax                         
        cmovs   eax, edx
        sar     eax, 3
        cmp     DWORD PTR [rbp-8], eax                 
        jne     .L3
        mov     eax, DWORD PTR [rbp-8]
        lea     edx, [0+rax*4]
        mov     eax, DWORD PTR [rbp-12]
        sub     eax, DWORD PTR [rbp-4]
        cmp     edx, eax
        jge     .L3

  ## y = r / 32;
        mov     eax, DWORD PTR [rbp-16]                   
        lea     edx, [rax+31]
        test    eax, eax
        cmovs   eax, edx
        sar     eax, 5
        mov     DWORD PTR [rbp-8], eax
        jmp     .L4


  ## g = 8 * (r - z);   
        mov     eax, DWORD PTR [rbp-16]                                          
        sub     eax, DWORD PTR [rbp-12]
        sal     eax, 3
        mov     DWORD PTR [rbp-4], eax



Related Solutions

Exercise #1:  Write MARIE assembly language code to input 3 values into variables x, y, and z,...
Exercise #1:  Write MARIE assembly language code to input 3 values into variables x, y, and z, calculate x + y -z, and outputs the result. Run your code in the simulator and submit a screen shot of your program run and the code. //x + y -z ORG 100     INPUT     STORE X     INPUT     STORE Y     INPUT     STORE Z     LOAD X     ADD Y     SUBT Z     OUTPUT     Halt X, Dec 0 Y, DEC 0 Z, DEC 0 Exercise #2: Write MARIE assembly...
Write the following code in ARM assembly code g=12, h=8, i=2, j=5; f = (g +...
Write the following code in ARM assembly code g=12, h=8, i=2, j=5; f = (g + h) - (i + j); Your program displays the message: f = (g + h) – (i + j) = 13 Note that 13 should be calculated, not hardcoded
Write assembly code for the following machine code. Assume that the segment is placed starting at...
Write assembly code for the following machine code. Assume that the segment is placed starting at location 80000. Create labels for jump and branch instructions. Indicate the actual memory addresses represented by such labels. 0010 1010 0000 1000 0000 0000 0000 1010 0001 0001 0000 0000 0000 0000 0000 0010 0000 0010 0001 0001 1000 0000 0010 0000 0000 1000 0000 0000 0100 1110 0010 0101 0000 0010 0001 0010 1000 0000 0010 0000
a. Write machine code for the following assembly code. Assume that the segment is placed starting...
a. Write machine code for the following assembly code. Assume that the segment is placed starting at location 80000. Use decimal numbers to represent each instruction. loop:         beq $s3, $s1, endwhile                  add $t0, $s3, $s4                  lw $t1, 0($t0)                  add $s0, $s0, $t1                  addi $s3, $s3, 4                  j loop endwhile: b. Write assembly code for the following machine code. Assume that the segment is placed starting at location 80000. Create labels for jump and branch instructions. Indicate the actual...
1.) Translate the following C code to MIPS assembly code. Assume that the variables f, g,...
1.) Translate the following C code to MIPS assembly code. Assume that the variables f, g, h, i, and j are assigned to registers $s0, $s1, $s2, $s3, and $s4, respectively. Assume that the base address of the arrays A and B are in registers $s6 and $s7, respectively   B[8] = A[i-j]; 2.Translate the following C code to MIPS assembly code. Assume that the values of v in $a0, k in $a1, temp in $t0.    // leaf procedure that...
Write MIPS assembly code for the following C code. for (i = 10; i < 30;...
Write MIPS assembly code for the following C code. for (i = 10; i < 30; i ++) { if ((ar[i] > b) || (ar[i] <= c)) ar[i] = 0; else ar[i] = a; }
(6) Define a binary operation ∗ on the set G = R^2 by (x, y) ∗...
(6) Define a binary operation ∗ on the set G = R^2 by (x, y) ∗ (x', y') = (x + x', y + y'e^x) (a) Show that (G, ∗) is a group. Specifically, prove that the associative law holds, find the identity e, and find the inverse of (x, y) ∈ G. (b) Show that the group G is not abelian. (c). Show that the set H= (x*x=e) is a subgroup of G.
Consider the scalar functions f(x,y,z)g(x,y,z)=x^2+y^2+z^2, g(x,y,z)=xy+xz+yz, and=h(x,y,z)=√xyz Which of the three vector fields ∇f∇f, ∇g∇g and...
Consider the scalar functions f(x,y,z)g(x,y,z)=x^2+y^2+z^2, g(x,y,z)=xy+xz+yz, and=h(x,y,z)=√xyz Which of the three vector fields ∇f∇f, ∇g∇g and ∇h∇h are conservative?
Let G be a bipartite graph and r ∈ Z>0. Prove that if G is r-regular,...
Let G be a bipartite graph and r ∈ Z>0. Prove that if G is r-regular, then G has a perfect matching. HINT:  Use the Marriage Theorem and the Pigeonhole Principle. Recall that G is r-regular means every vertex of G has degree
How to write fill.asm code (hack assembly)
How to write fill.asm code (hack assembly)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT