News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

What's wrong with this code

Started by Rainstorm, April 09, 2007, 11:50:49 PM

Previous topic - Next topic

Jimg

Hutch-
  Well, I'm certainly not going to worry about mac files :snooty:

As for the error, did you try it making a debug build?  I used these parameters - /c /coff /Cp /nologo /Fm /Zi /Zd /Fl /Sn

And I get this-
00000014  33 C9   invoke read_disk_file,addr fname,addr pfbuff, addr flen
00000016  83 F8 00   xor ecx,ecx
  cmp eax, 0
 
F:\WinAsm\Progs\AMiscTests\consoletest2\Console.Asm(26) : error A2006: undefined symbol : @@
  jne @f

     2       LOCAL nustr
= "      2         quot SUBSTR <"file open error">,1,1
     2       IFIDN quot,<">           
00000019 0000002E      2         .data
0000002E 66 69 6C 65 20     2           ??0019 db "file open error",0       
   6F 70 65 6E 20
   65 72 72 6F 72
   00
00000021      2         .code
     2         EXITM <ADDR ??0019>     
00000021  68 0000002E R   *     push   OFFSET ??0019
00000026  E8 00000000 E   *     call   StdOut
     1         invoke StdOut,reparg("file open error")
     1       IFNB <13,10>
     2         LOCAL txtname
0000002B 0000003E      2         .data
0000003E 0D 0A 00      2           ??001A db 13,10,0
0000002B      2         .code
     2         EXITM <OFFSET ??001A>
0000002B  68 0000003E R   *     push   dword  ptr OFFSET FLAT:??001A
00000030  E8 00000000 E   *     call   StdOut
     1         invoke StdOut,chr$(13,10)
     1       ENDIF
  print "file open error",13,10
     1       IFDIF <>,<NULL>                 
     1         IFNB <>                       
     1           print                        ;; print user defined text
     1         ELSE                                    ;; else
     1           print "Press any key to continue ..." ;; print default text
     3       LOCAL nustr
= "      3         quot SUBSTR <"Press any key to continue ...">,1,1
     3       IFIDN quot,<">           
00000035 00000041      3         .data
00000041 50 72 65 73 73     3           ??001B db "Press any key to continue ...",0       
   20 61 6E 79 20
   6B 65 79 20 74
   6F 20 63 6F 6E
   74 69 6E 75 65
   20 2E 2E 2E 00
00000035      3         .code
     3         EXITM <ADDR ??001B>     
00000035  68 00000041 R   *     push   OFFSET ??001B
0000003A  E8 00000000 E   *     call   StdOut
     2         invoke StdOut,reparg("Press any key to continue ...")
     2       IFNB <>
     2         invoke StdOut,chr$()
     2       ENDIF
     1         ENDIF
     1       ENDIF
0000003F  E8 00000000 E     1       call wait_key
     1       print chr$(13,10)
     3         LOCAL txtname
00000044 0000005F      3         .data
0000005F 0D 0A 00      3           ??001C db 13,10,0
00000044      3         .code
     3         EXITM <OFFSET ??001C>
     3       LOCAL nustr
= O      3         quot SUBSTR <OFFSET ??001C>,1,1
     3       IFIDN quot,<">           
     3         .data
     3           ??001D db OFFSET ??001C,0       
     3         .code
     3         EXITM <ADDR ??001D>     
     3       ELSE
     3         EXITM <OFFSET ??001C>             
00000044  68 0000005F R   *     push   dword  ptr OFFSET FLAT:??001C
00000049  E8 00000000 E   *     call   StdOut
     2         invoke StdOut,reparg(OFFSET ??001C)
     2       IFNB <>
     2         invoke StdOut,chr$()
     2       ENDIF
  inkey
     1       IFNDEF
0000004E  6A 00    *     push   +000000000h
00000050  E8 00000000 E   *     call   ExitProcess
     1         invoke ExitProcess, 0
     1       ELSE
     1         invoke ExitProcess,
     1       ENDIF
  exit
00000055
00000055  33 F6 @@:
00000057  8B 35 0000000A R     xor esi, esi
0000005D  EB 05     mov esi, pfbuff       ; move the address into esi


Sorry for the mess, but I would like to get to the bottom of this.  Perhaps you would like to move this part to a new thread?

hutch--

Jim,

I have not used debug builds since masm 6.0 in the early 90s in DOS. Does it build OK without the debug build, "/c /coff" minimum style ?
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Jimg

Yes, it assembles with no errors.  (But of course it won't link, but that's not what we're working on.)

Here's the minimum program that has the problem -
.nolist
include \masm32\include\masm32rt.inc
.listall
.code
start:
  jmp @f
  print "x"
@@:
  exit
end start

hutch--

Not here it doesn't.


Microsoft (R) Macro Assembler Version 6.15.8803
Copyright (C) Microsoft Corp 1981-2000.  All rights reserved.

Assembling: H:\asm3\rstorm\jimg\jimg.asm
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

Volume in drive H is WIN2K_H
Volume Serial Number is 20E8-3719

Directory of H:\asm3\rstorm\jimg

04/11/2007  03:58a                 117 jimg.asm
04/11/2007  03:58a                 997 jimg.obj
04/11/2007  03:58a               2,560 jimg.exe
               3 File(s)          3,674 bytes
               0 Dir(s)  19,336,445,952 bytes free
Press any key to continue . . .
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Rainstorm

QuoteOn entry, ECX isn't initialised to 0, so the first time around ECX actually has the file length (as returned by read_disk_file).
sinsi, that was it, : )  now it functions properly except if there is just one line in the file (then it returns 0 & not the proper character count) - but i realised that was because the EOF is on that 1st line itself so to speak, & I was using the zero terminator to check the EOF.
Same thing was happening with the last code hutch posted, i.e it shows a '0' charactercount if there is just one line in the file. - I will use the 'flen' method & that would eliminate that problem too.
jimg ,  am using the usual 6.14 version that comes with the masm package.

thanks all.

Rainstorm
-


Jimg

Rainstorm-

Glad you got it all working.  I didn't mean to hijack your thread, I'll start a new thread with my problem.


Rainstorm


Rainstorm

in, the below code ecx becomes 0 in the line  pre_count:
      xor ecx, ecx
yet in the end ecx seems to hold the right character count of the whole file & matches the file length
    mov scanned_length, ecx    <--- that line

how come ? that's weird

    .data

    pfbuff      dd  0
    flen        dd  0
    fname       db  "H:\Project\filetest1.txt",0
    count2      dd  0
scanned_length  dd  0,0
   
;----------------------------------------------------------------------

    .code
start:

  invoke read_disk_file,addr fname,addr pfbuff, addr flen 
  cmp eax, 0
  jne @F

  print "file open error",13,10
  inkey
  exit

@@:
    print "returned file length - "
    print ustr$(flen),13,10
    xor ecx, ecx
    mov esi, pfbuff
    jmp count_
   
  pre_count:

      xor ecx, ecx    <---  ecx 0 here
      add esi, 1
   
  count_:
    cmp ecx, flen           ; check for 'end of file'
    je exit_
    cmp byte ptr [esi], 10  ; check for 'end of line'
    je reset_count
    add ecx, 1           ; keep count of characters in ecx
    add esi, 1
    jmp count_

; --------------------------------------------------------
; replace the value in count1 with ecx if is less than the value in ecx
; --------------------------------------------------------
   
   reset_count:
      cmp ecx, count1
      jna pre_count
      mov count1, ecx
      jmp pre_count

;--------------------
; display the results
;--------------------

exit_:

    mov scanned_length, ecx    <-- ecx still holding the right character count of the whole file here
    free pfbuff

    print "scanned length - "
    print ustr$(scanned_length),13,10

    print "highest character count: - "
    print ustr$(count1),13,10

    inkey
    exit

end start

Jimg

apparently the very last line is the longest, and it doesn't have a newline on the end.

Rainstorm

yes that's true too.
i got it
actually because ecx gets reset the loop is running along in the buffer far past the file length.
thx