Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 2016-07-06
- #include <iostream>
- using namespace std;
- struct st1 { char vi[4]; }; struct st2 { int vd[4]; };
- class cl
- { char v1[4]; char v2[4]; long v3[4];
- public:
- cl(st1 ss); cl(st1 s1, long ar2[]);
- cl xxx1(char ar1[], st2 s2);
- void stampa()
- { char i;
- for (i=0;i<4;i++) cout << (int)v1[i] << ' '; cout << endl;
- for (i=0;i<4;i++) cout << (int)v2[i] << ' '; cout << endl;
- for (i=0;i<4;i++) cout << v3[i] << ' '; cout << endl << endl;
- }
- };
- #include "cc.h"
- cl::cl(st1 ss)
- {
- for (int i = 0; i < 4; i++) {
- v1[i] = v2[i] = ss.vi[i]; v3[i] = ss.vi[i] + ss.vi[i];
- }
- }
- cl::cl(st1 s1, long ar2[])
- {
- for (int i=0; i<4; i++) {
- v1[i] = v2[i] = s1.vi[i]; v3[i] = ar2[i];
- }
- }
- cl cl::xxx1(char ar1[], st2 s2)
- {
- st1 s1;
- for (int i = 0; i < 4; i++)
- s1.vi[i] = ar1[i];
- cl cla(s1);
- for (int i = 0; i < 4; i++)
- cla.v3[i] = s2.vd[i];
- return cla;
- }
- SOLUZIONE
- # COSTRUTTORE I
- .global _ZN2clC1E3stl
- _ZN2clC1E3stl:
- # RECORD DI ATTIVAZIONE
- # i | ss -16 #sono due valori, 4 byte ciascuno.
- # this -8 #this è un puntatore, occupa 8 byte.
- # %old_rbp <- %rbp
- # %rip
- # PROLOGO
- pushq %rbp
- movq %rsp, %rbp
- subq $16, %rsp
- # COPIA PARAMETRI
- movq %rdi, -8(%rbp) #this
- movl %esi, -16(%rbp) # ss e i
- # CORPO
- movl $0, -12(%rbp)
- for:
- cmpl $4, -12(%rbp)
- jge finefor
- movq -8(%rbp), %rdi #this
- movslq -12(%rbp), %rcx #i
- movb -16(%rbp, %rcx), %bl # ss.vi[i]
- movb %bl, (%rdi, %rcx) #v1[i] = ss.vi[i]
- movb %bl, 4(%rdi, %rcx) #v2[i] = ss.vi[i]
- movsbq %bl, %rbx #estendo a long
- movq %rbx, 8(%rdi, %rcx, 8) #v3[i] = ss.vi[i]
- addq %rbx, 8(%rdi, %rcx, 8) #v3[i]+= ss.vi[i]
- incl -12(%rbp)
- jmp for
- finefor:
- leave
- ret
- #COSTRUTTORE II
- .global _ZN2clC1E3stlPl
- _ZN2clC1E3stlPl:
- # RECORD DI ATTIVAZIONE
- # ar2 -24 # long ar2[] == puntatore -> 8 byte
- # i | s1 -16
- # this -8
- # %old_rbp <- %rbp
- # %rip
- # PROLOGO
- pushq %rbp
- movq %rsp, %rbp
- subq $16, %rsp
- # COPIA PARAMETRI
- movq %rdi, -8(%rbp)
- movl %esi, -16(%rbp)
- movq %rdx, -24(%rbp)
- # CORPO
- movl $0, -12(%rbp)
- for2:
- cmp $4, -12(%rbp)
- jge finefor2
- movq -8(%rbp), %rdi # this appoggio
- movslq -12(%rbp), %rcx #i uso registri di appoggio
- movb -16(%rbp, %rcx), %bl # ss.vi[i] in %bl
- movb %bl, (%rdi, %rcx) # v1[i] = s1.vi[i]
- movb %bl, 4(%rdi, %rcx) # v2[i] = s1.vi[i]
- movq -24(%rbp), %rdx # ar2[] appoggio
- movq (%rdx, %rcx, 8), %r8 # ar2[i]
- movq %r8, 8(%rdi, %rcx, 8) #NB ==> 8 è dovuto al fatto che v3[] è long
- incl -12(%rbp)
- jmp for2
- finefor2:
- leave
- ret
- # ELAB 1
- .global _ZN2cl5elab1EPc3st2
- _ZN2cl5elab1EPc3st2:
- # RECORD DI ATTIVAZIONE
- # clar -88 (return)
- # cla -80
- # -72 #v3[]
- # -64 #v2[]
- # -56 #v1[]
- # -48
- # s2 -40
- # -32
- # ar1[] -24
- # i | s1 -16
- # this -8
- # %old_rbp <- %rbp
- # %rip
- # PROLOGO
- pushq %rbp
- movq %rsp, %rbp
- subq $88, %rsp
- # COPIA PARAMETRI
- movq %rdi, -88(%rbp) # registro per il risultato clar
- movq %rsi, -8(%rbp) # this
- movq %rdx, -24(%rbp) # ar1[]
- movq %rcx, -40(%rbp) # s2
- movq %r8, -32(%rbp) #
- # CORPO
- movl $0, -12(%rbp)
- for3:
- cmpl $4, -12(%rbp)
- jge finefor3
- movq -8(%rbp), %rdi #this
- movq -12(%rbp), %rcx #i
- movq -24(%rbp), %rsi #ar1[]
- movb (%rsi, %rcx), %bl #ar1[i]
- movb %bl, -16(%rbp, %rcx) # s1.vi[i] = ar1[i]
- incl -12(%rbp)
- jmp for3
- finefor3:
- istanziaCla:
- leaq -80(%rbp), %rdi
- movl -16(%rbp), %esi
- call _ZN2clC1E3stl
- movl $0, -12(%rbp)
- for4:
- cmpl $4, -12(%rbp)
- jge finefor4
- movq -8(%rbp), %rdi #this
- movq -12(%rbp), %rcx #i
- movl -40(%rbp, %rcx, 4), %ebx #s2.vd[i]
- movslq %ebx, %rbx
- movq %rbx, -72(%rbp, %rcx, 8) #cla.v3[i] = s2.vd[i]
- incl -12(%rbp)
- jmp for4
- finefor4:
- for5:
- cmpl $5, -12(%rbp)
- jge finefor5
- movq -12(%rbp), %rcx #i
- movq -88(%rbp), %rbx #clar
- movq -80(%rbp, %rcx, 8), %rax #una riga di cla
- movq %rax, (%rbx, %rcx, 8) #copio la riga all indirizzo di ritorno
- incl -12(%rbp)
- jmp for5
- finefor5:
- leave
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement