Journal clone53421's Journal: Binary-to-ASCII (80x86)
Binary-to-ASCII in 80x86 assembly (oblig: ASCII-to-binary)
@echo off
goto batch
a
mov ax,cs
mov ds,ax
xor bh,bh;page number (always 0)
;_begin
xor cx,cx;initialize bit count (ch) and ascii char (cl)
mov ah,08
int 10;get the character under the cursor
mov bl,al;save it so we can restore it later
;_getch
mov ah,08
int 21;get a key
cmp al,1b;check for esc
jz 014d;goto _quit
cmp al,1a;check for ^z
jz 014d;goto _quit
cmp al,30;check for "0"
jz 0124;goto _procch
cmp al,31;check for "1"
jz 0124;goto _procch
jmp 010e;goto _getch
;_procch
mov ah,0a
mov dx,cx;preserve bit count & ascii char
mov cx,1
int 10;send typed digit to console
mov cx,dx;restore bit count & ascii char
shl cl,1;shift to make room for new bit
and al,1;convert ascii "0" and "1" to binary 0/1
or cl,al;put the new bit in the lsb of cl
inc ch;increment bit counter
cmp ch,8
jnz 010e;goto _getch
;_out
mov dl,cl;move ascii char to dl for output on int 21
mov ah,0a
mov al,bl;move original char to al for output
mov cx,1
int 10;restore the character that we overwrote
mov ah,02
int 21;print ascii char
jmp 0106;goto _begin
;_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
;_ASCIIZ
db "bin2asc.com",0
;_compile
MOV AX,CS
MOV DS,AX
MOV AH,3C
XOR CX,CX
MOV DX,0172;_ASCIIZ
INT 21
MOV BX,AX
MOV CX,0172;_ASCIIZ
MOV DX,0100
SUB CX,DX
MOV AH,40
INT 21
MOV AH,3E
INT 21
MOV AX,4C01
INT 21
r ip
17e
g
q
:exists
echo You don't need to run this. Run BIN2ASC.COM instead.
goto run
:batch
if exist bin2asc.com goto exists
if exist %0 goto extension
debug < %0.bat
goto run
:extension
debug < %0
:run
pause
cls
bin2asc.com
Assembly: Copy and paste into Notepad. Save as "bin2asc-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 bin2asc.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) binary into the DOS window. All characters other than '1', '0', Esc, and ^Z will be ignored (this allows the program to be forgiving of spaces or newline characters in the binary). Every 8 binary digits will be converted to the corresponding ASCII character. Use the sys menu to copy the output (if needed). Esc or ^Z exit.
Binary-to-ASCII (80x86) More Login
Binary-to-ASCII (80x86)
Slashdot Top Deals