/*
   From http://www.hanshq.net/making-executables.html


   To assemble and view the machine code:

   $ gcc -m32 -nostdlib rot13_linux.s
   $ objdump -d a.out
*/


        .section .rodata
rot13_table:
        .byte   0,   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11,  12
        .byte  13,  14,  15,  16,  17,  18,  19,  20,  21,  22,  23,  24,  25
        .byte  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38
        .byte  39,  40,  41,  42,  43,  44,  45,  46,  47,  48,  49,  50,  51
        .byte  52,  53,  54,  55,  56,  57,  58,  59,  60,  61,  62,  63,  64
        .byte 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
        .byte 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M'
        .byte  91,  92,  93,  94,  95,  96, 'n', 'o', 'p', 'q', 'r', 's', 't'
        .byte 'u', 'v', 'w', 'x', 'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g'
        .byte 'h', 'i', 'j', 'k', 'l', 'm', 123, 124, 125, 126, 127, 128, 129
        .byte 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142
        .byte 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155
        .byte 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168
        .byte 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181
        .byte 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194
        .byte 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207
        .byte 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220
        .byte 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233
        .byte 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246
        .byte 247, 248, 249, 250, 251, 252, 253, 254, 255


        .section .bss
        .comm buffer, 4096


        .section .text
        .global _start
_start:
read:
	movl    $3, %eax
        xorl    %ebx, %ebx
	movl    $buffer, %ecx
        movl    $4096, %edx
        int     $0x80

        testl   %eax, %eax
        jle     end

        movl	%eax, %edx
rot13:
        movzbl  (%ecx), %ebx
        movb  rot13_table(%ebx), %bl
        movb    %bl, (%ecx)
        incl    %ecx
        decl    %eax
        jnz     rot13

	movl    $4, %eax
	movl    $1, %ebx
        subl    %edx, %ecx
        int     $0x80
        jmp     read

end:
	movl    $1, %eax
        xorl    %ebx, %ebx
        int     $0x80
