Is there an opcode that zeroes a range of memory?
If not, I wonder how ZeroMemory does?:confused:
Posted on 2002-05-11 10:06:18 by C.Z.
A similar question has been asked here.
Posted on 2002-05-11 10:40:36 by jademtech
It does it by using a number of instructions, of course.
Is there an opcode that runs a 3r337 3D engine? If not, I wonder
how quake3 and the rest does it...
Posted on 2002-05-11 11:08:09 by f0dder
why dont you try this
cleanbuff proc
mov eax, offset logfont
xor ebx,ebx
mov BYTE PTR ,0
@@:
inc ebx
mov BYTE PTR ,0
cmp ebx,SIZEOF LOGFONT
jne @B
ret
cleanbuff endp
Posted on 2002-05-11 11:44:20 by Qages
ZeroMemory macro memory, n

local _Byte
local _MoveByByte
local _MoveByQword
local _Done
mov ebx, memory
mov eax, n
xor edx, edx
mov ecx, eax
and eax, 0FFFFFFF0h
je _Byte
add ebx, eax
pxor mm0, mm0
neg eax
_MoveByQword:
movq qword ptr [ebx+eax], mm0
add eax, 16
jne _MoveByQword
_Byte:
and ecx, 0Fh
je _Done
add ebx, ecx
neg ecx
_MoveByByte:
mov byte ptr [ebx+ecx], dl
inc ecx
jne _MoveByByte
_Done:
endm
Posted on 2002-05-11 13:01:38 by bdjames

It does it by using a number of instructions, of course.
Is there an opcode that runs a 3r337 3D engine? If not, I wonder
how quake3 and the rest does it...
No but there's an opcode that runs Windows95, it's called HLT. :grin:
Posted on 2002-05-11 16:33:02 by Maverick
Originally posted by f0dder It does it by using a number of instructions, of course.
Is there an opcode that runs a 3r337 3D engine? If not, I wonder
how quake3 and the rest does it...


LOL

mov eax, 031337h
pushad
cli
runquake3 eax
sti
popad
ret
Posted on 2002-05-11 18:56:14 by iblis
Thanks to all (except fOdder!!!! you were fooling me!!! :o I was asking about the opcodes (of course, not "opcode") that are likely to be the implementation of RtlZeroMemory!).

jademtech, the thread you told me helped me out.
Posted on 2002-05-11 21:03:39 by C.Z.
bomb01, you are supposed to joke
back:"I tried runquake3 and it did
not work".
Posted on 2002-05-11 21:36:47 by bdjames
Hi bdjames,
May be...


ZeroMemory macro memory, n
local _Byte
local _MoveByByte
local _MoveByQword
local _Done
mov ebx, memory
mov eax, n
;xor edx, edx
mov ecx, eax
;and eax, 0FFFFFFF0h
and eax, -8
je _Byte
;add ebx, eax
mov edx, eax
pxor mm0, mm0
;neg eax
_MoveByQword:
movq qword ptr [ebx+eax-8], mm0
;add eax,16
sub eax, 8
jnz _MoveByQword
add ebx, edx
_Byte:
;and ecx,0Fh
and ecx, 7
je _Done
;add ebx, ecx
;neg ecx
_MoveByByte:
;mov byte ptr [ebx+ecx-1], dl
mov byte ptr [ebx+ecx-1], 0
dec ecx
jnz _MoveByByte
_Done:
endm
:)
Posted on 2002-05-11 22:05:04 by buliaNaza
Oops...

Yes a byte is eight not four bits...

But is

mov byte ptr , 0

faster than:

mov byte ptr , dl

I will check it tomorrow.

ZeroMemory macro memory, n

local _Byte
local _MoveByByte
local _MoveByQword
local _Done
mov ebx, memory
mov eax, n
mov ecx, eax
and eax, -8
je _Byte
pxor mm0, mm0
mov edx, eax
_MoveByQword: movq qword ptr [ebx+eax-8], mm0
sub eax, 8
jne _MoveByQword
add ebx, edx
_Byte: and ecx, 7
je _Done
_MoveByByte: mov byte ptr [ebx+ecx-1], 0
dec ecx
jne _MoveByByte
_Done:
endm
Posted on 2002-05-11 22:27:33 by bdjames

I hate those who keep joking when others are with trouble...at least, not in this thread. :o



My joke came at a time when your question was already answered. Your "trouble" was no longer, and I didn't expect to be outright hated for posting innocent little lighthearted humor.
Posted on 2002-05-11 22:45:01 by iblis
bdjames, I appreciate your idea with quadword, but would


xor eax, eax
lea edi, Buffer
mov ecx, dwBufferLength
mov edx, ecx
shr ecx, 2
shl ecx, 2
sub edx, ecx
shr ecx, 2

rep stosd
mov ecx, edx
rep stosb

be faster than the jmps in your code?
Posted on 2002-05-11 23:02:41 by C.Z.




My joke came at a time when your question was already answered. Your "trouble" was no longer, and I didn't expect to be outright hated for posting innocent little lighthearted humor.



iblis, sorry for my offense.
I'd haul off.
Posted on 2002-05-11 23:17:50 by C.Z.
lol mine works fine to zero out memory
Posted on 2002-05-12 02:31:57 by Qages
Should depend on size of buffer...

ZeroMemory macro buffer, n

local _Byte
local _MoveByQword

mov edi, buffer
mov ecx, n
xor eax, eax
mov ebx, ecx
pxor mm0, mm0
and ecx, 7
and ebx, -8
je _Byte
add edi, ebx
neg ebx
_MoveByQword: movq qword ptr [edi+ebx],mm0
add ebx, 8
jne _MoveByQword
_Byte: rep stosb
endm


~ 1cycle per dword
Posted on 2002-05-12 10:12:50 by bdjames
bdjames, what's the syntax to enable MMX support?

I know that .mmx enables the support for instruction set, but the assembler doesn't recognize mmx registers even if .mmx is specified.:confused:
Posted on 2002-05-12 23:15:38 by C.Z.
if you're using the case sensitive option, use MM0 instead of mm0.

there was another thread about uppercasing MMX registers, but i forgot where that went.

edit: nm. found it:
click here
Posted on 2002-05-12 23:49:55 by jademtech
Qages

.data?
buffer01 byte 260 ?

if buffer01 had 259 character in it and i have already used it and wanted to clear this once (.data?) buffer..... will your code do it?

Or will a simple

mov buffer01 [0], 0

do the same thing.

Posted on 2002-05-13 01:47:35 by cmax
cmax, clearing the first byte will of course not clear the whole buffer -
but if you use the buffer for zero-terminated strings, it has the effect
of readying the buffer for a new string (setting the string length
to zero)
Posted on 2002-05-13 06:30:01 by f0dder