-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctions.asm
More file actions
137 lines (115 loc) · 1.65 KB
/
Functions.asm
File metadata and controls
137 lines (115 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
;FUNCTION;
factorial:
; calculates factorial of an input, eax -> eax
cmp eax, 2
jge calculate_factorial
; default return 1
mov eax, 1
ret
calculate_factorial:
mov ecx, eax
dec ecx
; for(ecx = n; ecx > 0; ecx--)
factorial_loop:
mul ecx
loop factorial_loop
ret
;FUNCTION;
print_int:
; prints integer from eax
push eax
mov ebx, format
mov byte [ebx + 1], 'd'
push format
call _printf
add esp, 8
ret
;FUNCTION;
print_float:
; prints float from eax
mov [__temp], eax
fld dword [__temp]
sub esp, 8
fstp qword [esp]
mov ebx, format
mov byte [ebx + 1], 'f'
push format
call _printf
add esp, 12
ret
;FUNCTION;
print_bool:
; prints bool from eax
push true_string ; default true
; check if false
cmp eax, 0
jne skip_false
; is false
mov [esp], dword false_string
skip_false:
mov ebx, format
mov byte [ebx + 1], 's'
push format
call _printf
add esp, 8
ret
;FUNCTION;
print_char:
; prints char from eax
mov ebx, format
mov byte [ebx + 1], 'c'
push eax
push format
call _printf
add esp, 8
ret
;FUNCTION;
print_ptr:
; prints pointer from eax
push eax
mov ebx, format
mov byte [ebx + 1], 'x'
push hex_str
call _printf
add esp, 4
push format
call _printf
add esp, 8
ret
;FUNCTION;
print_str:
; prints string from eax
mov ebx, format
mov byte [ebx + 1], 's'
push eax
push format
call _printf
add esp, 8
ret
;FUNCTION;
pow:
; calculates eax = eax ** ebx
fxch st1
fyl2x
fld1
fld st1
fprem
f2xm1
fadd
fscale
fxch st1
fstp st0
ret
;FUNCTION;
input_int:
; int input into eax
mov ebx, formatin
mov byte[ebx + 1], 'd'
sub esp, 4
push esp
push formatin
call _scanf
add esp, 8
pop eax
ret
extern _scanf