gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
version 0.81
[asm2wsl.git] / samples / sumn3.asm
diff --git a/samples/sumn3.asm b/samples/sumn3.asm
new file mode 100644 (file)
index 0000000..bd38a4a
--- /dev/null
@@ -0,0 +1,36 @@
+.model      small\r
+.code\r
+;read_num, print_num are macros\r
+        read_num n\r
+       mov cx, n\r
+l1:\r
+       read_num num\r
+       push num\r
+       loop l1\r
+       push n\r
+       call sumn\r
+       pop rez\r
+       print_num rez\r
+end1:\r
+       nop\r
+\r
+sumn   proc\r
+;n is on top of the stack\r
+;sum the next n top elements of the stack\r
+       pop cx \r
+        mov ax, 0\r
+        mov dx, 0\r
+theloop:\r
+        pop ax           ; get next from stack\r
+        add dx, ax        ; array sum is in dx\r
+       loop theloop\r
+       push dx           ; result\r
+           ret\r
+sumn   endp\r
+\r
+.data\r
+       num dw 12\r
+       n dw 3\r
+       rez dw 0 \r
+.stack\r
+end\r
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner