2007-05-02

128-bit programming challenge

Here's my entry for the 128-bit programming challenge. Not a single lookup table in there. The resulting stripped binary is down to exactly 500 bytes.


; nasm -f elf hex.asm
; ld hex.o

section .text
global _start
_start:
mov ecx,10h
mov esi,hex
mov edi,buffer
lp:
movzx eax,byte [esi]
mov ah,al
and al,0fh
cmp al,0ah
sbb al,69h
das
mov [edi+1],al
shr ax,12
cmp al,0ah
sbb al,69h
das
mov [edi],al
mov [edi+2],byte 20h
add edi,3
inc esi
loop lp
mov [edi],byte 0ah
mov ecx,buffer
mov eax,4
lp2:
xor ebx,ebx
inc ebx
mov edx,31h
int 80h
mov eax,1
mov ebx,0
int 80h
hex:
or ecx,edi
adc [edx],eax
popfd
jz lp2
pop ebx
fadd dword [ecx+56h]
lds esp,[ebx+56h]
mov al,al
section .bss
buffer resb 31h

No comments: