I
I
Irina2020-01-21 15:09:33
C++ / C#
Irina, 2020-01-21 15:09:33

How to solve the problem of working with two arrays in asm?

Good afternoon!
I need to write a program where I have an array of 16(32) bytes. It is necessary to move this array from c ++ to an assembler insert, and there already transfer all elements that are equal to the sum of neighboring ones from this array to another array. It is possible to use a maximum of double words in assembler. That is, e*x registers cannot be taken. Who can tell where to find material on this topic, or offer a code example to solve the problem? I tried to find something on the Internet on this topic, but, unfortunately, I did not find anything :(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2020-01-21
@SirenaProgrammer

It is necessary to move this array from c ++ to an assembler insert, and there already transfer all elements that are equal to the sum of neighboring ones from this array to another array.
That is, e*x registers cannot be taken. Who can tell where to find material on this topic, or offer a code example to solve the problem?

It is possible to write this code in such a way that it does not explicitly use any specific registers. Specific registers will be substituted by the compiler. For example (gcc):
#include <stdint.h>

void f(void)
{
    uint32_t a[16] = {1, 2, 3, 1, 5, 4, -1, }, b[16] = {0};
    void *a1, *b1;
    uint32_t tmp, cnt = 14;

    asm (
        "lea %[a], %[a1]\n\t"
        "lea %[b], %[b1]\n"
        "1:\n\t"
        "mov (%[a1]), %[tmp]\n\t"
        "add 8(%[a1]), %[tmp]\n\t"
        "cmp 4(%[a1]), %[tmp]\n\t"
        "jne 2f\n\t"
        "mov %[tmp], (%[b1])\n\t"
        "add $4, %[b1]\n"
        "2:\n\t"
        "add $4, %[a1]\n\t"
        "dec %[cnt]\n\t"
        "jnz 1b\n\t"
        : [cnt] "=&r" (cnt), [tmp] "=&r" (tmp),
          [a1] "=&r" (a1), [b1] "=&r" (b1),
          [b] "=m" (b)
        : [a] "m" (a));
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question