summing an array

  1. Include Irvine32.inc
  2. .data
  3.     total byte "result : "0dh0ah0
  4.     intarray dword 1234
  5.     sum dword 0
  6. .code
  7.     main proc
  8.     mov esi, offset intarray        ; ESI = address of intarray
  9.     mov ecx, lengthof intarray      ; length of intarray
  10.     mov eax, 0
  11.     mov ebx, 0
  12.     L1:
  13.     add eax, [esi]                  ; add an array index
  14.     add esi, type intarray          ; point to next element
  15.     add sum, eax
  16.     call writeint
  17.     call crlf
  18.     Loop L1                         ; repeat until ecx == 0
  19.     mov edx, offset total
  20.     call writestring
  21.     mov ebx, sum
  22.     call writeint
  23.     exit
  24.     main endp
  25.     end main


留言

這個網誌中的熱門文章

Codeforces --- string task

Uva 674 ---- coin change

codeforces 271A --- beautiful year