Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 2016-07-06
  2.  
  3. #include <iostream>
  4. using namespace std;
  5. struct st1 { char vi[4]; }; struct st2 { int vd[4]; };
  6. class cl
  7. {   char v1[4]; char v2[4]; long v3[4];
  8. public:
  9.     cl(st1 ss); cl(st1 s1, long ar2[]);
  10.     cl xxx1(char ar1[], st2 s2);
  11.     void stampa()
  12.     {   char i;
  13.         for (i=0;i<4;i++) cout << (int)v1[i] << ' '; cout << endl;
  14.         for (i=0;i<4;i++) cout << (int)v2[i] << ' '; cout << endl;
  15.         for (i=0;i<4;i++) cout << v3[i] << ' '; cout << endl << endl;
  16.     }
  17. };
  18.  
  19. #include "cc.h"
  20. cl::cl(st1 ss)
  21. {
  22.     for (int i = 0; i < 4; i++) {
  23.         v1[i] = v2[i] = ss.vi[i]; v3[i] = ss.vi[i] + ss.vi[i];
  24.     }
  25. }
  26. cl::cl(st1 s1, long ar2[])
  27. {
  28.     for (int i=0; i<4; i++) {
  29.         v1[i] = v2[i] = s1.vi[i]; v3[i] = ar2[i];
  30.     }
  31. }
  32. cl cl::xxx1(char ar1[], st2 s2)
  33. {
  34.     st1 s1;
  35.     for (int i = 0; i < 4; i++)
  36.         s1.vi[i] = ar1[i];
  37.     cl cla(s1);
  38.     for (int i = 0; i < 4; i++)
  39.         cla.v3[i] = s2.vd[i];
  40.     return cla;
  41. }
  42.  
  43. SOLUZIONE
  44.  
  45. # COSTRUTTORE I
  46.  
  47. .global _ZN2clC1E3stl
  48. _ZN2clC1E3stl:
  49.  
  50. # RECORD DI ATTIVAZIONE
  51. # i   |   ss    -16  #sono due valori, 4 byte ciascuno.
  52. # this    -8         #this è un puntatore, occupa 8 byte.
  53. # %old_rbp    <- %rbp
  54. # %rip
  55.  
  56. # PROLOGO
  57.   pushq %rbp
  58.   movq %rsp,    %rbp
  59.   subq $16,   %rsp
  60.  
  61. # COPIA PARAMETRI
  62.   movq %rdi,    -8(%rbp)        #this
  63.   movl %esi,    -16(%rbp)       # ss e i
  64.  
  65. # CORPO
  66.   movl $0,    -12(%rbp)
  67. for:
  68.   cmpl $4,   -12(%rbp)
  69.   jge finefor
  70.   movq -8(%rbp),    %rdi          #this
  71.   movslq -12(%rbp),   %rcx        #i
  72.   movb -16(%rbp, %rcx),   %bl     # ss.vi[i]
  73.   movb %bl,   (%rdi, %rcx)         #v1[i]  = ss.vi[i]
  74.   movb %bl,   4(%rdi, %rcx)         #v2[i] = ss.vi[i]
  75.   movsbq %bl,   %rbx                #estendo a long
  76.   movq %rbx, 8(%rdi, %rcx, 8)          #v3[i] = ss.vi[i]
  77.   addq %rbx, 8(%rdi, %rcx, 8)           #v3[i]+= ss.vi[i]
  78.   incl -12(%rbp)
  79.   jmp for
  80. finefor:
  81.   leave
  82.   ret
  83.  
  84. #COSTRUTTORE II
  85.  
  86. .global _ZN2clC1E3stlPl
  87. _ZN2clC1E3stlPl:
  88.  
  89. # RECORD DI ATTIVAZIONE
  90. # ar2       -24                                 # long ar2[] == puntatore -> 8 byte
  91. # i   |   s1    -16
  92. # this    -8
  93. # %old_rbp <-     %rbp
  94. # %rip
  95.  
  96. # PROLOGO
  97.   pushq %rbp
  98.   movq %rsp,    %rbp
  99.   subq $16,   %rsp
  100.  
  101. # COPIA PARAMETRI
  102.   movq %rdi,    -8(%rbp)
  103.   movl %esi,    -16(%rbp)
  104.   movq %rdx,    -24(%rbp)
  105.  
  106. # CORPO
  107.   movl $0, -12(%rbp)
  108. for2:
  109.   cmp $4,   -12(%rbp)
  110.   jge finefor2
  111.   movq -8(%rbp),    %rdi                 # this appoggio
  112.   movslq -12(%rbp),   %rcx                #i  uso registri di appoggio
  113.   movb -16(%rbp, %rcx),    %bl              # ss.vi[i] in %bl
  114.   movb %bl,   (%rdi, %rcx)        # v1[i] = s1.vi[i]
  115.   movb %bl,   4(%rdi, %rcx)       # v2[i] = s1.vi[i]
  116.   movq -24(%rbp),   %rdx                # ar2[] appoggio
  117.   movq (%rdx, %rcx, 8), %r8       # ar2[i]
  118.   movq %r8,   8(%rdi, %rcx, 8)          #NB ==> 8 è dovuto al fatto che v3[] è long
  119.   incl -12(%rbp)
  120.   jmp for2
  121. finefor2:
  122.   leave
  123.   ret
  124.  
  125. # ELAB 1
  126.  
  127. .global _ZN2cl5elab1EPc3st2
  128. _ZN2cl5elab1EPc3st2:
  129.  
  130. # RECORD DI ATTIVAZIONE
  131. # clar       -88  (return)
  132. # cla        -80
  133. #         -72    #v3[]
  134. #         -64    #v2[]
  135. #         -56    #v1[]
  136. #         -48
  137. # s2         -40
  138. #           -32
  139. # ar1[]     -24
  140. # i | s1    -16
  141. # this        -8
  142. # %old_rbp      <-    %rbp
  143. # %rip
  144.  
  145. # PROLOGO
  146.   pushq %rbp
  147.   movq %rsp,    %rbp
  148.   subq $88,   %rsp
  149.  
  150. # COPIA PARAMETRI
  151.   movq %rdi,    -88(%rbp)     # registro per il risultato clar
  152.   movq %rsi,    -8(%rbp)         # this
  153.   movq %rdx,    -24(%rbp)        # ar1[]
  154.   movq %rcx,    -40(%rbp)        # s2
  155.   movq %r8,   -32(%rbp)          #
  156.  
  157. # CORPO
  158.   movl $0, -12(%rbp)
  159. for3:
  160.   cmpl $4,    -12(%rbp)
  161.   jge finefor3
  162.   movq -8(%rbp),    %rdi         #this
  163.   movq -12(%rbp),    %rcx        #i
  164.   movq -24(%rbp),   %rsi        #ar1[]
  165.   movb (%rsi, %rcx),  %bl       #ar1[i]
  166.   movb %bl,   -16(%rbp, %rcx)    # s1.vi[i] = ar1[i]
  167.   incl -12(%rbp)
  168.   jmp for3
  169. finefor3:
  170.  
  171. istanziaCla:
  172.   leaq -80(%rbp),   %rdi
  173.   movl -16(%rbp),   %esi
  174.   call _ZN2clC1E3stl
  175.  
  176.   movl $0,    -12(%rbp)
  177. for4:
  178.   cmpl $4,    -12(%rbp)
  179.   jge  finefor4
  180.   movq -8(%rbp),    %rdi         #this
  181.   movq -12(%rbp),    %rcx        #i
  182.   movl -40(%rbp, %rcx, 4), %ebx    #s2.vd[i]
  183.   movslq %ebx, %rbx
  184.   movq %rbx, -72(%rbp, %rcx, 8)   #cla.v3[i] = s2.vd[i]
  185.   incl -12(%rbp)
  186.   jmp for4
  187. finefor4:
  188.  
  189. for5:
  190.   cmpl $5,   -12(%rbp)
  191.   jge   finefor5
  192.   movq -12(%rbp),    %rcx        #i
  193.   movq -88(%rbp),  %rbx           #clar
  194.   movq -80(%rbp, %rcx, 8),  %rax   #una riga di cla
  195.   movq %rax, (%rbx, %rcx, 8)       #copio la riga all indirizzo di ritorno
  196.   incl -12(%rbp)
  197.   jmp for5
  198. finefor5:
  199.   leave
  200.   ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement