Código de máquina x86 en DOS ( .comarchivo) - 70 bytes
Tratar con archivos .COM, crear un síndrome de palyndrome es fácil, ya que el "cargador" COM simplemente coloca el contenido del archivo en la dirección 100hy salta allí, el programa ya debe codificar su final de alguna manera e ignorar todo después de eso, así que solo podemos agregar el reverso de los primeros bytes N-1 (solo advertencia: si el programa de alguna manera intenta hacer trucos con la longitud del archivo, todo se rompe).
Aquí está el volcado hexadecimal de mi .COM-palyndromizing .COM:
00000000 31 db 8a 1e 80 00 c6 87 81 00 00 ba 82 00 b8 00 |1...............|
00000010 3d cd 21 72 30 89 c6 bf ff ff b9 01 00 ba fe 00 |=.!r0...........|
00000020 89 f3 b4 3f cd 21 3c 01 75 18 b4 40 bb 01 00 cd |...?.!<.u..@....|
00000030 21 85 ff 75 e5 89 f3 f7 d9 88 ee b8 01 42 cd 21 |!..u.........B.!|
00000040 eb d8 47 74 f0 c3 |..Gt..|
Toma el archivo de entrada en la línea de comando y escribe la salida en stdout; El uso esperado es algo así compalyn source.com > out.com.
Asamblea comentada:
org 100h
section .text
start:
; NUL-terminate the command line
xor bx,bx
mov bl, byte[80h]
mov byte[81h+bx],0
; open the input file
mov dx,82h
mov ax,3d00h
int 21h
; in case of error (missing file, etc.) quit
jc end
; si: source file handle
mov si,ax
; di: iteration flag
; -1 => straight pass, 0 reverse pass
mov di,-1
loop:
; we read one byte at time at a bizarre memory
; location (so that dl is already at -2 later - we shave one byte)
mov cx,1
mov dx,0feh
mov bx,si
mov ah,3fh
int 21h
; if we didn't read 1 byte it means we either got to EOF
; or sought before the start of file
cmp al,1
jne out
; write the byte on stdout
mov ah,40h
mov bx,1
int 21h
; if we are at the first pass we go on normally
test di,di
jnz loop
back:
; otherwise, we have to seek back
mov bx,si
; one byte shorter than mov cx,-1
neg cx
; dl is already at -2, fix dh so cx:dx = -2
mov dh,ch
mov ax,4201h
int 21h
jmp loop
out:
; next iteration
inc di
; if it's not zero we already did the reverse pass
jz back
end:
ret
Probado en sí mismo y las soluciones a una pregunta anterior parecen funcionar bien en DosBox, seguirán algunas pruebas más exhaustivas en ejecutables DOS "canónicos".