gitweb on Svarog
projekti pod git sistemom za održavanje verzija -- projects under the git version control systemdiff --git a/samples-with-macros/array-sum-predef.asm b/samples-with-macros/array-sum-predef.asm
--- /dev/null
@@ -0,0 +1,83 @@
+.model small\r
+;make a sum of an array - version with predefined everything\r
+\r
+;#macro-commands-start\r
+end_execution macro\r
+; finish the execution\r
+ mov ax, 4c02h\r
+ int 21h\r
+endm \r
+\r
+print_str macro s\r
+; print a s string on screen\r
+ push ax\r
+ push dx \r
+ mov dx, offset s\r
+ mov ah, 09\r
+ int 21h\r
+ pop dx\r
+ pop ax\r
+endm\r
+\r
+inttostr macro num1 str1\r
+; convert num1 to str1\r
+ push ax\r
+ push bx\r
+ push cx\r
+ push dx\r
+ push si\r
+ mov ax, num1\r
+ mov dl, '$'\r
+ push dx\r
+ mov si, 10\r
+itosloop:\r
+ mov dx, 0\r
+ div si\r
+ add dx, 48\r
+ push dx\r
+ cmp ax, 0\r
+ jne itosloop\r
+ \r
+ mov bx, offset str1\r
+itosloopa: \r
+ pop dx\r
+ mov [bx], dl\r
+ inc bx\r
+ cmp dl, '$'\r
+ jne itosloopa\r
+ pop si \r
+ pop dx\r
+ pop cx\r
+ pop bx\r
+ pop ax \r
+endm\r
+\r
+print_num macro num\r
+ ;convert num, print str\r
+ inttostr num,tempStr\r
+ print_str tempStr\r
+endm\r
+;#macro-commands-end\r
+\r
+.code\r
+start:\r
+ mov dx, @data\r
+ mov ds, dx \r
+ mov cx, n\r
+ mov ax, 0\r
+ mov dx, 0\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
+niz db 1,2,3,4,5,6,7,0 \r
+tempStr db " "\r
+\r
+ends\r
+end start\r