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 / gcd-predef.asm
1 .model small
2 data segment
3 strNZD db " "
4 data ends
5 ;#macro-commands-start
6 ; print a string on screen
7 print_str macro s
8 push ax
9 push dx
10 mov dx, offset s
11 mov ah, 09
12 int 21h
13 pop dx
14 pop ax
15 endm
18 ; write a single char
19 print_char macro c
20 push ax
21 push dx
22 mov ah, 02
23 mov dl, c
24 int 21h
25 pop dx
26 pop ax
27 endm
29 ; finish the execution
30 end_execution macro
31 mov ax, 4c02h
32 int 21h
33 endm
35 ; Konvertovanje broja u string
36 inttostr macro num1 str1
37 push ax
38 push bx
39 push cx
40 push dx
41 push si
42 mov ax, num1
43 mov dl, '$'
44 push dx
45 mov si, 10
46 petlja2:
47 mov dx, 0
48 div si
49 add dx, 48
50 push dx
51 cmp ax, 0
52 jne petlja2
54 mov bx, offset str1
55 petlja2a:
56 pop dx
57 mov [bx], dl
58 inc bx
59 cmp dl, '$'
60 jne petlja2a
61 pop si
62 pop dx
63 pop cx
64 pop bx
65 pop ax
66 endm
68 print_num macro num
69 inttostr num,strNZD
70 print_str strNZD
71 endm
72 ;#macro-commands-end
74 .code
76 start:
77 mov ax,12
78 mov bx,8
80 compare:
81 cmp ax,bx
82 je exit ;exit since they're equal
83 ja greater
84 sub bx,ax
85 jmp compare
87 greater:
88 sub ax,bx
89 jmp compare
91 exit:
92 ;exit out of the program
93 print_num ax
94 ; print out a result
95 end_execution
97 .stack
98 end start
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner