gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
version 0.81
[asm2wsl.git] / samples / array-sum-input.asm
diff --git a/samples/array-sum-input.asm b/samples/array-sum-input.asm
new file mode 100644 (file)
index 0000000..666a3f3
--- /dev/null
@@ -0,0 +1,53 @@
+.model small\r
+;make a sum of an array - version with loading values\r
+;predefined array size\r
+\r
+;#macros-removed-from-listing
+\r
+.code\r
+start:\r
+        mov dx, @data\r
+        mov ds, dx \r
+        print_str prompt\r
+        read_num n\r
+        mov ax, 0\r
+        mov cx, n\r
+        cmp maxn, cx\r
+        jae normal\r
+        print_str errorN\r
+        end_execution\r
+normal:          \r
+loadloop:\r
+        print_str prompt\r
+        read_num t\r
+        mov ax,t\r
+        mov bx,n\r
+        sub bx,cx\r
+        mov niz[bx],al\r
+        loop loadloop\r
+        print_new_line\r
+        ; now sum up\r
+        mov cx, n\r
+        xor ax,ax\r
+mainloop:              \r
+        mov bx, cx\r
+        add al, niz[bx-1]   ; get array memeber, byte\r
+        ; store sum in al\r
+        loop mainloop         ; end calc if done\r
+        print_num ax\r
+        end_execution\r
+\r
+data segment\r
+n       dw  7\r
+t       dw  0\r
+maxn    dw  20\r
+niz     db  1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0     \r
+tempStr db "        "\r
+prompt db "Number?$"\r
+errorN db "Number too large!$"\r
+ends\r
+end start\r
+\r
+\r
+\r
+\r
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner