gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
version 0.81
[asm2wsl.git] / samples-with-macros / array-sum-predef.asm
1 .model small
2 ;make a sum of an array - version with predefined everything
4 ;#macro-commands-start
5 end_execution macro
6 ; finish the execution
7 mov ax, 4c02h
8 int 21h
9 endm
11 print_str macro s
12 ; print a s string on screen
13 push ax
14 push dx
15 mov dx, offset s
16 mov ah, 09
17 int 21h
18 pop dx
19 pop ax
20 endm
22 inttostr macro num1 str1
23 ; convert num1 to str1
24 push ax
25 push bx
26 push cx
27 push dx
28 push si
29 mov ax, num1
30 mov dl, '$'
31 push dx
32 mov si, 10
33 itosloop:
34 mov dx, 0
35 div si
36 add dx, 48
37 push dx
38 cmp ax, 0
39 jne itosloop
41 mov bx, offset str1
42 itosloopa:
43 pop dx
44 mov [bx], dl
45 inc bx
46 cmp dl, '$'
47 jne itosloopa
48 pop si
49 pop dx
50 pop cx
51 pop bx
52 pop ax
53 endm
55 print_num macro num
56 ;convert num, print str
57 inttostr num,tempStr
58 print_str tempStr
59 endm
60 ;#macro-commands-end
62 .code
63 start:
64 mov dx, @data
65 mov ds, dx
66 mov cx, n
67 mov ax, 0
68 mov dx, 0
69 mainloop:
70 mov bx, cx
71 add al, niz[bx-1] ; get array memeber, byte
72 ; store sum in al
73 loop mainloop ; end calc if done
74 print_num ax
75 end_execution
77 data segment
78 n dw 7
79 niz db 1,2,3,4,5,6,7,0
80 tempStr db " "
82 ends
83 end start
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner