-
Notifications
You must be signed in to change notification settings - Fork 0
/
fisier3.asm
165 lines (135 loc) · 1.98 KB
/
fisier3.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
.data
str: .space 300
delim: .asciz " "
formatPrintf: .asciz "%d\n"
formatScanf: .asciz "%[^\n]"
v: .space 100
res: .space 4
e: .space 4
primulnr: .space 4
var: .space 4
nr: .space 4
cts: .space 4
lit: .space 4
.text
.global main
main:
pushl $str
pushl $formatScanf
call scanf
popl %ebx
popl %ebx
pushl $delim
pushl $str
call strtok
popl %ebx
popl %ebx
lea v, %edi
movl %eax, res
pushl res
call atoi
popl %ebx
cmp $0, %eax #verific daca primul element din sir este nr sau variabila
je variabila1
movl %eax, primulnr
pushl primulnr #urc primul nr pe stiva
et_for:
pushl $delim
pushl $0
call strtok
popl %ebx
popl %ebx
cmp $0, %eax
je exit
movl %eax, res
pushl res
call atoi
popl %ebx
cmp $0, %eax #verific daca este variabila/operatie sau numar
je varop
movl %eax, nr
pushl nr #pun nr pe stiva
jmp et_for
variabila1:
xorl %ecx, %ecx
movl res, %esi
movb (%esi, %ecx, 1), %al
pushl %eax
jmp et_for
varop:
movl res, %esi
xorl %ecx, %ecx
movb (%esi, %ecx, 1), %al
movl %eax, var
incl %ecx
movb (%esi, %ecx, 1), %al
cmp $0, %al
jne operatie
je variabila2
variabila2:
movl var, %ecx
subl $97, %ecx
movl (%edi, %ecx, 4), %eax
cmp $0, %eax
jne varpush
pushl var
jmp et_for
varpush:
pushl %eax
jmp et_for
operatie:
movl var, %eax
cmp $97, %eax
je op_add
cmp $100, %eax
je op_div
cmp $108, %eax
je op_let
cmp $109, %eax
je op_mul
cmp $115, %eax
je op_sub
op_add:
popl %eax
popl %ebx
addl %ebx, %eax
pushl %eax
jmp et_for
op_div:
xorl %edx, %edx
popl %ebx
popl %eax
divl %ebx
pushl %eax
jmp et_for
op_let:
popl cts
popl %ebx
subl $97, %ebx
movl %ebx, %ecx
movl cts, %eax
movl %eax, (%edi, %ecx, 4)
jmp et_for
op_mul:
xorl %edx, %edx
popl %ebx
popl %eax
mull %ebx
pushl %eax
jmp et_for
op_sub:
popl %ebx
popl %eax
subl %ebx, %eax
pushl %eax
jmp et_for
exit:
popl e
pushl e
pushl $formatPrintf
call printf
popl %ebx
popl %ebx
movl $1, %eax
xorl %ebx, %ebx
int $0x80