Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .global supersum
- supersum:
- // eax - pointer to A
- // ebx - pointer to B
- // ecx - pointer to C
- // esi - size A
- // edi - size B
- pushl %ebp
- pushl %edx
- pushl %esi
- pushl %edi
- pushl %ebx
- cmpl %esi, %edi // edi > esi (size B > size A) go to start
- jg start_loop_first
- //swap A, B
- movl %esi, %ebp
- movl %edi, %esi
- movl %ebp, %edi
- movl %eax, %ebp
- movl %ebx, %eax
- movl %ebp, %ebx
- // use ebp as itearator
- start_loop_first:
- xor %ebp, %ebp // i = 0
- loop_first:
- cmpl %esi, %ebp // i > size A
- jg finish_first_loop
- movb $0, (%ecx, %ebp) // C[i] = 0
- addl $1, %ebp // i++
- jmp loop_first
- finish_first_loop:
- xor %ebp, %ebp // i = 0
- loop_second:
- cmpl %edi, %ebp // i > size B
- jg finish_second_loop
- movb $0, (%ecx, %ebp) // C[i] = 0
- addl $1, %ebp // i++
- jmp loop_second
- finish_second_loop:
- xor %ebp, %ebp // i = 0
- clc // CF = 0
- pushf
- loop_add_a:
- cmpl %esi, %ebp // i >= size A
- jge finish_add_a
- movb (%eax, %ebp), %dl // tmp (dl) = A[i]
- popf
- adcb %dl, (%ecx, %ebp) // C[i] += tmp + CF
- pushf
- addl $1, %ebp // i++
- jmp loop_add_a
- finish_add_a:
- popf
- adcb $0, (%ecx, %ebp) // C[i] += CF
- xor %ebp, %ebp // i = 0
- clc // CF = 0
- pushf
- loop_add_b:
- cmpl %edi, %ebp // i >= size B
- jge finish_add_b
- movb (%ebx, %ebp), %dl // tmp (dl) = B[i]
- popf
- adcb %dl, (%ecx, %ebp) // C[i] += tmp + CF
- pushf
- addl $1, %ebp // i++
- jmp loop_add_b
- finish_add_b:
- popf
- adcb $0, (%ecx, %ebp) // C[i] += CF
- // C = A + B
- // now need to find length
- cmpl %edi, %esi // esi > edi
- jg swap_registers
- //edi >= esi
- movl %edi, %ebp
- jmp find_loop
- swap_registers: // esi > edi
- movl %esi, %ebp
- find_loop: // ebp - iterator to last
- cmpl $0, %ebp
- jz finish_program // if ebp == 0
- cmpb $0, (%ecx, %ebp) // C[i] != 0
- jnz finish_program
- subl $1, %ebp // --i
- jmp find_loop
- finish_program:
- cmpb $0, (%ecx, %ebp) // C[i] == 0
- jz zeroo
- jmp finish_last
- zeroo:
- movl $-1, %ebp
- finish_last:
- addl $1, %ebp
- movl %ebp, %eax
- popl %ebx
- popl %edi
- popl %esi
- popl %edx
- popl %ebp
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement