A
A
Alertoso2021-04-17 02:08:45
assembler
Alertoso, 2021-04-17 02:08:45

Can I do better?

Can I make this lab better?
Condition: Calculate the sum of the array after the minimum element.

Program Lab6;

{$APPTYPE CONSOLE}

Uses
  Windows;

Const
  N = 10;

Label MinAndMax, M, Exit, sum, m2, exit2;

Var Num1, Num2, Res, I, summ: Integer;
  Arr: Array[1..N] of Integer;
  Min, Max, ResOfSub: Integer;

Begin
  SetConsoleCP(1251);
  SetConsoleOutPutCP(1251);
  Randomize;
  writeln(' ---------------------------------------');
  writeln('|                 Array                 |');
  writeln(' ---------------------------------------');
  for I:=1 to N do
  Begin
    Arr[I]:=Random(100);
    write('|');
    write(Arr[i]:3);
  End;
  write('|');
  writeln;
  ResOfSub:=11;
  writeln(' ---------------------------------------');
  asm
      lea   esi, [arr]
      mov   ecx,  N

      MinAndMax:
          lodsd
          cmp     ebx, eax
          ja      M
          loop    MinAndMax
          jmp     Exit

      M:
          mov   ebx, eax
          mov   edx, ecx
          loop    MinAndMax

      Exit:
      mov   [min], ebx
      sub   [ResOfSub], edx

      lea   esi, [arr]
      mov   ecx,  N
      Sum:
        lodsd
        cmp edx, ecx
        ja   M2
        loop  Sum
        jmp Exit2

      M2:
        add  [summ], eax
        loop  sum

      Exit2:
  End;
  writeln(Min);
  writeln(ResOfSub);
  writeln(summ);
  readln
End.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
VitalyChaikin, 2021-04-19
@VitalyChaikin

cmp ebx, eaxthere is no initialization before the instruction , ebxthis is probably a mistake :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question