gitweb on Svarog
projekti pod git sistemom za održavanje verzija -- projects under the git version control systemdiff --git a/samples/sumn3.asm b/samples/sumn3.asm
--- /dev/null
+++ b/samples/sumn3.asm
@@ -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