Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .section .data
- i:
- .int 0
- .global i
- j:
- .int 0
- .global j
- .section .text
- .global f
- .global f2
- .global f3
- .global f4
- f:
- # prologue
- pushl %ebp # save previous stack frame pointer
- movl %esp,%ebp # the stack frame pointer for sum function
- movl $0,%eax # place zeros in eax
- movl $0,%ecx # place zeros in ecx
- movl i,%eax # place i in eax
- movl j,%ecx # place j in ecx
- cmpl %eax, %ecx
- je jmp_is_equal
- addl %ecx,%eax # adds ecx to eax. Result in eax
- adcl $0, %edx # adds the carry to edx. Result in edx
- sbbl $1,%eax # subtracts 1 from eax. Result in eax
- jmp end
- jmp_is_equal:
- movl $1, %eax
- jmp end
- f2:
- # prologue
- pushl %ebp # save previous stack frame pointer
- movl %esp,%ebp # the stack frame pointer for sum function
- movl $0,%eax # place zeros in eax
- movl $0,%ecx # place zeros in ecx
- movl i,%eax # place i in eax
- movl j,%ecx # place j in ecx
- cmpl %ecx, %eax
- jg jmp_is_greater
- addl $1,%ecx # adds 1 to ecx. Result in ecx
- adcl $0, %edx # adds the carry to edx. Result in edx
- jmp mult
- jmp_is_greater:
- sbbl $1,%eax
- jmp mult
- mult:
- imul %ecx,%eax
- jmp end
- f3:
- # prologue
- pushl %ebp # save previous stack frame pointer
- movl %esp,%ebp # the stack frame pointer for sum function
- movl $0,%edx
- movl $0,%eax # place zeros in eax
- movl $0,%ecx # place zeros in ecx
- movl i,%ecx # place i in eax
- movl j,%eax # place j in ecx
- cmpl %eax, %ecx
- jl jmp_is_less
- imul %eax,%ecx
- addl $1, %eax # adds 1 to ecx. Result in ecx
- adcl $0, %edx # adds the carry to edx. Result in edx
- jmp mult1
- jmp_is_less:
- addl %eax, %ecx # adds eax to ecx. Result in ecx
- adcl $0, %edx # adds the carry to edx. Result in edx
- movl %ecx, %eax
- adcl $2, %eax
- adcl $0, %edx
- jmp mult1
- mult1:
- idiv %ecx
- jmp end
- f4:
- # prologue
- pushl %ebp # save previous stack frame pointer
- movl %esp,%ebp # the stack frame pointer for sum function
- movl $0,%eax # place zeros in eax
- movl $0,%ecx # place zeros in ecx
- movl i,%eax # place i in eax
- movl j,%ecx # place j in ecx
- addl %eax, %ecx # adds eax to ecx. Result in ecx
- adcl $0, %edx
- cmpl $10, %ecx
- jl jmp_less
- #ERRO É NO ELSE DA FUNCAO F4
- movl j,%eax #dá-me mal estas 4 linhas
- imul %eax, %eax #esta multiplicacao dá mal
- movl $3, %ebx # e por isso dá floating point exception
- idiv %ebx # quando divido. Mas não sei pk dá mal a multiplicacao.
- jmp_less:
- imul %eax,%eax
- imul $4, %eax
- jmp end
- end:
- # epilogue
- movl %ebp, %esp # restore the previous stack pointer ("clear" the stack)
- popl %ebp # restore the previous stack frame pointer
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement