Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .text
- .type fun, @function
- .global fun
- #a - rdi
- #b - rsi
- #pcs - rdx
- #count - rcx
- fun:
- PUSH %rbx
- XOR %rbx, %rbx
- XOR %r9, %r9
- XOR %r10, %r10
- XOR %rax, %rax
- MOV $1, %rbx # (i+1)
- MOV $0, %r9 # how Many 1
- CMP $1, %rsi # which bit
- JE sum
- CMP $2, %rsi
- JE mul
- JMP nothing
- loop:
- PUSH %rdi
- AND $1, %rdi
- JMP count
- afterCount:
- CMP $0, %rsi
- JE afterOp
- PUSH %rax
- MOV %rdi, %rax
- MUL %rbx
- MOV %rax, %r8
- POP %rax
- CMP $1, %rsi
- JE sumOp
- CMP $2, %rsi
- JE mulOp
- afterOp:
- POP %rdi
- INC %rbx
- SHR $1, %rdi
- CMP $64, %rbx
- JNE loop
- afterLoop:
- POP %rbx
- MOVL %r9d, (%rcx)
- MOVL %r10d, (%rdx)
- RET
- sum:
- MOV $0, %rax #starting value
- JMP loop
- mul:
- MOV $1, %rax #starting value
- JMP loop
- nothing:
- MOV $0, %rax
- JMP loop
- sumOp:
- ADD %r8, %rax #xi in rax
- JMP afterOp
- mulOp:
- MUL %r8 #xi in rax
- JMP afterOp
- count:
- CMP $0, %rdi
- JE afterCount
- INC %r9
- MOV %rbx, %r10
- JMP afterCount
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement