Scott Earnes
Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:need BP7-asm help
QuoteGerd wrote: > To clear video memory very fast I wrote following procedure: > {*********************************************************} > { fill memory with word value using 4 byte stepping > { Call: FillWord (dest, count, value); > { Input: dest: destination > { count: word; number of double words > { value: word; fill value > {---------------------------------------------------------} > procedure FillDWord (var dest; count, value: word); assembler; > asm > les di, dest {es,di = dest} > mov cx, count {cx = count} > mov ax, value {ax = value} > db 66h > shl ax, 16 {eax hi = value} > mov ax, value {eax low= value} > db 66h > rep stosw {fill with double word stepping} > end;
This code is very buggy, and I'd recommend some changes -- you're ignoring the fact that there are an extra 16 bits in the extended registers, and depending on what state the processor is in, you could be in for a minor disaster. Try this: procedure fillword (var dest; count, value : word); assembler; asm db 66h; xor di,di {clear EDI -- important!} db 66h; xor cx,cx {clear ECX -- important!} les di,[dest] {load pointer to memory to ES:[(E)DI]} mov ax,[value] {get 16-bit value} db 66h; shl ax,16 {shift into upper word} mov ax,[value] {refresh low word} cld {clear direction flag -- important!} mov cx,[count] {load word count} db 66h; rep stosw {do the store} end; Note the changes here: If the high word of EDI or ECX are set for a 32-bit store, unpredictable things could happen. Also, the direction flag MUST be cleared. If you enter this procedure when it's set, the rep stosd will count EDI downward and make a mess of things. Quote> Now I want set memory with a longint value. But there is a problem. > How can I set longint value to register eax ???
Here's a possible solution (haven't tested it, but it compiles): procedure filldword (var dest; count : word; var value : longint); assembler; asm push ds {save DS register -- required} db 66h; xor si,si {clear ESI} db 66h; xor cx,cx {clear ECX} mov cx,[count] {load counter} cld {clear direction flag} lds si,[value] {get address of "value"} lodsw {load the low word (comes first)} push ax {save it to the stack} lodsw {load the high word} db 66h; shl ax,16 {shift it into the upper word of EAX} pop ax {restore the low word} pop ds {... and DS} db 66h; xor di,di {clear EDI} les di,[dest] {get mem pointer into ES:[(E)DI]} db 66h; rep stosw {do the mem store} end; Quote> If you know it, PLEASE repost or send an email. Thanx Gerd
-- Scott Earnest | _,-""-_,-""-_,-""-_,-""-_,-""-_,-" | set...@ix.netcom.com (primary) | We now return you to our regularly | siny...@{*word*104}space.org (alternate) | scheduled chaos and mayhem. . . . |
|