Question: Write the required embedded (_asm) assembler code for each section in the corresponding inline assembler blocks denoted by the _asm keyword. See the example displayed

Write the required embedded (_asm) assembler code for each section in the corresponding inline assembler blocks denoted by the _asm keyword.

See the example displayed output at the end of this assignment for guidance.

Shift to load Bytes

Write assembler code to put the values of the C++ constants byte0, byte1, byte2, and byte3 into the C++ memory variable uint32_t resultUInt32.

The bytes have to be in the following order in resultUInt32 that is displayed in hex by the C++ part of the program:

11223344

Endianess

Step through the C++ memory constant uint32_t source32Bit (0x44332211) in a byte wise manner from the lowest to the highest byte address and put the byte results into the following C++ variables:

uint8_t lowestAddressByte0Up, lowestAddressByte1Up, lowestAddressByte2Up, lowestAddressByte3Up;

Powers of 2 Multiply and Divide

The C++ code will prompt the user to enter a multiplier 1, then prompt for an exponent for a base 2 multiplier.

Write the required assembler code in the _asm code block to put the results to the C++ variable product that gets displayed by the C++ code.

The C++ code will prompt the user to enter a dividend, then then prompt for an exponent for a base 2 divisor.

Write the required assembler code in the _asm code block to put the results to the C++ variable quotient that gets displayed by the C++ code.

Use logical shifts to execute the operations for the base 2 multiply and base 2 divide.

Sample Test Run Output:

Byte 0 is 11

Byte 1 is 22

Byte 2 is 33

Byte 3 is 44

The placement result is 11223344

In Memory little endian storage for 44332211(LSB on right side)

The lowest address byte is 11

The next up address byte is 22

The next up address byte is 33

The next up address byte is 44

Enter an integer > = 0 for multiplicand : 5

Enter an integer > = 0 to be an exponent for base 2 multiplier : 3

Multiplicand 5 x 2 to the power of 3 = 40

Enter an integer > = 0 for dividend : 16

Enter an integer > = 0 to be an exponent for base 2 divisor : 3

Dividend 16 / 2 to the power of 3 = 2

Press any key to continue . . .

this my code

#include "stdafx.h"

#include

#include

#include

using namespace std;

void main()

{

const uint8_t byte0(0x11), byte1(0x22), byte2(0x33), byte3(0x44);

uint32_t resultUInt32(0);

cout << hex;

cout << "Byte 0 is " << (unsigned)byte0 << endl;

cout << "Byte 1 is " << (unsigned)byte1 << endl;

cout << "Byte 2 is " << (unsigned)byte2 << endl;

cout << "Byte 3 is " << (unsigned)byte3 << endl << endl;

_asm {

; Put the values of byte0, byte1, byte2, and byte3 into the C++ memory variable uint32_t resultUInt32.

; the order in the memory variable from most significant to least should be byte0 byte1 byte2 byte3

}

cout << "The placement result is " << resultUInt32 << endl << endl;

const uint32_t source32Bit(0x44332211);

uint8_t lowestAddressByte0Up = 0, lowestAddressByte1Up = 0, lowestAddressByte2Up = 0, lowestAddressByte3Up = 0;

_asm {

; Step through by byte sizes the memory constant uint32_t source32Bit(0x44332211) from the lowest to the highest byte address

; and put the byte results into the coresponding C++ variables

}

cout << "In Memory little endian storage for " << source32Bit << "(LSB on right side)" << endl << endl;

cout << "The lowest address byte is " << (unsigned)lowestAddressByte0Up << endl;

cout << "The next up address byte is " << (unsigned)lowestAddressByte1Up << endl;

cout << "The next up address byte is " << (unsigned)lowestAddressByte2Up << endl;

cout << "The next up address byte is " << (unsigned)lowestAddressByte3Up << endl << endl;

cout << dec;

uint32_t multiplicand,

exponentforBase2Multiplier,

product;

cout << "Enter an integer > = 0 for multiplicand : "; cin >> multiplicand;

cout << "Enter an integer > = 0 to be an exponent for base 2 multiplier : "; cin >> exponentforBase2Multiplier;

_asm {

; use shift opertor to mutiply by power of 2

}

cout << "Multiplicand " << multiplicand << " x 2 to the power of " << exponentforBase2Multiplier << " = " << product << endl << endl;

uint32_t dividend,

exponentforBase2Divisor,

quotient;

cout << "Enter an integer > = 0 for dividend : "; cin >> dividend;

cout << "Enter an integer > = 0 to be an exponent for base 2 divisor : "; cin >> exponentforBase2Divisor;

_asm {

; use shift opertor to divide by power of 2

}

cout << "Dividend " << dividend << " / 2 to the power of " << exponentforBase2Divisor << " = " << quotient << endl << endl;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!