ASSEMBLER MODULE Win32 Console Application solution in the M

ASSEMBLER MODULE (Win32 Console Application solution in the Microsoft Visual Studio)

Step1: Count the number of odd values (n mod 2 <> 0) for each row.

Use template the following template below as a base for the solution!

Important: All calculations, conditions and jumps must be implemented only with Inline or full assembler!

#include \"stdafx.h\"

#include

#include

void solution_for_grade_7(const int * arr, size_t arr_rows, size_t arr_cols, int * result)

{

    __asm

    {

        // Your Inline Assembler instructions for grade 7 level go here

        // :::

    }

}

const int ROWS = 2;

const int COLS = 3;

int main()

{

    // Change the array definitions to be appropriate for your assignments:

    int data1[ROWS][COLS] = { { 0, -1, 2 }, { 3, 4, -5 } };

    int result1[ROWS]; // Note: for some assignments the result size will depend on the COLS!

    // Change the parameters according to your assignment function, e.g.:

    solution_for_grade_7((const int *)data1, ROWS, COLS, result1);

    // Print the result one-dimensional array to the console:

    for (size_t i = 0; i < ROWS; i++)

        printf(\"%d \", res1[i]);

    // :::

    return 0;

}

Step2: Implement task (Count the number of odd values (n mod 2 <> 0) for each row) and place them in separate assembler module (in file with extension .ASM) and use the template below for assembler module.

Important: Demonstrate assembler module by calling procedures from the C/C++ code.

.586

.model flat, C

.code

SolutionForGrade7 PROC PUBLIC USES ...

[LOCAL ...]

:::

ret

SolutionForGrade7 ENDP

:::

END

Solution

Answer

The required is as below:

#include \"stdafx.h\"
#include <cstdio>
#include <cassert>

// Variant implement own function for each grade level , e.g.:
void solution_for_grade_7(const int* arr, size_t arr_rows,                        size_t arr_cols, int* result)
{
int counter = 0;
int modNumb = 2;
__asm
{

  
mov ecx, [arr_rows] // ecx == for(int ROWS = 2;----;----;)
Loop_for_Row:
mov ebx, arr //defining arr here
push ecx //saving row loop counter
xor esi, esi
mov ecx, [arr_cols]
Loop_for_Col :
xor edx, edx
mov eax, dword ptr[ebx + esi] // eax = arr[ROWS][n]
idiv[modNumb] // eax = eax mod 2
cmp edx, 0 // (eax mod 2) == 0 ?
je Skip // jump to Skip, if true
inc [counter]
Skip:
add esi, 4
loop Loop_for_Col // repeat (for COL=N;------;-----) loop
add ebx, esi //next row
pop ecx //restore Loop_for_Row counter i.e. ecx = 2
  
//Store the counted odd values into the result1 array
xor edx, edx
xor eax, eax
mov edx, result
mov eax, [counter]
mov [edx + ecx * 4], eax
mov [counter], 0
loop Loop_for_Row
}
}

const int ROWS = 2;
const int COLS = 3;

int main()
{

// Change the array definitions to be appropriate for your assignments:
int data1[ROWS][COLS] = { { 0, -1, 2 }, { 3, 4, -5 } };
int result1[ROWS] = {}; // Note: for some assignments the result will depend on the COLS!

// Change the parameters according to your assignment function, e.g.:
solution_for_grade_7((const int*)data1, ROWS, COLS, result1);

// Print the result one-dimensional array to the console:
for (size_t i = 0; i < ROWS; i++)
{
printf(\"%d \", result1[i]);
}
// :::
getchar();
return 0;
}

ASSEMBLER MODULE (Win32 Console Application solution in the Microsoft Visual Studio) Step1: Count the number of odd values (n mod 2 <> 0) for each row. Us
ASSEMBLER MODULE (Win32 Console Application solution in the Microsoft Visual Studio) Step1: Count the number of odd values (n mod 2 <> 0) for each row. Us
ASSEMBLER MODULE (Win32 Console Application solution in the Microsoft Visual Studio) Step1: Count the number of odd values (n mod 2 <> 0) for each row. Us

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site