-
Notifications
You must be signed in to change notification settings - Fork 0
/
ass6_14CS30006_1.s
196 lines (196 loc) · 3.09 KB
/
ass6_14CS30006_1.s
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
.section .rodata
.LC0:
.string "Example of passing pointer to function\n"
.LC1:
.string "Value passed : "
.LC2:
.string "\n"
.LC3:
.string "Value returned is: "
.LC4:
.string "\n"
.LC5:
.string "Read an integer!!"
.LC6:
.string "\n"
.LC7:
.string "The integer read is:"
.LC8:
.string "\n"
# function printi start
# function prints start
# function readi start
# function f start
#--param_offset:24
#--loacl var offset: 4 -4
#--loacl var offset: 4 -8
#--loacl var offset: 4 -12
#--loacl var offset: 4 -16
#-16
##ptra
##ptrx
##ptrt0
##ptrt1
##ptrt2
##ptrretVal
.globl f
.type f, @function
f:
pushq %rbp
movq %rsp, %rbp
subq $48, %rsp
# t0= *a
movq 16(%rbp), %rax
movl (%rax), %ecx
movl %ecx, -8(%rbp)
# x = t0
movl %eax, -4(%rbp)
# t1 = 5
movl $5, -12(%rbp)
# x+t1
movl -4(%rbp), %edx
movl -12(%rbp), %eax
addl %edx, %eax
movl %eax, -16(%rbp)
# x = t2
movl -16(%rbp), %eax
movl %eax, -4(%rbp)
# return x
movq -4(%rbp), %rax
leave
ret
# function f end
leave
ret
.size f, .-f
# function main start
#--loacl var offset: 4 -4
#--loacl var offset: 4 -8
#--loacl var offset: 8 -16
#--loacl var offset: 4 -20
#--loacl var offset: 8 -28
#--loacl var offset: 4 -32
#--loacl var offset: 4 -36
#--loacl var offset: 4 -40
#--loacl var offset: 4 -44
#--loacl var offset: 4 -48
#--loacl var offset: 4 -52
#--loacl var offset: 4 -56
#--loacl var offset: 4 -60
#--loacl var offset: 4 -64
#--loacl var offset: 4 -68
#--loacl var offset: 4 -72
#--loacl var offset: 4 -76
#--loacl var offset: 4 -80
#--loacl var offset: 4 -84
#-84
##ptra
##ptrq
##ptre
##ptrt3
##ptrt4
##ptrprints
##ptr.LC0
##ptr.LC1
##ptrprinti
##ptr.LC2
##ptrf
##ptr.LC3
##ptr.LC4
##ptr.LC5
##ptr.LC6
##ptrreadi
##ptr.LC7
##ptr.LC8
##ptrt5
##ptrretVal
.globl main
.type main, @function
main:
pushq %rbp
movq %rsp, %rbp
subq $112, %rsp
# t3 = 3
movl %eax, -20(%rbp)
# q = t3
movl -20(%rbp), %eax
movl %eax, -8(%rbp)
# t4= &q
leaq -8(%rbp), %rax
movq %rax, -28(%rbp)
# e = t4
movl -28(%rbp), %eax
movl %eax, -16(%rbp)
# param .LC0
movq $.LC0, %rdi
# call prints 1
call prints
# param .LC1
movq $.LC1, %rdi
# call prints 1
call prints
# param q
movq -8(%rbp), %rdi
# call printi 1
call printi
# param .LC2
movq $.LC2, %rdi
# call prints 1
call prints
# param e
# call f 1
movq -16(%rbp), %rax
pushq %rax
call f
addq $8, %rsp
#--
# a = f
movl %eax, -4(%rbp)
# param .LC3
movq $.LC3, %rdi
# call prints 1
call prints
# param a
movq -4(%rbp), %rdi
# call printi 1
call printi
# param .LC4
movq $.LC4, %rdi
# call prints 1
call prints
# param .LC5
movq $.LC5, %rdi
# call prints 1
call prints
# param .LC6
movq $.LC6, %rdi
# call prints 1
call prints
# param e
movq -16(%rbp), %rdi
# call readi 1
call readi
# q = readi
movl %eax, -8(%rbp)
# param .LC7
movq $.LC7, %rdi
# call prints 1
call prints
# param q
movq -8(%rbp), %rdi
# call printi 1
call printi
# param .LC8
movq $.LC8, %rdi
# call prints 1
call prints
# t5 = 0
movl %eax, -84(%rbp)
# return t5
movq -84(%rbp), %rax
leave
ret
# function main end
leave
ret
.size main, .-main