2014-01-19 104 views
0

我试图将ascii字符转换为二进制文件。 我正在从这个txt文件中读取字符串。如何将ascii字符转换为二进制文件emu8086

; 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 'ABCDEF' 


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不会随着更新的var而改变。

+0

ASCII字符只是一个二进制字节值的解释*。 –

+0

谢谢Jonathon,是的,我知道。但如何将每个字从十六进制转换为字节? –

回答

相关问题