Search code examples
assemblybinaryasciinasm

Assembly prints wrong ascii character


I was trying to create a simple assembly program that prints the ascii character whose binary code is in rax. I have the following code:

section .data
   res db '', 0

global _start
_start:
    mov rbx, 1000001
    mov [res], rbx
    
    mov rax, 1
    mov rdi, 1
    mov rsi, res
    mov rdx, 1
    syscall


    mov rax, 60
    xor rdi, rdi
    syscall

When I execute, it outputs 'A', which is correct since 1000001 is the binary code for ascii A, but if I execute this:

section .data
   res db '', 0

global _start
_start:
    mov rbx, 1000010
    mov [res], rbx
    
    mov rax, 1
    mov rdi, 1
    mov rsi, res
    mov rdx, 1
    syscall


    mov rax, 60
    xor rdi, rdi
    syscall

It outputs 'J', but according to the table I used 1000010 should output 'B'. What makes this even stranger for me is that if I use decimal instead of binary I get the right output. What am I doing wong?


Solution

  • 100000110 = F424116, and 4116 = 6510 = A ASCII

    100001010 = F424A16, and 4A16 = 7410 = J ASCII