我试图将ascii字符转换为二进制。 我正在用txt文件读取字符串。
; emu8086 version 4.00-Beta-12 or better is required!
; put file named "input.txt" to c:\emu8086\vdrive\c\
; (it's possible to copy "ReadMe.txt" and rename it or use any other
;file that contains ASCII chars).
org 100h ; .com memory layout
mov dx, offset file ; address of file to dx
mov al,0 ; open file (read-only)
mov ah,3dh
int 21h ; call the interupt
jc terminate ; if error occurs, terminate program
mov bx,ax ; put handler to file in bx
mov cx,1 ; read one character at a time
print:
lea dx, BUF
mov ah,3fh ; read from the opened file (its handler in bx)
int 21h
CMP AX, 0 ; how many bytes transfered?
JZ terminate ; end program if end of file is reached (no bytes
;left).
mov al, BUF ; char is in BUF, send to ax for printing (char is
;in al)
mov ah,0eh ; print character (teletype).
int 10h
jmp print ; repeat if not end of file.
terminate:
mov ah, 0 ; wait for any key...
int 16h
ret
file db "input.txt", 0
BUF db ?
END
所以,我想打印到屏幕的第一个256字节。
总结一下, 输入:任何文件, 输出如下: 文件名:input.txt
00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
A0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
B0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
C0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
D0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
E0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
F0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
编辑:
我改变了这个明智的代码
org 100h ; .com memory layout
table DB '0123456789ABCDEF'
mov dx, offset file ; address of file to dx
mov al,0 ; open file (read-only)
mov ah,3dh
int 21h ; call the interupt
jc terminate ; if error occurs, terminate program
mov bx,ax ; put handler to file in bx
mov cx,1 ; read one character at a time
print:
lea dx, BUF
mov ah,3fh ; read from the opened file (its handler in bx)
int 21h
CMP AX, 0 ; how many bytes transfered?
;JZ terminate ; end program if end of file is reached (no bytes
;left).
mov al, BUF ; char is in BUF, send to ax for printing (char is
;in al)
; hex i ekrana bastirma kismi, fakat bu kodlardan sonra
; buf degismiyor.. ancak sadece ekrana yazdirirsak buf degisiyor
MOV DL, AL
LEA BX, table ; load data table.
MOV AL, DL
SHR AL, 4 ; leave high part only.
XLAT ; get hex digit.
MOV AH, 0Eh ; teletype sub-function.
INT 10h
MOV AL, DL
AND AL, 0Fh ; leave low part only.
XLAT ; get hex digit.
mov ah,0eh ; print character (teletype).
int 10h
jmp print ; repeat if not end of file.
;mov ah,0eh ; print character (teletype).
;int 10h
;jmp print ; repeat if not end of file.
terminate:
mov ah, 0 ; wait for any key...
int 16h
ret
file db "input.txt", 0
BUF db ?
END
但是在这个时候,BUF var不会随着更新的变化而变化。
答案 0 :(得分:0)
谷歌稍微透露了这一页:
http://www.dailyfreecode.com/code/convert-hexadecimal-number-binary-1746.aspx
您一定会了解如何将其移植到您想要的平台。