lo

I have a BYTE called srcp that is 1536 bytes long and i want to put 768 bytes of it to another BYTE called dest.I cant get it work ... any ideas? Here is code:

//srcp is a BYTE 1536 bytes with values in it
int Width = 768;
BYTE* dest;

_asm
{
mov eax, Width
mov esi, srcp
mov edi, dest
copy_more_bitsl:
movq mm0, ; read 8 bits
movntq , mm0 ; write 8 bits
add esi, 8 ; update source pointer
add edi, 8 ; update dest pointer
dec eax ; count down line width
jnz copy_more_bitsl ; keep copying till done
emms
}

I'm just getting rubbish in dest.

Bye
Posted on 2004-09-10 21:54:43 by Mbee
How about simply trying:
lea  esi,srcp

lea edi,dest
mov ecx,768/4
rep movsd

Raymond
Posted on 2004-09-10 22:38:54 by Raymond
Thanks Raymond.


did not work for me -

lea esi,srcp
lea edi,dest
mov ecx,768/4
rep movsd

The 'rep movsd' crashes prog and if i comment it out, the output is no good.

The C++ code i did is too slow to be any use:


for (int z = TopCrop; z < (512 - BottomCrop); z++) // need to use orig value for height
{
BYTE* CurrentLine = pInfo->Overlay + z * pInfo->OverlayPitch; //got the raw line
for (int e = 0; e < unpadd_pitch; e++) //note unpadd pitch will be the calced crop pitch
{
DS_NewBuf[e + (unpadd_pitch * (z - TopCrop))] = CurrentLine [e + LeftCrop];
}
}


Thanks anyway
Posted on 2004-09-10 23:04:29 by Mbee
How about doing something like the following:


BYTE *CurrentLine = pInfo->Overlay + TopCrop * pInfo->OverlayPitch + LeftCrop;
BYTE *EndLine = pInfo->Overlay + (512 - BottomCrop) * pInfo->OverlayPitch + LeftCrop;
BYTE *OutBuf = DS_NewBuf;
while (CurrentLine < EndLine) {
memmove(OutBuf, CurrentLine, unpadd_pitch);
OutBuf += unpadd_pitch;
CurrentLine += pInfo->OverlayPitch;
}
Posted on 2004-09-10 23:27:51 by death
Thanks Death - but i need to learn assemblying.

The problem is :

a BYTE with bytes of type A and B:

BBAAABBAAABBAAA

and i want to create a new BYTE from the source BYTE that just has bytes of type A.

AAAAAAAAA

ther type is not identifiable - its the location in the source BYTE that is important.

Ta
Posted on 2004-09-11 00:06:39 by Mbee
The 'rep movsd' crashes prog and if i comment it out, the output is no good.
The only reason the program would crash is if insufficient memory was allocated for the "dest" variable or the "dest" variable is not used properly. The actual syntax to reserve sufficient memory for data variables is very dependant on the assembler you are using. With MASM syntax, it would look like:
dest db 768 dup(?)

The suggested code also assumed that the "srcp" and "dest" variables were declared data variables. If those are the actual addresses (or handles) of memory allocated by the system (such as with LocalAlloc), the suggested code would then need to be modified as follows:
mov esi,srcp 

mov edi,dest
mov ecx,768/4
rep movsd

Assembler is easy after you learn the basics.

Raymond
Posted on 2004-09-11 11:33:23 by Raymond

movq mm0, ; read 8 bits
movntq , mm0 ; write 8 bits
"q" is 8 "Bytes" , not 8 "Bits".


dec eax ; count down line width
"dec eax" is "eax=eax-1",
but your define is "int Width = 768"? 768 bytes? at (8 bytes per 1 movq)?

if you want "fast speed" by MMX, XMM...,
maybe you need look this
http://www.joryanick.com/memcpySGI.htm
Posted on 2004-09-11 23:05:43 by Kestrel
The way string instructions work is the processor uses ECX as the count register. That is how many bytes/words or dwords you wish to move. Also you don't see this in a flat memory model but the processor always uses es:edi as the destination and ds:esi as source, so it is a good idea to keep this in mind and apply these rules in your string operations. The segment registers are implied in flat memory model.

byte operation

Mov cx,xx ; number of bytes to move
mov esi,xx ; source address (a label)
mov edi,xx ; destination address (a label)
cld ; clear direction flag (assending operation/left to right)
rep movsb ; repeat count in CX move string in bytes

dword operation

mov ecx ; number of dwords to move
mov esi,xx
mov edi,xx
cld
rep movsdw ; move number of dwords in ECX
Posted on 2004-09-12 09:12:49 by mrgone
Cant make it work - i am sooooooooooo depressed....

There are 7 billion people on this stinking planet - has not one of them ever written a primer for MSAM.

STILL - dont know if im dealing with data, mem location, offsets, --- what is in the registers bits/byets/addresses/relatives?

I REALLY HATE HATE HATE this stuff but you have to use it if you need speedy code.

It all stinks and i hate it.
Posted on 2004-09-12 15:41:14 by Mbee
Mbee,

Just come back to your basics, the code suggested to you here is simple and DOES work fine if you set it up right.

Make sure BOTH the source and DESTINATION are valid memory addresses. Make sure the destination is large enough to receive the copied data. Then write the very simple code that copies it from one place to another.


mov ecx, count
mov esi, source
mov edi, destination
rep movsb

This code works but some of the suggestions are faster. If you can get it to work by suppling the correct memory locations, you can write much faster code to do the copy.
Posted on 2004-09-12 19:31:53 by hutch--
quote: has not one of them ever written a primer for MASM.


I think post above has :lol: That's the man himself. Hutch wrote MASM. I think he can set you straight.
Posted on 2004-09-13 11:44:48 by mrgone
I don't see the word MASM there... Surely he might have written MASM on other occasions, but then again, a lot of people have.
Posted on 2004-09-13 12:05:27 by Sephiroth3
I thought I had better correct this one. MASM is a trade name that belongs to Microsoft and they long ago wrote ML.EXE that is the Microsoft assembler.

I maintain the MASM32 project to ensure that low level programming is accessible to anyone who wants to try it out and anyone who has a use for it or needs it in their programs.

While I have written the bulk of it, there are in fact many different contributors who have helped to make it a better project and their contribution has been documented in the project.
Posted on 2004-09-13 19:59:44 by hutch--
I REALLY HATE HATE HATE ....

Don't Hate! Look Sample Codes is good ! is enjoy....
You love a some one, just copy it, paste into your source, that's right!

This is AMD Sample Codes, Step by Step, fast by fast...
http://cdrom.amd.com/devconn/events/gdc_2002_amd.pdf
Posted on 2004-09-14 01:04:58 by Kestrel
Altough some codes might be refusing you should LOVE code research...
(off-topic a bit but never mind)
Posted on 2004-09-14 02:47:45 by Dom