News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Is this a bug?

Started by mineiro, March 29, 2017, 09:11:49 AM

Previous topic - Next topic

mineiro

Today I face this strange thing;
I don't touched more on file so I can post it. Don't execute this file because need a file and it's generating error.
;Version 6.14.8444
;build to console mode
include \masm32\include\masm32rt.inc

.686
.xmm

voltas equ 100000

header_file struct
original_size dd ?
line_count dd ?
line_lenght dd ?
header_file ends

testing PROTO :dword, :dword

.data
bug db "mov edi,offset bug generated mov edi,0",0
align 4
duration db "duration: %d ms",0dh,0ah,00h

.data?
houtput dd ?
counter dd ?
_start_ dd ?

pfile dd ?
szfile dd ?

temp dd ?

align 16
mbug db 100000 dup(?)
sz_tmp1 db 40 dup (?)

.code
start:
invoke GetStdHandle,STD_OUTPUT_HANDLE
mov houtput,eax

mov pfile,InputFile("Level1.dat")
mov szfile,ecx

call GetTickCount
mov [_start_],eax

rept voltas
invoke testing, pfile,szfile
endm

call GetTickCount
sub eax,[_start_]
invoke wsprintfA,offset sz_tmp1,offset duration,eax
invoke WriteConsole,houtput,addr sz_tmp1,eax,addr temp,0

free pfile
inkey "Done..."
invoke ExitProcess, 0

align 16
testing proc _pfile:DWORD,_szfile:DWORD

  LOCAL  tLine:DWORD
  LOCAL  tLineLen :DWORD
  LOCAL  tSum:DWORD

  LOCAL  tLen :DWORD

LineLenght equ 160
m2m tLen,_szfile


mov esi,_pfile
assume esi:ptr header_file
m2m tSum,[esi].original_size
m2m tLine,[esi].line_count
m2m tLineLen,[esi].line_lenght
assume esi:nothing

add esi,sizeof header_file
sub tLen,sizeof header_file

    mov edi, offset mbug            ;<---------------- generating mov edi,0
    .if edi == 0   ;<--- these procedures below don't work
    invoke MessageBox,0,addr bug,addr bug,MB_OK    ;<------all parameters are 0
    invoke ExitProcess,-1                          ;<------functions are pointing to next instruction (like eip)
    .endif
   
mov eax,"@@@@"

.while tLen != 0
movzx ecx,sbyte ptr [esi]
test cl,cl
.if sign?
neg cl
sub tLineLen,ecx
mov edx,ecx
shr ecx,2
and edx,00000011b
rep stosd
mov ecx,edx
rep stosb

mov ecx,tLineLen
xor eax,60606060h

mov edx,ecx
shr ecx,2
and edx,00000011b
rep stosd
mov ecx,edx
rep stosb

mov tLineLen,LineLenght
.elseif zero?
push esi
lea esi,[edi-LineLenght]
mov ecx,LineLenght/4
rep movsd
pop esi
.else
sub tLineLen,ecx
mov edx,ecx
shr ecx,2
and edx,00000011b
rep stosd
mov ecx,edx
rep stosb
xor eax,60606060h
.endif
inc esi
dec tLen
.endw
ret
testing endp

end start

I'd rather be this ambulant metamorphosis than to have that old opinion about everything

HSE

Are you sure the offset of mbug is zero?
And inmediate values need to be moved to a general register first. Doesn't it?
Equations in Assembly: SmplMath

mineiro

hello sir HSE;
have you assembled, linked and on disassembly look to that place?
If I instruct "mov edi, offset mbug" this is what I should get
To you it's coded as "mov edi,0"? Can you check?

Ps: This source file it's working if I change "voltas equ 100000" to "voltas equ 1000" and insert a file need to be read.

---edited--
Inserted zip file, if I change on source code "voltas to 1000" works fine, if I change "voltas equ 100000" so instead of generate code "mov edi,offset mbug" it's generating code "mov edi,0", so, causing a bug on program. Other thing is that some external functions seems to be not working too.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

HSE

No rigid disk sound here, only mosquitos. I misunderstand the note in the code. :t
Equations in Assembly: SmplMath

jj2007

Quote from: mineiro on March 29, 2017, 11:06:18 AMif I change "voltas equ 100000" so instead of generate code "mov edi,offset mbug" it's generating code "mov edi,0", so, causing a bug on program

You are generating the code 100000 times - no wonder the assembler chokes on that ::)

That is indeed a bug in ML version 6.14 & 6.15. The Watcom family has other problems with this one - it takes an eternity to build:
build all took 122497 ms

The code works, though, also with ML 8.0 and higher:
duration: 5351 ms
So I would suggest you delete ML 6.* from your disk 8)

mineiro

Thanks for answers HSE and jj2007.

So, this is a ml problem, I was thinking that was linker. I received a warning:
LINK : warning LNK4089: all references to "user32.dll" discarded by /OPT:REF
But I have only used user32.dll functions to show a messagebox error message that don't work of course. That's why I inserted exitprocess on that piece just to use function on other library that don't work too.

HSE, I have on my house citronella plant, good as natural repellent, it also works against that aedes aegypt too.
jj2007, so file worked, yes, I will update assembler. Thanks for tips.
Thank you sir's.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

LordAdef

I'm just watching! Curious to see what you are up to, and of course learning!

I think I do have the latest ML in my VS community. Never bothered to replace the old one in the SDK.

Just in case you are interested Mineiro... to know

(I'm breaking any rules here, am I?)

mineiro

Hello sir LordAdef;
I remember this bug but to me this happens when you're dealing with large datas so assembler just crash. This case it not crashed. By lucky members have faced this on past.
My intention was to remove loop overhead (spurious) on measure. I know that I forced assembler, but I was just trying to force this program.
Well, I can measure an independent loop and do calculus, will not be 100% but will get close.
I'm just playing with this file sir LordAdef, and now I think I need a head and tail code to align address to even numbers. If I'm storing numbers on memory and that address it's odd, so we loose performance, but if address it's a dword (in this case) multiple, so we can gain some performance.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

LordAdef

Maestro Mineiro, my Prince of Minas Gerais (State that I love by the way),

I joined this procedure to my main project and I will post tonight so you can have some fun.
The only change I made to the test bed was to "Alloc" memory instead of copying to the predetermined array.

It worked well when I replaced the original procedure. This proc was the reason I was trying to use multiple modules. It's the sort of procedure once you get it right, you don't need it in the main page. In case you come up with a faster algo, we can just replace the asm file.


mineiro

hello sir LordAdef;
I'm playing with that file on my idle time. If Decomp address is aligned to 16 I have some gain on zero procedure with code below. Yes, that structure is not really need because only member need is linelength. I can also rewrite that hll, but for readable I'm maintaining this for a while.
.elseif zero?
push rsi
lea esi,[edi-LineLenght]
;---------------
; mov ecx,LineLenght/16
; @@:
; movaps xmm0,[esi]    ;if you receive fauls change this line to "movups xmm0,[esi]", but timing will get closer to other code option below
; movaps [edi],xmm0
; lea esi,[esi+16] ;add esi,16
; lea edi,[edi+16] ;add edi,16
; dec ecx
; jnz @B
;---------------
mov ecx,LineLenght/4
rep movsd
;---------------
pop rsi


I also figured that instead of read counter by counter on a byte way, I can divide and get remainder on file.dat-12, so, I can read 4 counters per moment, not tested, just supposition.
I'm just thinking about other approaches too.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything