News:

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

buffer to buffer display text

Started by AiaKonai, October 13, 2011, 01:21:52 PM

Previous topic - Next topic

AiaKonai

The following code is supposed to display
ab <- the two characters read from test.txt
and then ten zeros
like this
ab0000000000
but it only shows
ab

Any help is appreciated

 
  .486
  .model flat, stdcall
  option casemap :none

  include \masm32\include\windows.inc
  include \masm32\macros\macros.asm

  include \masm32\include\masm32.inc
  include \masm32\include\gdi32.inc
  include \masm32\include\user32.inc
  include \masm32\include\kernel32.inc.

  includelib \masm32\lib\masm32.lib
  includelib \masm32\lib\gdi32.lib
  includelib \masm32\lib\user32.lib
  includelib \masm32\lib\kernel32.lib

  .data   
    filename db "c:\masm32\assembly projects\fopen\test.txt",0
   
    file_handle HANDLE ?
    file_buffer DWORD 256 dup (0)
    msg db 10 dup ("0"),0
    readC DW ?
    LUT db "0123456789ABCDEF",0
  .code

start:
;   invoke CreateFile,ADDR filename,GENERIC_READ,FILE_SHARE_READ,
;                       NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL
  invoke CreateFile,ADDR filename,GENERIC_READ,FILE_SHARE_READ,
                      NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL
  mov file_handle,eax
  invoke ReadFile,file_handle,ADDR file_buffer,sizeof(BYTE)*2,ADDR readC,NULL
  invoke StdOut,ADDR file_buffer
  invoke CloseHandle,file_handle
  mov cl,LUT
  mov msg,cl
  invoke StdOut,ADDR msg
  exit
end start

ToutEnMasm


If the contents of the buffer is
Quoteab0000000000
All print functions will show ab and stop at the zero.
You need to use another functions to show the zero suit ,dwtohex for example.

evlncrn8

possibly?

mov cl,LUT       ; reads 1 byte from LUT into cl
mov msg,cl       ; stores this byte into msg...

looks VERY wrong to me....

edited because i misread, probably still misread but thats how i roll ;p

dedndave

it looks like it should work   :bg
let me try it....

dedndave

very strange
for some reason, MOV CL,LUT gets a binary 0 in CL instead of an ASCII 0   :P

AiaKonai

Quote from: dedndave on October 13, 2011, 01:46:30 PM
very strange
for some reason, MOV CL,LUT gets a binary 0 in CL instead of an ASCII 0   :P

That would be the problem then...... :( Why in the world is it a binary 0?

AiaKonai

On that same subject how did you find that out? I've been searching for a good debugger.

AiaKonai

@ToutEnMasm

There are two buffers being displayed. One is the file buffer as read from test.txt (which contains 4 letters ..."abcd")
The other is msg which is initialized with 10 ascii zero's followed by a real 0.
I was attempting to insert the first element of LUT into the msg buffer and display it. (which ironically should not change it at ALL)

dedndave

ok i figured it out - lol
the "number of bytes read" variable is supposed to be a DWORD - you have it defined as a WORD
when you read the file, it overwrites the first 2 bytes of the string (with 0's)
    readC DW ?
    readC DD ?

also, i found a few little problems in the header
one of the lines ends with a period which, oddly enough, doesn't seem to bother the assembler - lol
the order you specify the includes is a little messy
and, msvcrt inc/lib should probably be included because some of the masm32 functions may require it (not sure about that one)
at any rate, you can get rid of all this stuff
 .486
 .model flat, stdcall
 option casemap :none

 include \masm32\include\windows.inc
 include \masm32\macros\macros.asm

 include \masm32\include\masm32.inc
 include \masm32\include\gdi32.inc
 include \masm32\include\user32.inc
 include \masm32\include\kernel32.inc.

 includelib \masm32\lib\masm32.lib
 includelib \masm32\lib\gdi32.lib
 includelib \masm32\lib\user32.lib
 includelib \masm32\lib\kernel32.lib

and replace it with this
 include \masm32\include\masm32rt.inc

ToutEnMasm


Put your code with your loaded file in a zip.
It seems that you have mixed ascii and binary data.

AiaKonai

Quote from: dedndave on October 13, 2011, 02:04:27 PM
ok i figured it out - lol
the "number of bytes read" variable is supposed to be a DWORD - you have it defined as a WORD
when you read the file, it overwrites the first 2 bytes of the string (with 0's)
    readC DW ?
    readC DD ?

also, i found a few little problems in the header
one of the lines ends with a period which, oddly enough, doesn't seem to bother the assembler - lol
the order you specify the includes is a little messy
and, msvcrt inc/lib should probably be included because some of the masm32 functions may require it (not sure about that one)
at any rate, you can get rid of all this stuff
 .486
 .model flat, stdcall
 option casemap :none

 include \masm32\include\windows.inc
 include \masm32\macros\macros.asm

 include \masm32\include\masm32.inc
 include \masm32\include\gdi32.inc
 include \masm32\include\user32.inc
 include \masm32\include\kernel32.inc.

 includelib \masm32\lib\masm32.lib
 includelib \masm32\lib\gdi32.lib
 includelib \masm32\lib\user32.lib
 includelib \masm32\lib\kernel32.lib

and replace it with this
 include \masm32\include\masm32rt.inc

I knew it :( .... always something obscure that looks right to me that causes the biggest problem... TYVM!!!