Hi,

The following should replace the word "Hello" in memory with "HHHHH".

I am just testing the following code so that I can understand how asm works, but I keep getting an unhandled memory exception when i get the 'mov byte ptr [eax], 048H' line.

I have tried to change it to 'move byte [eax], 048H' but it won't even compile.



PHP Code:
// amtest.cpp : Defines the entry point for the application.
//

#include "stdafx.h"

void test(LPSTR,int);

int APIENTRY WinMain(HINSTANCE hInstance,
                     
HINSTANCE hPrevInstance,
                     
LPSTR     lpCmdLine,
                     
int       nCmdShow)
{
     
// TODO: Place code here.

    
CHAR szWord "Hello";

    
test ((LPSTR)szWordsizeof(szWord));

    return 
0;
}


void test(LPSTR ptrAddressint len)
{
    
    
_asm
    
{
        
pusha    //push all registers onto stack
        
mov eax, [edi 8// load eax with ptrAddress
        
mov ecx, [edi 12// load ecx with length of string (loop counter)
loop_start:
        
mov byte ptr [eax], 048//replace memory position with Ascii('H')
        
inc eax //move to next memory location
        
dec ecx //decrease counter
        
jnz loop_start //loop
        
popa //get registers back
    
}

    return;


If anyone could help me I would appreciate it. Thanks