News:

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

FASMLIB 0.4

Started by vid, December 18, 2006, 08:32:17 PM

Previous topic - Next topic

hutch--

I have worked out how to duplicate the problem you mentioned. You just need to know a bit more about masm to display the problem as the examples you posted did not

Do it like this.


    mov pbuf, input("Enter Text ",62," ")

    .data
      txt db "Trailing text AFTER the input macro",13,10
          db "If you can read these lines then the ascii 13 preceding it has not been overwritten",13,10,0
    .code

    print OFFSET txt


MASM write data sequentially so the test data "txt" is directly after the text buffer for the "input" macro and this is able to demonstrate the problem you mentioned if you enter > 127 characters at the console.

The basics of doing a bug report is to post a reproducable problem where none of your examples did this.

I will post the fix for it reasonably soon now that the problem is identified. Just helps to make the masm32 macro system a little smaller.  :bg
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

vid

 :dazzled: :dazzled: :dazzled:

i tried to explain that to you at least three times!!! And I gave you sources and binary of example which reproduced the problem.

So, another thing: The real length of input cannot be determined from buffer contents. You *must* use returned size. (hope i won't need another 10 posts to prove)

hutch--

Here is the fixup. What I needed was a lot less errors in what the problem was and a report of what happened.
Quote
Is input macro intended to overwrite data behind the read buffer?.
This is what I needed to know.

Macro allocates 132 bytes in the uninitialised data section but only passes 128 bytes to the StdIn procedure. Code writes zero terminator at the end of the written buffer then the StripLF algo truncates the line on any ascii13 to a zero and exits on zero if it finds it first.


; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    include \masm32\include\masm32rt.inc
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

comment * -----------------------------------------------------
                        Build this  template with
                       "CONSOLE ASSEMBLE AND LINK"
        ----------------------------------------------------- *

    inputx MACRO prompt:VARARG
      LOCAL txt
      LOCAL buffer
      IFNB <prompt>
        .data
          txt db prompt, 0
          align 4
        .data?
          buffer db 132 dup (?)
          align 4
        .code
        invoke StdOut,ADDR txt
        invoke StdIn,ADDR buffer,128
        mov BYTE PTR [buffer+eax], 0
        invoke StripLFx,ADDR buffer
        EXITM <OFFSET buffer>
      ELSE
        .data?
          buffer db 132 dup (?)
          align 4
        .code
        invoke StdIn,ADDR buffer,128
        mov BYTE PTR [buffer+eax], 0
        invoke StripLFx,ADDR buffer
        EXITM <OFFSET buffer>
      ENDIF
    ENDM

    .code

start:
   
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    call main
    inkey
    exit

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

main proc

    LOCAL pbuf  :DWORD
    LOCAL blen  :DWORD
    LOCAL phex  :DWORD

    mov pbuf, input("Enter text ",62," ")
    mov blen, len(pbuf)
    add eax, eax
    add eax, eax
    mov phex, alloc(eax)

    .data
      txt db "Howdy",13,10,"If you can you see me, it works. :)",13,10,0
    .code

    print OFFSET txt

    invoke bin2hex,pbuf,blen,phex
    print phex,13,10

    free phex

    ret

main endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE

StripLFx proc src:DWORD

    mov eax, [esp+4]
    sub eax, 1
  @@:
    add eax, 1
    cmp BYTE PTR [eax], 0
    je tlfout
    cmp BYTE PTR [eax], 13
    jne @B

    mov BYTE PTR [eax], 0
    ret 4

  tlfout:
    ret 4

StripLFx endp

OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

end start

[attachment deleted by admin]
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

hutch--

Here is your Christmas present.  :bg

I played with fasm some months ago to build a library that could be used by POASM or MASM. This has a couple of test modules, a batch file and Pelle's library manager from the MASM32 Project. The MAKEIT.BAT file has the build method and as usual you will need to set the path to fasm.

These two test modules use C calling convention as I don't know enough about fasm to set them to STDCALL but I am sure its an easy task.

[attachment deleted by admin]
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

vid

I believe 129 bytes would be enough.

For your purpose (read and handle entire line at once) this solution should be enough.

But this is pretty unstandard and IMO worser than typical way of reading console - where you only read as much as you are interested in. For example, when user wants to read number, and on input you have "123abc", then "123" is readen and returned, and "abc" is left to read. Of course this needs some buffering. I believe those are functions like this, which people await from library.

Thanks for your present. I understand how to create .lib with FASM now. I am just solving issue how to do it without breaking my sources into dozen files.

nice xmas to everyone