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 / rek-gcd-predef.asm
1 .model small
2 ;recursive version of GCD, predefined input
3 data segment
4 strNZD db " "
5 data ends
6 ;#macro-commands-start
7 ; print a string on screen
8 print_str macro s
9 push ax
10 push dx
11 mov dx, offset s
12 mov ah, 09
13 int 21h
14 pop dx
15 pop ax
16 endm
19 ; write a single char
20 print_char macro c
21 push ax
22 push dx
23 mov ah, 02
24 mov dl, c
25 int 21h
26 pop dx
27 pop ax
28 endm
30 ; finish the execution
31 end_execution macro
32 mov ax, 4c02h
33 int 21h
34 endm
36 ; Konvertovanje broja u string
37 inttostr macro num1 str1
38 push ax
39 push bx
40 push cx
41 push dx
42 push si
43 mov ax, num1
44 mov dl, '$'
45 push dx
46 mov si, 10
47 petlja2:
48 mov dx, 0
49 div si
50 add dx, 48
51 push dx
52 cmp ax, 0
53 jne petlja2
55 mov bx, offset str1
56 petlja2a:
57 pop dx
58 mov [bx], dl
59 inc bx
60 cmp dl, '$'
61 jne petlja2a
62 pop si
63 pop dx
64 pop cx
65 pop bx
66 pop ax
67 endm
69 print_num macro num
70 inttostr num,strNZD
71 print_str strNZD
72 endm
73 ;#macro-commands-end
75 .code
77 start:
78 push 8
79 push 12
80 call gcd
81 pop ax
82 print_num ax
83 ; print out a result
84 end_execution
86 ;volatile procedure, ruins ax,bx,cx
87 gcd proc
88 ;#extra-start
89 pop cx ;ret adress
90 ;#extra-end
91 ;get params
92 pop ax
93 pop bx
94 ;#extra-start
95 push cx ;ret for later
96 ;#extra-end
97 cmp ax,bx
98 je endequal
99 ja greatera
100 ;ensure ax is greater
101 xchg ax,bx
102 greatera:
103 sub ax,bx
104 push bx
105 push ax
106 call gcd
107 pop ax;result
109 endequal:
110 ;#extra-start
111 pop cx
112 ;#extra-end
113 push ax; result
114 ;#extra-start
115 push cx;needed before ret
116 ;#extra-end
117 ret
118 gcd endp
119 .stack
120 end start
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner