i am a complete newbie when it comes to assembly so please dont scream at me..
the objective of my project is to read from any text file copy everything and convert them to binary THEN covert that binary back to its original text and output that text into a new output file..
so this is my code
TITLE conversion and output to a file
;-----------------------------------------------------------------
;program description: read from a file then convert char to binary
;then convert back to text into output file
;author: Yao Jiang
;creation date: 12-01-09
;-----------------------------------------------------------------
include /masm32/include/masm32rt.inc
;-----------------------------------------------------------------
.data
inname db 'file1.txt',0
outname db 'file2.dat',0
inh dw ?
outh dw ?
buff db ?
;-----------------------------------------------------------------
.code
openfile:
mov dx, offset inname
mov ah, 3dh
mov al, 0 ;0 to open the file to read
int 21h
jc error ;check for error, ie file not found
;or cant be opened
mov inh, ax ;save file handle
read:
mov ah, 3fh ;read data from file
mov bx, inh
mov dx, offset buff
mov cx, 1 ;read 1 type
int 21h
jc error
cmp ax, cx ;check for end of file
jne endoffile
mov al, buff
call write
jmp read
endoffile:
mov ah, 3eh ;close file
mov bx, inh
int 21h
mov ah, 3eh
mov bx, outh
int 21h
PROC write
push ax bx cx dx
mov ah, 2
mov dl, buff
int 21h
pop ax bx cx dx
ret
ENDP
end start
;-----------------------------------------------------------------
so far nothing works, for some reason i cant open the file and im having trouble trying to do conversion before writing to the new file
PLEASE HELP!!!
by the way im using masm32 because professor told the class to
Comments
:
: TITLE conversion and output to a file
:
: ;-----------------------------------------------------------------
:
: ;program description: read from a file then convert char to binary
: ;then convert back to text into output file
: ;author: Yao Jiang
: ;creation date: 12-01-09
:
: ;-----------------------------------------------------------------
:
: include /masm32/include/masm32rt.inc
:
: ;-----------------------------------------------------------------
:
: .data
:
: inname db 'file1.txt',0
: outname db 'file2.dat',0
: inh dw ?
: outh dw ?
: buff db ?
:
: ;-----------------------------------------------------------------
:
: .code
[color=Red]: mov ax, @DATA
: mov ds, ax[/color]
:
: openfile:
:
: mov dx, offset inname
: mov ah, 3dh
: mov al, 0 ;0 to open the file to read
: int 21h
: jc error ;check for error, ie file not found
: ;or cant be opened
: mov inh, ax ;save file handle
:
: read:
:
: mov ah, 3fh ;read data from file
: mov bx, inh
: mov dx, offset buff
: mov cx, 1 ;read 1 type
: int 21h
: jc error
: cmp ax, cx ;check for end of file
: jne endoffile
: mov al, buff
: call write
: jmp read
:
: endoffile:
:
: mov ah, 3eh ;close file
: mov bx, inh
: int 21h
: mov ah, 3eh
: mov bx, outh
: int 21h
:
: PROC write
:
: push ax bx cx dx
: mov ah, 2
: mov dl, buff
: int 21h
: pop ax bx cx dx
: ret
:
: ENDP
:
: end start
:
: ;-----------------------------------------------------------------
:
: so far nothing works, for some reason i cant open the file and im
: having trouble trying to do conversion before writing to the new file
:
: PLEASE HELP!!!
:
: by the way im using masm32 because professor told the class to
:
:
[link=http://www.programmersheaven.com/download/21643/download.aspx]http://www.programmersheaven.com/download/21643/download.aspx[/link]
[/color]
1) the output file isn't opened, only the input file is, the code for it should look like this:
[code]
mov dx, offset outname
mov ah, 3dh
mov al, 1 ;1 to open the file to write
int 21h
jc error ;check for error, ie file not found
;or cant be opened
mov outh, ax ;save file handle
[/code]
2) your error handler is missing (I assume you just left it out to save space since you're also missing the "start:" label)
3) the exit command is missing, add this after closing the files:
[code]
mov ax, 4c00h
int 21h
[/code]
4) registers must be popped back in reverse order
5) your writing to file code is missing, try this:
[code]
PROC write
push ax bx cx dx
mov ah, 2
mov dl, buff
int 21h
[color=Red]
mov ah, 40h
mov bx, outh
mov cx, 1
mov dx, offset buff
int 21h
pop dx cx bx ax
[/color]
ret
ENDP
[/code]
mov ax, @data
i keep getting the error "undefined symbol"
[code]
mov ax, data
mov ax, seg inname
[/code]
Also, consider that the strength of Masm32 is 32-bit Windows programming. For 16-bit, [link=http://flatassembler.net/]Fasm[/link] is more suitable.