A
A
Alexey Mairin2018-03-08 10:01:41
assembler
Alexey Mairin, 2018-03-08 10:01:41

What's wrong with finding elements on assembler?

Hello! I ask for help in solving the problem of forming an array from 2 others (by searching for the maximum element) example: result[i] =max(array1[i], array2[i])
It seems like I wrote everything with comments
But it basically does not work

_asm finit
    _asm {
      xor esi,esi//обнуляю
      xor ecx,ecx//обнуляю
      loopForI://цикл для прохода по массивам
      mov ax, firstArray[esi]//заношу "i"эллемент
        loopForJ//цикл для сравнение итого со всеми житыми
      mov bx, secondArray[ebp]//заношу "j"эллемент
      cmp ax,bx//сравниваю
      jg max //если больше, то пушу в стек
      cmp bx,ax// сравниваю
      jg min // если больше, житый, то пушу его
      inc ebp// нарашиваю "j"
        loop loopForJ//внутренний цикл по j
      loop loopForI// общий цикл по i

      min:
        push bx//пушу в стек
        inc esi//нарашиваю "i"
        xor ebp,ebp//"зануляю j"
        jmp loopForI//"прыгаю снова на большой цикл"
      max ://Тоже, что и в min
        push ax
        inc esi
        xor ebp, ebp
      jmp loopForI

        xor esi,esi//занулил
        poploop://цикл по стеку
      pop maxArray[esi]//попнул в массив максимальных
        loop poploop
    
  }
  __asm fwait

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Saboteur, 2018-03-08
@saboteur_kiev

Well, in principle, the logic of the program is not working for you.
For example, the internal loopForJ, after which in both cases - if the elements are not equal, you reset ebp, so you don’t have to pass through the second array at all.
It's even hard to tell you need to redo everything.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question