0

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?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
user110269
  • 25
  • 7
  • 1
    Almost a duplicate: [How to represent hex value such as FFFFFFBB in x86 assembly programming?](https://stackoverflow.com/a/37152498) includes the `mov ax,1100_1000b` and other syntax that NASM allows for binary (base-2) numeric constants. Of course you should just `mov ebx, 'B'` if that's what you want. – Peter Cordes Dec 23 '20 at 19:07

1 Answers1

1

100000110 = F424116, and 4116 = 6510 = A ASCII

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

Erik Eidt
  • 23,049
  • 2
  • 29
  • 53