## Convert space-separated decimal numbers to binary ## You know, I think this is almost the same as the i386 ## system call interface, but maybe with different registers? ## Also, different system call numbers! On i386 %eax=1 is ## _exit(). .globl _start ## First, read a byte: _start: xor %edi, %edi # fd 0 mov $buf, %esi # into buf xor %edx, %edx inc %edx # 1 byte xor %eax, %eax # _NR_read is 0 syscall test %eax, %eax # quit if error or EOF jle done ## Only if we’ve got a space, write out the number: mov (buf), %eax cmp $32, %eax jne keep_converting ## We got a space, so we should write out our byte: mov %ebx, (buf) # store byte into buf xor %edi, %edi inc %edi # fd 1 mov $buf, %esi # write from buf mov %edi, %edx # 1 byte mov %edi, %eax # _NR_write is 1 syscall ## Then repeat: xor %ebx, %ebx # clear accumulating number jmp _start keep_converting: imul $10, %ebx mov (buf), %eax and $15, %eax add %eax, %ebx jmp _start ## Got EOF or error, so exit. done: xor %edx, %edx mov $231, %eax # _NR_exit_group in unistd_64.h syscall .data .align 8 buf: .byte 0 .byte 0 .byte 0 .byte 0 .byte 0 .byte 0 .byte 0 .byte 0