Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need help with assembly lanuage plz PART I: Given a 32-bit integer, swap all odd bits with even bits. For example, if the given number

need help with assembly lanuage plz

PART I: Given a 32-bit integer, swap all odd bits with even bits. For example, if the given number is 23 (00010111), it should be converted to 43 (00101011). Every even position bit is swapped with adjacent bit on right side, and every odd position bit is swapped with adjacent on left side. Implementation details: The input integer is stored in registers ebx. You need to store the answer into register eax. Hint: You only need a half-dozen instructions to do this. Think about "clearing" odd (even) bits and using shift (shl, shr) instructions. If we have an 8-bit number 00010111, the expected output is 00101011. Clearing (zeroing) odd bits (7, 5, 3, 1) of 00010111 would make it 00010101. Now if we shift it to the left by one bit, it becomes 00101010. The odd bits of 00101010 are equal to the odd bits of the expected output. They are "0 1 1 1". Using the same technique, generate the even bits of the expected output and then figure out a way for combining generated odd and even bits.

--------------------------------------------------------------------

PART II: You are given three 32-bit signed integers. You need to add the smallest number to the largest number and multiply that sum by 2017. You cannot use mul/imul instructions. Implementation details: The three integers are stored in registers eax, ebx, and ecx. You need to store the answer into register eax. Hint: One way of finding minimum and maximum number is to sort the numbers.

--------------------------------------------------------------------

- Write your assembly code only in the marked blocks.

- Do NOT change anything outside the marked blocks.

- For part II, you are NOT allowed to use any version of the MULTIPLY instruction!

- Remember to fill in your name, student ID below.

*/

char *yourName = ""; char *yourStudentID = "";

/* Implement the body of this function for part I*/ int swapBits(int x) { int result;

__asm { mov ebx, x

// YOUR CODE STARTS HERE

// YOUR CODE ENDS HERE

mov result, eax } return result;

}

/* Implement the body of this function for part II*/ void minMax(int a, int b, int c, int *result) { __asm { mov esi, result

mov eax, a mov ebx, b mov ecx, c

// YOUR CODE STARTS HERE // YOUR CODE ENDS HERE

mov[esi][0], eax }

return; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatio Temporal Database Management International Workshop Stdbm 99 Edinburgh Scotland September 10 11 1999 Proceedings Lncs 1678

Authors: Michael H. Bohlen ,Christian S. Jensen ,Michel O. Scholl

1999th Edition

3540664017, 978-3540664017

More Books

Students also viewed these Databases questions