Question

In: Computer Science

Evaluate (3b/2+c)*(6b-a) by writing the code in assembly. where a=2, b=3 and c=5. Write the equivalent...

  1. Evaluate (3b/2+c)*(6b-a) by writing the code in assembly.

where a=2, b=3 and c=5.

  1. Write the equivalent C++ code in assembly language.

if (bx<= ax) && ( cx > dx )

{

ax = 5;

dx = 6;

}

NOTE: Only use 16 bit or 8 bit registers like ax,bx,cx,dx or al,bl,cl,dl. You can either do this using loop statement or conditional or unconditional jmps in assembly language. Keep the code as simple as possible. For question you need to use cmp in assembly language to compare the values. You need to ask from the user the values of ax,bx,cx and dx as input.

Solutions

Expert Solution

       push    rbp
        mov     rbp, rsp
        sub     rsp, 16
        mov     DWORD PTR [rbp-4], 2
        mov     DWORD PTR [rbp-8], 3
        mov     DWORD PTR [rbp-12], 5
        mov     edx, DWORD PTR [rbp-8]
        mov     eax, edx
        add     eax, eax
        add     eax, edx
        mov     edx, eax
        shr     edx, 31
        add     eax, edx
        sar     eax
        mov     edx, eax
        mov     eax, DWORD PTR [rbp-12]
        lea     ecx, [rdx+rax]
        mov     edx, DWORD PTR [rbp-8]
        mov     eax, edx
        add     eax, eax
        add     eax, edx
        add     eax, eax
        sub     eax, DWORD PTR [rbp-4]
        imul    eax, ecx
        mov     DWORD PTR [rbp-16], eax
        mov     eax, DWORD PTR [rbp-16]
        mov     esi, eax
        mov     edi, OFFSET FLAT:_ZSt4cout
        call    std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
        mov     eax, 0
        leave
        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     .L5
        cmp     DWORD PTR [rbp-8], 65535
        jne     .L5
        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
.L5:
        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

Related Solutions

Use synthetic division to find the quotient and the remainder. (2b^4-6b^3+3b+16)/(b-2)
Use synthetic division to find the quotient and the remainder. (2b^4-6b^3+3b+16)/(b-2)
This is to be done with MIPS assembly language. Write MIPS code which is equivalent to...
This is to be done with MIPS assembly language. Write MIPS code which is equivalent to the follow java program: int day = (int)(Math.random() * 7); switch (day) { case 1: System.out.println(“Monday”); break case 2: System.out.println(“Tuesday”); break case 3: System.out.println(“Wednesday”); break case 4: System.out.println(“Thursday”); break case 5: System.out.println(“Friday”); break case 6: System.out.println(“Saturday”); break case 0: System.out.println(“Sunday”); break }
1. Evaluate: (a+b)/(c-d) + 9/(a+d) when a=5, b=3, c=8, d=4 a. 6 b. 3 c. 15/2...
1. Evaluate: (a+b)/(c-d) + 9/(a+d) when a=5, b=3, c=8, d=4 a. 6 b. 3 c. 15/2 d. 17/13 2. Solve for x: 5(x+3) = 35 a. 2 b. 7 c. 4 d. -4 3. Acid rain occurs primarily as a result of a. operating a nuclear power plant b. burning coal or oil containing sulfur c. by-products created by operating an oil refinery d. the use of Freon and other refrigerants 4. The "ozone holes" at the polar region arise...
23. Given a = 5, b = 4, c = 2, evaluate the following: a) a//c...
23. Given a = 5, b = 4, c = 2, evaluate the following: a) a//c b) a % b c) b **c d) b *= c 27. Given the following var_1 = 2.0 var_2 = "apple" var_3 = 'orange' var_4 = 4 Predict the output of the following statements or indicate that there would be an error. a) print (var_1) b) print (var_2) c) print ("var_3") d) print (var_1 / var_4) e) print (var_4 + var_3) f) print (var_2...
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; }
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
2. Translate the following C/Java code to MIPS assembly code. Assume that the values of a,...
2. Translate the following C/Java code to MIPS assembly code. Assume that the values of a, i, and j are in registers $s0, $t0, and $t1, respectively. Assume that register $s2 holds the base address of the array A (add comments to your MIPS code). j = 0; for(i=0 ; i<a ; i++) A[i]=i+j++;
Find 3 definitions of e. Prove they are equivalent (transitivity: a=b, b=c, and a=c) prove the...
Find 3 definitions of e. Prove they are equivalent (transitivity: a=b, b=c, and a=c) prove the 3 defintions of e are equivalent.
2. Mrs. Robinson considers 8 cliffins (c) to be equivalent to 3 wiggins (w): a. Write...
2. Mrs. Robinson considers 8 cliffins (c) to be equivalent to 3 wiggins (w): a. Write down a utility function UR(c, w) that represents Mrs. Robinson’s preferences over cliffins and wiggins. b. The price of cliffins and the price of wiggins are pc and pw, respectively, and Mrs. Robinson has an income equal to Y. Suppose pc/pw =1/4. Solve for Mrs. Robinson’s Marshallian demand functions for cliffins and wiggins. c. Mrs. Banks, a friend of Mrs. Robinson’s, has the following...
Directions: Convert the following problems below to c++ equivalent code Problem 3: Take any 2 digit...
Directions: Convert the following problems below to c++ equivalent code Problem 3: Take any 2 digit number from 31 to 99. (You do not have to check the numbers just assume the user will enter a valid number so long as you tell them to). Store an extra copy of this number for later 3.   Add 82 to the number. 4.    Remove the hundreds place from your number 5.    Add 1 to the number. 6.    Subtract this from your...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT