Input will be in ASCII characters, you need to mask to binary. ASCII 0 - 9 is hexidecimal 30h - 39h, or binary 00110000 - 00111001
By masking off upper 4 bits you get binary equivalent of that digit. Alpha letters can be converted upper/lower case with bit masks
also. To see how its working, I recommend Evans debugger (codef00.com) edb to step through program. This program is written for
Linux 64 bit.
; Comments: Program is to show concept, no error checking. Input
; is possible to overrun char buffer and/or enter char's
; other than numeric.
; ASCII char's 0-9 equal hex 30h - 39h
; binary 0011 0111 = ASCII '7'. Mask off upper 4 bits to
; change to binary 7.
; To compile:
; nasm -f elf64 april.asm
; ld -melf_x86_64 -o april april.o
; edb --run "/path to program"/april
; NOTE: Recommend Evans debugger (codef00.com) edb to observe execution.
;=======================================================================
;
Bits 64
Section .data
msg db 'Enter a number: '
msglen equ $ - msg
Section .bss
cbuffer resb 32
Section .text
Global _start
_start: mov rax,1 ; (write)
mov rdi,1
mov rsi,msg
mov rdx,msglen
syscall
mov rax,0 ; (read)
mov rdi,0
mov rsi,cbuffer
mov rdx,10h
syscall
;
xor rax,rax ;Result register
xor rbx,rbx ;Temp ASCII digit
mov rcx,0Ah ;x 10 multiplier
mov rsi,cbuffer ;Where ASCII string
_cnvrt: mov bl,[rsi] ;Get numeric char
cmp bl,0Ah ;Linefeed?
jz _done ; we're done
mul rcx ;Multiply by 10
and bl,0Fh ;Mask ASCII to binary
add rax,rbx ;Add to result
inc rsi ;Increment string pointer
jmp _cnvrt ;Next character
;
; At this point RAX contains binary conversion.
;
_done: mov rax,3Ch ; (exit)
mov rdi,0
syscall