gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
version 0.81
[asm2wsl.git] / samples / sumn-stack-prompt.asm
diff --git a/samples/sumn-stack-prompt.asm b/samples/sumn-stack-prompt.asm
new file mode 100644 (file)
index 0000000..52ce6ea
--- /dev/null
@@ -0,0 +1,44 @@
+.model      small\r
+;#macros-removed-from-listing
+\r
+.code\r
+;read_num, print_num, etc are macros\r
+\r
+start:  \r
+    mov ax, data\r
+    mov ds, ax            \r
+    print_str prompt\r
+    read_num n\r
+    mov cx, n\r
+l1:                 \r
+    print_str prompt\r
+       read_num num\r
+       push num\r
+       loop l1\r
+       ; now sum up the top n from the stack\r
+    mov cx, n\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
+       ; result            \r
+       print_new_line\r
+       print_str resStr\r
+       print_num dx\r
+end1:\r
+       nop\r
+       end_execution\r
+\r
+\r
+.data\r
+       num dw 12\r
+       n dw 3\r
+       rez dw 0 \r
+       tempStr db "        "\r
+       prompt  db "number? $"\r
+       resStr  db "result $"\r
+\r
+.stack\r
+end start\r
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner