Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Help

[b][red]This message was edited by oldandtired at 2006-3-5 21:13:49[/red][/b][hr]
[b][red]This message was edited by oldandtired at 2006-3-5 21:13:7[/red][/b][hr]
I'm a beginning assembler. I'm supposed to open and read a text file, then print the contents to the screen. It opens the file, reads the file and outputs it to the screen, but a load of random characters follow. Could someone please look at my code and see if you can figure this out? I copied the screen output and pasted it in at the bottom so you can see what I mean. There should be enough comments to help you figure out what I'm doing. Thanks-C

(top part of code-I think it has to do with this section. FYI- I set aside 200 bytes of buffer area in my code)

DATA SEGMENT
;directive to define byte data
;string data definition
;
TITLE1 DB 'Hello world',13,10,'$'
FILENAME BYTE 'D:DATA.TXT',0 ;(0 terminates string)
INHANDLE WORD ?
BYTESREAD WORD ?
BUFFER BYTE ?
DATA ENDS
;*************
STACK SEGMENT STACK
;generates a repeated storage allocation, using constant expression as counter
DB 32 DUP ('STACK ')
STACK ENDS
;***********
_____________________________________________________________
(screen output)


Hello world

Hey Paul, do you understand how we did this?
Yo Kira, how does this look now?
STACK STACK STACK STACK STACK STACK STACK STACK STACK STACK
STACK STACK STACK STACK STACK STACK STACK STACK STACK P
? + ? ? ?? n?^?V ??2 ?-?+n?+?+ ??-? -!+lq+ ? +? -!r3
? ??? + ? -!r ? ?+ ??-? ? -!r
>?? -!r + L-!NNB08`? CV?
Tenth10.obj?
? ? ? ? ?Tenth10.obj6 ? ?? /Microsoft (R) Macro
Assembler Version 6.15.8803?6-??-?? K?
M?? O?+h??+F+?-x?% =? ?s?x?
j?? ?p??t??h???P+p%+L+?+dJ-!X?+ ?+ ? [?+O?- +-?, ?+t??
d?FX?+?-!+?
3+?+!++ ?+!3-6+!?+ ?+!=u?T = tKVP=? u86+!;t.:? t)< t:?l?u?FV?:
? t :?+ d?ZZT??ZZT( X^-F-?Fdnd>!?!u?du>!?!u?d>!Press any key to
continue . . .





Comments

  • tsagldtsagld Member Posts: 621
    : [b][red]This message was edited by oldandtired at 2006-3-5 21:13:49[/red][/b][hr]
    : [b][red]This message was edited by oldandtired at 2006-3-5 21:13:7[/red][/b][hr]
    : I'm a beginning assembler. I'm supposed to open and read a text file, then print the contents to the screen. It opens the file, reads the file and outputs it to the screen, but a load of random characters follow. Could someone please look at my code and see if you can figure this out? I copied the screen output and pasted it in at the bottom so you can see what I mean. There should be enough comments to help you figure out what I'm doing. Thanks-C
    :
    : (top part of code-I think it has to do with this section. FYI- I set aside 200 bytes of buffer area in my code)
    :
    : DATA SEGMENT
    : ;directive to define byte data
    : ;string data definition
    : ;
    : TITLE1 DB 'Hello world',13,10,'$'
    : FILENAME BYTE 'D:DATA.TXT',0 ;(0 terminates string)
    : INHANDLE WORD ?
    : BYTESREAD WORD ?
    : BUFFER BYTE ?
    : DATA ENDS
    : ;*************
    : STACK SEGMENT STACK
    : ;generates a repeated storage allocation, using constant expression as counter
    : DB 32 DUP ('STACK ')
    : STACK ENDS
    : ;***********
    : _____________________________________________________________
    : (screen output)
    :
    :
    : Hello world
    :
    : Hey Paul, do you understand how we did this?
    : Yo Kira, how does this look now?
    : STACK STACK STACK STACK STACK STACK STACK STACK STACK STACK
    : STACK STACK STACK STACK STACK STACK STACK STACK STACK P
    : ? + ? ? ?? n?^?V ??2 ?-?+n?+?+ ??-? -!+lq+ ? +? -!r3
    : ? ??? + ? -!r ? ?+ ??-? ? -!r
    : >?? -!r + L-!NNB08`? CV?
    : Tenth10.obj?
    : ? ? ? ? ?Tenth10.obj6 ? ?? /Microsoft (R) Macro
    : Assembler Version 6.15.8803?6-??-?? K?
    : M?? O?+h??+F+?-x?% =? ?s?x?
    : j?? ?p??t??h???P+p%+L+?+dJ-!X?+ ?+ ? [?+O?- +-?, ?+t??
    : d?FX?+?-!+?
    : 3+?+!++ ?+!3-6+! ?+ ?+!= u?T = tKVP=? u86+!;t.:? t)< t:?l?u?FV?:
    : ? t :?+ d?ZZT??ZZT( X^-F-?Fdnd>!?!u?du>!?!u?d>!Press any key to
    : continue . . .
    :
    :
    :
    :
    :
    :

    You didn't post the code that actually reads and prints the file. Hard to tell this way.


    Greets,
    Eric Goldstein
    www.gvh-maatwerk.nl

  • oldandtiredoldandtired Member Posts: 10
    [b][red]This message was edited by oldandtired at 2006-3-7 7:50:24[/red][/b][hr]
    [b][red]This message was edited by oldandtired at 2006-3-7 7:49:39[/red][/b][hr]
    Be nice now. Remember- I'm a novice. Please tell me what I'm missing here.

    ; opens the file
    MOV AX,716Ch ;extended create or open file
    MOV BX,0 ;read only mode
    MOV CX,0 ;normal attribute
    MOV DX,1 ;action: open existing file
    MOV SI,OFFSET FILENAME ;points to FILENAME
    INT 21h
    JNC SUCCESS ;jump to SUCCESS if file opened
    ;
    MOV DX,OFFSET NOOPEN ;otherwise, output error message
    MOV AH,9
    INT 21h
    JMP QUIT ;jump to QUIT and skip ELSE41
    ;
    SUCCESS:
    ;
    MOV INHANDLE,AX
    ; print out success message
    MOV AH,9
    MOV DX,OFFSET YESOPEN
    INT 21h
    ;
    ; Read the input file
    MOV AH,3Fh ;read file
    MOV BX,INHANDLE ;file handle
    MOV CX,200 ;max bytes to read
    MOV DX,OFFSET BUFFER ;points to buffer
    INT 21h
    JC QUIT ;quit if error
    MOV BYTESREAD,AX
    ;
    ; Output the read file to the screen
    MOV AH,9
    MOV DX,OFFSET BUFFER
    INT 21h
    ;
    ; close the file
    MOV AH,3Eh ;function: closes file
    MOV BX,INHANDLE ;input file handle
    INT 21h
    ;
    QUIT:
    MOV AX,4c00h ;end program, return to DOS
    INT 21h
    ;
    PROG10 ENDP
    CODE ENDS
    END PROG10
















    : : [b][red]This message was edited by oldandtired at 2006-3-5 21:13:49[/red][/b][hr]
    : : [b][red]This message was edited by oldandtired at 2006-3-5 21:13:7[/red][/b][hr]
    : : I'm a beginning assembler. I'm supposed to open and read a text file, then print the contents to the screen. It opens the file, reads the file and outputs it to the screen, but a load of random characters follow. Could someone please look at my code and see if you can figure this out? I copied the screen output and pasted it in at the bottom so you can see what I mean. There should be enough comments to help you figure out what I'm doing. Thanks-C
    : :
    : : (top part of code-I think it has to do with this section. FYI- I set aside 200 bytes of buffer area in my code)
    : :
    : : DATA SEGMENT
    : : ;directive to define byte data
    : : ;string data definition
    : : ;
    : : TITLE1 DB 'Hello world',13,10,'$'
    : : FILENAME BYTE 'D:DATA.TXT',0 ;(0 terminates string)
    : : INHANDLE WORD ?
    : : BYTESREAD WORD ?
    : : BUFFER BYTE ?
    : : DATA ENDS
    : : ;*************
    : : STACK SEGMENT STACK
    : : ;generates a repeated storage allocation, using constant expression as counter
    : : DB 32 DUP ('STACK ')
    : : STACK ENDS
    : : ;***********
    : : _____________________________________________________________
    : : (screen output)
    : :
    : :
    : : Hello world
    : :
    : : Hey Paul, do you understand how we did this?
    : : Yo Kira, how does this look now?
    : : STACK STACK STACK STACK STACK STACK STACK STACK STACK STACK
    : : STACK STACK STACK STACK STACK STACK STACK STACK STACK P
    : : ? + ? ? ?? n?^?V ??2 ?-?+n?+?+ ??-? -!+lq+ ? +? -!r3
    : : ? ??? + ? -!r ? ?+ ??-? ? -!r
    : : >?? -!r + L-!NNB08`? CV?
    : : Tenth10.obj?
    : : ? ? ? ? ?Tenth10.obj6 ? ?? /Microsoft (R) Macro
    : : Assembler Version 6.15.8803?6-??-?? K?
    : : M?? O?+h??+F+?-x?% =? ?s?x?
    : : j?? ?p??t??h???P+p%+L+?+dJ-!X?+ ?+ ? [?+O?- +-?, ?+t??
    : : d?FX?+?-!+?
    : : 3+?+!++ ?+!3-6+! ?+ ?+!= u?T = tKVP=? u86+!;t.:? t)< t:?l?u?FV?:
    : : ? t :?+ d?ZZT??ZZT( X^-F-?Fdnd>!?!u?du>!?!u?d>!Press any key to
    : : continue . . .
    : :
    : :
    : :
    : :
    : :
    : :
    :
    : You didn't post the code that actually reads and prints the file. Hard to tell this way.
    :
    :
    : Greets,
    : Eric Goldstein
    : www.gvh-maatwerk.nl
    :
    :





  • anthrax11anthrax11 Member Posts: 511
    : [b][red]This message was edited by oldandtired at 2006-3-7 7:50:24[/red][/b][hr]
    : [b][red]This message was edited by oldandtired at 2006-3-7 7:49:39[/red][/b][hr]
    : Be nice now. Remember- I'm a novice. Please tell me what I'm missing here.
    :
    : ; opens the file
    : MOV AX,716Ch ;extended create or open file
    : MOV BX,0 ;read only mode
    : MOV CX,0 ;normal attribute
    : MOV DX,1 ;action: open existing file
    : MOV SI,OFFSET FILENAME ;points to FILENAME
    : INT 21h
    : JNC SUCCESS ;jump to SUCCESS if file opened
    : ;
    : MOV DX,OFFSET NOOPEN ;otherwise, output error message
    : MOV AH,9
    : INT 21h
    : JMP QUIT ;jump to QUIT and skip ELSE41
    : ;
    : SUCCESS:
    : ;
    : MOV INHANDLE,AX
    : ; print out success message
    : MOV AH,9
    : MOV DX,OFFSET YESOPEN
    : INT 21h
    : ;
    : ; Read the input file
    : MOV AH,3Fh ;read file
    : MOV BX,INHANDLE ;file handle
    : MOV CX,200 ;max bytes to read
    : MOV DX,OFFSET BUFFER ;points to buffer
    : INT 21h
    : JC QUIT ;quit if error
    : MOV BYTESREAD,AX
    : ;
    : ; Output the read file to the screen
    : MOV AH,9
    : MOV DX,OFFSET BUFFER
    [blue]
    MOV DI,DX
    ADD DI,BYTESREAD
    MOV BYTE PTR[DI],'$' ;Message must be ended with a '$' character
    [/blue]
    : INT 21h
    : ;
    : ; close the file
    : MOV AH,3Eh ;function: closes file
    : MOV BX,INHANDLE ;input file handle
    : INT 21h
    : ;
    : QUIT:
    : MOV AX,4c00h ;end program, return to DOS
    : INT 21h
    : ;
    : PROG10 ENDP
    : CODE ENDS
    : END PROG10
    :
    :
    [blue]See, this is why one shouldnt post the same message to different message boards. There is no need for people to think twice. I already replied to the other post.and although I gave you the general idea of the problem, but made a typeo there, the above code should work fine.
  • oldandtiredoldandtired Member Posts: 10
    Anthrax-You're upset because I posted this message twice? If so, I apologize. I posted them both at the same time, thinking that one might get replied to sooner than the other and I had a deadline.It won't happen again since I know how great you guys are in replying to posts now.

    My teacher wanted me to use my own code, so I thought I would just go ahead and post my code here first, instead of using yours, to see what I was doing wrong with what I had already. As you know, I didn't post my whole code on the other message board.Please accept my apologies if I have offended you.


    : [blue]See, this is why one shouldnt post the same message to different message boards. There is no need for people to think twice. I already replied to the other post.and although I gave you the general idea of the problem, but made a typeo there, the above code should work fine.
    :

  • anthrax11anthrax11 Member Posts: 511
    : Anthrax-You're upset because I posted this message twice? If so, I apologize. I posted them both at the same time, thinking that one might get replied to sooner than the other and I had a deadline.It won't happen again since I know how great you guys are in replying to posts now.
    :
    [blue]I tried not to be as rough as I turned out to be. Sorry. I'm just glad you understand how cross-posting is a rather unnecessary thing to do.[/blue]

    : My teacher wanted me to use my own code, so I thought I would just go ahead and post my code here first, instead of using yours, to see what I was doing wrong with what I had already. As you know, I didn't post my whole code on the other message board.Please accept my apologies if I have offended you.
    :
    :
    [blue]You are welcome to post your own code here! In fact, you should. It shows us, that you have thought about the problem, you've tried to solve it and you're not just asking for someone to do your homework.

    I don't have anything against you:p[/blue]
Sign In or Register to comment.