Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Prog challenge:

Name: Anonymous 2009-05-25 1:16

Write Ascii85 to binary converter in 10 lines of code.
Hard Mode: Using Python.
Hardcore Mode: in Esoteric language of your choice.

Name: Anonymous 2009-05-25 1:46

.286
cseg segment
assume cs:cseg, ds:cseg, es:cseg, ss:cseg
org 256
entrypoint:
    mov di, offset outbuffer
main_loop:
    xor bx, bx  ; low word of developing dord
    xor dx, dx  ; high word of developing dord
    mov bp, 5   ; how much development the dord has remaining
read_loop:
    call GetChar
cmp_start:
    inc ax
    jz do_eof
    cmp al, 21h
    jz read_loop
    cmp al, 0ah
    jz read_loop
    cmp al, 0eh
    jz read_loop
    cmp al, 0bh
    jz read_loop
    cmp al, 'z'+1
    jz do_z
    cmp al, '~'+1
    jz do_efd
    cmp al, '!'+1
    jb read_loop
    cmp al, 'u'+1
    ja read_loop
    sub al, '!'+1   ; develop the dord - turn into a digit 0 - 84
    xchg bx, ax     ; put it away for now
    call mul85      ; multiply existing dord
    add ax, bx      ; add this new one to it
    jnc nov
    inc dx          ; take high one too
nov:
    xchg ax, bx     ; put it back
    dec bp
    jnz read_loop   ; dord developed yet? no? otherwise just write it out
write_dord:
    xchg ax, dx
    xchg al, ah
    stosw
    xchg ax, bx
    xchg al, ah
    stosw
; check for overflow
    cmp di, offset outbuffer+28160
    jb main_loop
    push offset entrypoint
do_wr:
    mov dx, offset outbuffer
    mov cx, di
    sub cx, dx
    jz do_wr_n
    mov ah, 40h
    mov bx, 1
    int 21h
do_wr_n:
    ret
do_z:
    cmp bp, 5
    jnz read_loop
do_z_ok:    ; write a null dord
    xor bx, bx
    xor dx, dx
    jmp short write_dord
do_efd:
    call GetChar
    cmp al, '>'
    jnz cmp_start
do_eof:
    cmp bp, 5       ; no partial dord
    jz do_wr
    xchg ax, bx
    mov bx, bp
do_eof_dev:     ; develop the final dord to maturity
    call mul85
    dec bp
    jnz do_eof_dev
    neg bx
    add bx, 4
    jz do_wr
    mov cx, bx
;-- rounding fix --
    dec bx
    jnz rn2
    add dx, 128
    jmp short writebytesloop
rn2:
    dec bx
    jnz rn3
    add ah, 128
    jmp short rn35
rn3:
    add ax, 128
rn35:
    jnc writebytesloop
    inc dx
;------------------
writebytesloop:
    xchg dh, al
    xchg dh, dl
    xchg dl, ah
    stosb
    loop writebytesloop
    jmp short do_wr
mul85:  ; multiply DX:AX by 85 and leave the result in DX:AX
        ; no overflow check!
    push bx
    push cx
    mov bl, 85  ; bh already 0
    push dx
    mul bx
    pop cx
    push dx
    xchg ax, cx
    mul bx
    pop dx
    add ax, dx
    xchg ax, dx
    xchg ax, cx
    pop cx
    pop bx
    ret
GetChar:
    mov ax, inbufcnt
    or ax, ax
    jnz GetChar_NI
    push bx
    push cx
    push dx
    xchg ax, bx
    mov ah, 3fh
    mov cx, 35200
    mov dx, offset inbuffer
    int 21h
    mov si, dx
    pop dx
    pop cx
    pop bx
    mov inbufcnt, ax
    or ax, ax
    jnz GetChar_NI
    dec ax
    ret
GetChar_NI:
    xor ax, ax
    lodsb
    dec word ptr inbufcnt
    ret
inbufcnt dw 0
inbuffer db 35200 dup (?)
outbuffer db 28160 dup (?)
cseg ends
end entrypoint

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List