Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .section .text
- .global main
- .intel_syntax noprefix
- convert:
- push rbp
- mov rbp, rsp
- sub rsp, 16
- lea rdi, qword ptr [rip+.fmt_scanf]
- lea rsi, qword ptr [rip+input]
- xor rax, rax
- call scanf@plt
- lea rdi, qword ptr [rip+.fmt_printf_message]
- xor rax, rax
- call printf@plt
- # copy 'n' to rdx
- mov r13, [rip+input]
- // bool display = false;
- mov r14, 0
- // int i = 63
- mov r12, 63
- .loop:
- // int bit = r13;
- mov rsi, r13
- // bit = (bit >> i) & 1;
- mov rcx, r12
- shr rsi, cl
- and rsi, 1
- // if (bit)
- cmp rsi, 1
- je .set_display_to_true
- jne .check_if_display
- // display = true
- .set_display_to_true:
- mov r14, 1
- // if (display)
- .check_if_display:
- cmp r14, 1
- jne .decrement
- // printf("%d", bit)
- .show_bit:
- lea rdi, qword ptr [rip+.fmt_printf]
- xor rax, rax
- call printf@plt
- .decrement:
- // i--
- sub r12, 1
- // i >= 0
- cmp r12, 0
- jge .loop
- lea rdi, qword ptr [rip+.newline]
- xor rax, rax
- call printf@plt
- add rsp, 16
- pop rbp
- ret
- main:
- push rbp
- mov rbp, rsp
- sub rsp, 16
- .conversion:
- call convert
- jmp .conversion
- add rsp, 16
- pop rbp
- # return 0
- xor rax, rax
- ret
- .section .rodata
- .fmt_scanf:
- .asciz "%llu"
- .fmt_printf_message:
- .asciz "Binary: "
- .fmt_printf:
- .asciz "%d"
- .newline:
- .asciz "\n"
- .section .bss
- input: .zero 8
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement