x86 Assembly

Moderators: None (Apply to moderate this forum)
Number of threads: 4563
Number of posts: 16029

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
HELP ME PLEASE!!! it is a project i have to do... Posted by yaochen42 on 3 Dec 2009 at 5:08 PM
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

Report
Re: HELP ME PLEASE!!! it is a project i have to do... Posted by yaochen42 on 4 Dec 2009 at 5:22 PM
anyone??? please help!!!
Report
Re: HELP ME PLEASE!!! it is a project i have to do... Posted by AsmGuru62 on 5 Dec 2009 at 5:33 AM
Segment register(s) not set - see RED...
:
: 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

: mov ax, @DATA
: mov ds, ax

:
: 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
:
:
Report
Re: HELP ME PLEASE!!! it is a project i have to do... Posted by yaochen42 on 5 Dec 2009 at 10:53 AM
i just do the same thing and its still not working... still giving the error "cannot open file"
Report
Re: HELP ME PLEASE!!! it is a project i have to do... Posted by AsmGuru62 on 6 Dec 2009 at 5:51 AM
I do not have masm32 - I use FASM, so I can't really run the code and see. Do you have a debugger? If not, I suggest AFD - it is an OK debugger for DOS code. You can get it here:

http://www.programmersheaven.com/download/21643/download.aspx
Report
Re: HELP ME PLEASE!!! it is a project i have to do... Posted by yaochen42 on 10 Dec 2009 at 2:15 PM
for the line

mov ax, @data

i keep getting the error "undefined symbol"
Report
Re: HELP ME PLEASE!!! it is a project i have to do... Posted by anthrax11 on 10 Dec 2009 at 5:14 PM
Try one of these:
mov ax, data
mov ax, seg inname

Also, consider that the strength of Masm32 is 32-bit Windows programming. For 16-bit, Fasm is more suitable.
Report
Re: HELP ME PLEASE!!! it is a project i have to do... Posted by anthrax11 on 6 Dec 2009 at 11:25 AM
I haven't tested it, but it seems that:

1) the output file isn't opened, only the input file is, the code for it should look like this:
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

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:
mov ax, 4c00h
int 21h

4) registers must be popped back in reverse order
5) your writing to file code is missing, try this:
PROC write

push ax bx cx dx
mov ah, 2
mov dl, buff
int 21h

mov ah, 40h
mov bx, outh
mov cx, 1
mov dx, offset buff
int 21h

pop dx cx bx ax

ret

ENDP




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.