Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×
User Journal

Journal clone53421's Journal: ASCII-to-binary (80x86)

ASCII-to-binary in 80x86 assembly (oblig: Binary-to-ASCII)

@echo off
goto batch
 
a
        mov ax,cs
        mov ds,ax
        xor ch,ch ;initialize column counter
;_newchar
        mov ah,08
        int 21 ;get a key
        cmp al,1b ;check for esc
        jz 0159 ;goto _quit
        cmp al,1a ;check for ^z
        jz 0159 ;goto _quit
        mov ah,0a
        xor bh,bh
        mov dh,ch ;preserve column counter
        mov cx,1
        int 10 ;send to console in case output is redirected
        mov ch,dh ;restore column counter
        mov cl,8
        mov ah,02
;_nextbit
        mov dl,30 ;set output char to "0"
        shl al,1
        jnb 012b ;goto _iszero
        inc dl ;change output char to "1"
;_iszero
        mov bl,al ;preserve input char
        int 21 ;print "0" or "1"
        mov al,bl ;restore input char
        dec cl ;decrement the bit counter
        jnz 0123 ;goto _nextbit
        add ch,8 ;increase the column counter
        add ch,[0180] ;add _padlen
        and ch,7f ;don't allow ch to go above 127
        cmp ch,47 ;see if we're overflowing the line
        jnb 014d ;goto _crlf
        mov ah,09
        mov dx,017e ;address of _padding
        int 21 ;print padding string
        jmp 0106 ;goto _newchar
;_crlf
        xor ch,ch ;reset the column counter
        mov dl,0d
        int 21 ;print cr
        mov dl,0a
        int 21 ;print lf
        jmp 0106 ;goto _newchar
;_quit
        mov ah,03
        xor bh,bh
        int 10 ;get cursor position
        mov ah,08
        int 10 ;preserve character under cursor
        mov ah,02
        mov bl,al
        mov cx,dx
        mov dl,1a
        int 21 ;send ^z
        mov dx,cx
        int 10 ;restore cursor position
        mov ah,0a
        mov al,bl
        mov cx,1
        int 10 ;restore character under cursor
        mov ah,4c
        int 21 ;return to dos
;_padding
        db " ","$"
;_padlen
        db 1
;_ASCIIZ
        db "asc2bin.com",0
;_compile
        MOV AX,CS
        MOV DS,AX
        MOV AH,3C
        XOR CX,CX
        MOV DX,0181 ;_ASCIIZ
        INT 21
        MOV BX,AX
        MOV CX,0181 ;_ASCIIZ
        MOV DX,0100
        SUB CX,DX
        MOV AH,40
        INT 21
        MOV AH,3E
        INT 21
        MOV AX,4C01
        INT 21
 
r ip
18d
g
q
 
:exists
echo You don't need to run this. Run ASC2BIN.COM instead.
goto run
 
:batch
if exist asc2bin.com goto exists
 
if exist %0 goto extension
debug < %0.bat
goto run
 
:extension
debug < %0
 
:run
pause
cls
asc2bin.com

Assembly: Copy and paste into Notepad. Save as "asc2bin-asm.bat" (include the quotes to force the extension). Run the batch file in Windows by double-clicking or by executing it from the command prompt. On its first run, the batch file will run debug.exe and assemble the asc2bin.com executable in the current directory. After assembling the executable the batch will launch it. (Subsequently you can launch the executable without need for the batch file.)

Use: Type or paste (using the sys menu on the command prompt window) into the DOS window. Use the sys menu to copy the output. Esc or ^Z exit.

This discussion has been archived. No new comments can be posted.

ASCII-to-binary (80x86)

Comments Filter:

A morsel of genuine history is a thing so rare as to be always valuable. -- Thomas Jefferson

Working...