-
Notifications
You must be signed in to change notification settings - Fork 0
/
cerinta3.asm
174 lines (137 loc) · 1.86 KB
/
cerinta3.asm
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
.data
delim: .asciz " "
sir1: .space 102
cuv: .space 102
nr: .space 4
v: .long -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
var: .space 4
formatscanf: .asciz "%[^\n]"
f: .asciz "%d\n"
.text
.global main
main:
lea v, %esi
pushl $sir1
pushl $formatscanf
call scanf
popl %ebx
popl %ebx
pushl $delim
pushl $sir1
call strtok
popl %ebx
popl %ebx
movl %eax, cuv
pushl cuv
call atoi
popl %ebx
cmp $0, %eax
je verif1
pushl %eax
jmp etfor
verif1:
xorl %ecx, %ecx
movl cuv, %edi
movb (%edi, %ecx, 1), %al
pushl %eax
etfor:
pushl $delim
pushl $0
call strtok
popl %ebx
popl %ebx
cmp $0, %eax
je exit
movl %eax, cuv
pushl cuv
call atoi
popl %ebx
movl %eax, nr
cmp $0, %eax
je verif2
pushl %eax
jmp etfor
verif2:
pushl cuv
call strlen
popl %ebx
cmp $1, %eax
jg operatie
jmp verif3
verif3:
xorl %ecx, %ecx
movl cuv, %edi
movb (%edi, %ecx, 1), %al
cmp $48, %eax
je etzero
jmp variabila
etzero:
pushl $0
jmp etfor
variabila:
movl %eax, var
sub $97, %eax
movl (%esi, %eax, 4), %ebx
cmp $-1, %ebx
je litera
pushl %ebx
jmp etfor
litera:
pushl var
jmp etfor
operatie:
xorl %ecx, %ecx
movl cuv, %edi
movb (%edi, %ecx, 1), %al
cmp $97, %al
je add
cmp $100, %al
je div
cmp $109, %al
je mul
cmp $115, %al
je sub
cmp $108, %al
je let
let:
popl %eax
popl %ecx
subl $97, %ecx
movl %eax, (%esi, %ecx, 4)
jmp etfor
add:
popl %eax
popl %ebx
add %ebx, %eax
pushl %eax
jmp etfor
div:
xorl %edx, %edx
popl %ebx
popl %eax
divl %ebx
pushl %eax
jmp etfor
mul:
xorl %edx, %edx
popl %eax
popl %ebx
mull %ebx
pushl %eax
jmp etfor
sub:
popl %ebx
popl %eax
sub %ebx, %eax
pushl %eax
jmp etfor
exit:
popl %eax
pushl %eax
pushl $f
call printf
popl %ebx
popl %ebx
movl $1, %eax
xorl %ebx, %ebx
int $0x80