Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use the associated .cpp file to execute the assignment. Write assembler code to

ID: 667712 • Letter: U

Question

Use the associated .cpp file to execute the assignment.

Write assembler code to put the values of byte1, byte2, byte3, and byte4 into the C++ memory variable resultUInt32. The bytes have to be in the following order when resultUInt32 is displayed in hex by the C++ part of the program: 11223344

#include "stdafx.h"

#include <iostream>

#include <cstdint>

using namespace std;

void main() {

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

uint32_t resultUInt32(0);

_asm {

mov ah, byte1

mov al, byte2

shl eax, 16

mov ah, byte3

mov al, byte4

mov resultUInt32, eax

}

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

}

Explanation / Answer

I have marked the changes in bold, and the solution is quite clear. Please let me know if you still want some explanation.

#include "stdafx.h"
#include <iostream>
#include <cstdint>

using namespace std;

void main() {
//const uint8_t byte1(0x11), byte2(0x22), byte3(0x33), byte4(0x44);
const uint8_t byte1 = 0x11, byte2 = 0x22, byte3 = 0x33, byte4 = 0x44;
//uint32_t resultUInt32(0);
uint32_t resultUInt32 = 0;

_asm {
mov eax,byte1
shl eax 8
OR eax byte2
shl eax 8
OR eax byte3
shl eax 8
OR eax byte4
mov resultUInt32, eax
};

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

}