News:

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

type conversion

Started by loki_dre, April 17, 2008, 06:03:19 AM

Previous topic - Next topic

loki_dre

is it possible to link a byte pointer:
BYTE* memory = 0;

to a memory allocated using the following method:
---------------------------------------
.data?
        hMemory     HANDLE  ?
        pMemory     DWORD   ?
.code
        ;ALLOCATE AND LOCK OUR MEMORY
        invoke GlobalAlloc, GMEM_MOVEABLE or GMEM_ZEROINIT, MEMORYSIZE
        mov hMemory, eax
        invoke GlobalLock, hMemory
        mov pMemory, eax
-----------------------------------------
and do it without using MemCopy function or a similar method

donkey

No

If you allocate memory the pointer returned is to that block of memory and in the case you gave it was zeroed so every byte will be zero. To put something else in that memory you will have to copy it over.

You can think of your memory as a note book. Each page of the note book is numbered at the bottom, when you write into the note book you can do it in either pencil or pen, pencil is read/write and pen is read only. When you no longer need the information you have written to a page you draw a line through it. When you ask Windows to allocate more memory it will search for a blank page or a page with a line drawn through it. Windows will return the page number it finds, if you need the information from another page copied to it you will have to do the copying yourself.

I think you are trying to apply C rules to ASM and you cannot do that, C performs a lot of the grunt work for you in the background like filling local variables and copying blocks of data. You will find that in ASM none of this is done for you, you're the grunt and you have to do all of these tasks explicitly.

Edgar
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

loki_dre

how can I see how a function like MemCopy works.....my intention is to duplicated it & add some processing routines to the data so that I can minimize the time of my program.
Goal:
copy & process data from a BYTE* to memory allocated.


loki_dre

nevermind, found it:


MemCopy proc public uses esi edi Source:PTR BYTE,Dest:PTR BYTE,ln:DWORD

    ; ---------------------------------------------------------
    ; Copy ln bytes of memory from Source buffer to Dest buffer
    ;      ~~                      ~~~~~~           ~~~~
    ; USAGE:
    ; invoke MemCopy,ADDR Source,ADDR Dest,4096
    ;
    ; NOTE: Dest buffer must be at least as large as the source
    ;       buffer otherwise a page fault will be generated.
    ; ---------------------------------------------------------

    cld
    mov esi, [Source]
    mov edi, [Dest]
    mov ecx, [ln]

    shr ecx, 2
    rep movsd

    mov ecx, [ln]
    and ecx, 3
    rep movsb

    ret

MemCopy endp

loki_dre

how can I implement the AND function or NOT function for a constant?
I tried:
IMAGE_SIZE_COL_BYTES    EQU     (((24*1280 + 31) AND (NOT 31))/8)

it doesn't seem to work correctly for me


donkey

What value should be returned ?? If you're looking for 3840 then it works if not you have to explain what isn't working and why not otherwise there's no way to help you.

Donkey
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

loki_dre

It seems like BEDMAS was not correctly applied by the compiler:
24*1280 + 31
was interpreted as
24*(1280 + 31)
I changed it to:
(24*1280) + 31
and got the correct result


MichaelW

Quote
24*1280 + 31
was interpreted as
24*(1280 + 31)

What assembler are you using? 24*(1280+31)=31464, but for 24*1280+31 MASM and GoAsm should return 30751.

eschew obfuscation

loki_dre

MASM32 V9.00

try the whole thing....maybe it makes a difference
IMAGE_SIZE_COL_BYTES    EQU     (((24*1280 + 31) AND (NOT 31))/8)

MichaelW


; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    IMAGE_SIZE_COL_BYTES EQU (((24*1280 + 31) AND (NOT 31))/8)

    print ustr$(IMAGE_SIZE_COL_BYTES),13,10

    inkey "Press any key to exit..."
    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start


3840

eschew obfuscation