-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmacros.asm
More file actions
83 lines (67 loc) · 1.51 KB
/
Copy pathmacros.asm
File metadata and controls
83 lines (67 loc) · 1.51 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
%macro _prologue 0
push ebp
mov ebp, esp
%endmacro
%macro _epilogue 0
leave
ret
%endmacro
%macro ?call 2 ;@call function error
call %1
cmp eax, 0
jl %2
%endmacro
%macro @call1 2 ;@call1 function input
push %2
call %1
add esp, 4
%endmacro
%macro @call1 3 ;@call1 function input recover
push %2 ;arguments gets popped into recover
call %1 ;do not recover into return register
pop %3
%endmacro
%macro ?call1 3 ;?call1 func, arg1, error
@call1 %1, %2
cmp eax, 0
jl %3
%endmacro
%macro ?call1 4 ;?call1 func, arg1, error, recover
@call1 %1, %2, %4
cmp eax, 0
jl %3
%endmacro
%macro ?call2 4 ;?call2 func, arg1, arg2, error
push %3
push %2
call %1
add esp, 8
cmp eax, 0
jl %4
%endmacro
%macro ?call3 5 ;?call3 func, arg1, arg2, arg3, error
push %4
push %3
push %2
call %1
add esp, 12
cmp eax, 0
jl %5
%endmacro
%define _arg(n) ebp + 8 + 4*(n)
%define _ARG(n) [_arg(n)]
%define _slot(n) ebp - 4*(n)
%define _SLOT(n) [_slot(n)]
;defines a macro name(input, err) that expands to ?call1 function, name, err
%macro FALLIBLE1 2 ;FALLIBLE1 name, function
%define %1(input, err) ?call1 %2, input, err
%endmacro
%macro FALLIBLE2 2 ;FALLIBLE2 name, function
%define %1(input1, input2, err) ?call2 %2, input1, input2, err
%endmacro
%macro FALLIBLE3 2 ;FALLIBLE3 name, function
%define %1(input1, input2, input3, err) ?call3 %2, input1, input2, input3, err
%endmacro
%macro FUNCTION1 2
%define %1(input) @call1 %2, input
%endmacro