Advertisement
Guest User

Untitled

a guest
Oct 21st, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .section .data
  2.  
  3.     i:
  4.         .int 0
  5.      .global i
  6.     j:
  7.         .int 0
  8.      .global j
  9.    
  10. .section .text
  11.     .global f              
  12.     .global f2
  13.     .global f3
  14.     .global f4    
  15.    
  16.     f: 
  17.         # prologue
  18.         pushl %ebp      # save previous stack frame pointer
  19.         movl  %esp,%ebp # the stack frame pointer for sum function
  20.        
  21.         movl $0,%eax    # place zeros in eax
  22.         movl $0,%ecx    # place zeros in ecx
  23.         movl i,%eax     # place i in eax
  24.         movl j,%ecx     # place j in ecx
  25.        
  26.         cmpl %eax, %ecx
  27.         je jmp_is_equal
  28.        
  29.         addl %ecx,%eax  # adds ecx to eax. Result in eax
  30.         adcl $0, %edx   # adds the carry to edx. Result in edx
  31.         sbbl $1,%eax    # subtracts 1 from eax. Result in eax
  32.        
  33.         jmp end
  34.        
  35.     jmp_is_equal:  
  36.        
  37.         movl $1, %eax
  38.        
  39.         jmp end
  40.  
  41.     f2:
  42.         # prologue
  43.         pushl %ebp      # save previous stack frame pointer
  44.         movl  %esp,%ebp # the stack frame pointer for sum function
  45.        
  46.         movl $0,%eax    # place zeros in eax
  47.         movl $0,%ecx    # place zeros in ecx
  48.         movl i,%eax     # place i in eax
  49.         movl j,%ecx     # place j in ecx
  50.        
  51.         cmpl %ecx, %eax
  52.         jg jmp_is_greater
  53.        
  54.         addl $1,%ecx    # adds 1 to ecx. Result in ecx
  55.         adcl $0, %edx   # adds the carry to edx. Result in edx
  56.        
  57.         jmp mult
  58.        
  59.     jmp_is_greater:
  60.        
  61.         sbbl $1,%eax
  62.        
  63.         jmp mult
  64.        
  65.     mult:
  66.        
  67.         imul %ecx,%eax
  68.        
  69.         jmp end
  70.  
  71.     f3:
  72.         # prologue
  73.         pushl %ebp      # save previous stack frame pointer
  74.         movl  %esp,%ebp # the stack frame pointer for sum function
  75.        
  76.         movl $0,%edx
  77.         movl $0,%eax    # place zeros in eax
  78.         movl $0,%ecx    # place zeros in ecx
  79.         movl i,%ecx     # place i in eax
  80.         movl j,%eax     # place j in ecx
  81.        
  82.         cmpl %eax, %ecx
  83.         jl  jmp_is_less
  84.        
  85.         imul %eax,%ecx
  86.         addl $1, %eax    # adds 1 to ecx. Result in ecx
  87.         adcl $0, %edx    # adds the carry to edx. Result in edx
  88.        
  89.         jmp mult1
  90.        
  91.     jmp_is_less:   
  92.        
  93.         addl %eax, %ecx  # adds eax to ecx. Result in ecx
  94.         adcl $0, %edx    # adds the carry to edx. Result in edx
  95.        
  96.         movl %ecx, %eax
  97.         adcl $2, %eax
  98.         adcl $0, %edx
  99.        
  100.         jmp mult1
  101.        
  102.     mult1:
  103.    
  104.         idiv %ecx
  105.    
  106.         jmp end
  107.        
  108.     f4:
  109.         # prologue
  110.         pushl %ebp      # save previous stack frame pointer
  111.         movl  %esp,%ebp # the stack frame pointer for sum function
  112.        
  113.         movl $0,%eax    # place zeros in eax
  114.         movl $0,%ecx    # place zeros in ecx
  115.         movl i,%eax     # place i in eax
  116.         movl j,%ecx     # place j in ecx
  117.        
  118.         addl %eax, %ecx  # adds eax to ecx. Result in ecx
  119.         adcl $0, %edx
  120.        
  121.         cmpl $10, %ecx
  122.         jl jmp_less
  123.        
  124.            
  125.                             #ERRO É NO ELSE DA FUNCAO F4
  126.         movl j,%eax         #dá-me mal estas 4 linhas
  127.         imul %eax, %eax     #esta multiplicacao dá mal
  128.         movl $3, %ebx       # e por isso dá floating point exception
  129.         idiv %ebx           # quando divido. Mas não sei pk dá mal a multiplicacao.
  130.        
  131.        
  132.     jmp_less:
  133.        
  134.         imul %eax,%eax
  135.         imul $4, %eax
  136.        
  137.         jmp end
  138.  
  139.     end:
  140.  
  141.     # epilogue
  142.     movl %ebp, %esp # restore the previous stack pointer ("clear" the stack)
  143.     popl %ebp # restore the previous stack frame pointer
  144.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement