I do assembly rate in si. It should, for example, replace the desired element of the array with another letter.

I send an array to a function via

char fas3=rule2(&text2[0]); 

And in the function here is:

 __asm { add [a], 1 mov [a], 's' } 

Why does not it work? How to make it work?

    2 answers 2

    It does not work, because [a] is the address of the first cell of the array, which is stored somewhere else. And you perform operations with a pointer, not an array.

    It is necessary to do the following:

     __asm { push eax ; Сохранить состояние регистра eax mov eax, [b] ; Прочитать в него адрес первого элемента массива mov [eax], 's' ; Записать в память по оному адресу новое значение pop eax ; Восстановить состояние регистра eax } 

    Ah, yes, if the function consists entirely of this and then it is not necessary to save and restore the state of the register - the compiler will do everything by itself. I suspect that he will do it anyway, but you never know.

    • Thank. Why cmp [eax], [ebx] is not perceived? I really want to compare the two elements of the array, but it does not. eax, ebx are set like your eax. The debugger considers the type of operator to be invalid. - anon321
    • pdos.csail.mit.edu/6.828/2009/readings/i386/CMP.htm - look at the table of permissible operands of the command, it’s immediately clear what’s wrong. I briefly explain: r-register, imm - the number itself, m - a memory cell. And not a debugger - a compiler. - Alexey Sonkin
    • And [eax] is not r / m-byte? If it is, then it turns out to be a contradiction with pdos.csail.mit.edu/6.828/2009/readings/i386/MOV.htm , because mov me temp_char, [ebx] does not work for me either. How to compare them? - anon321
    • And is not temp_char the same memory?) But you look more precisely what can be compared with what. Even on a piece of paper rewrite - so in almost all teams of this type. - Alexey Sonkin
    • I, probably, will abuse your kindness. Something like this: xor eax, eax xor ebx, ebx push eax mov eax, [a] mov ebx, [a] add eax, j add ebx, j add ebx, i add i, 1 mov edx, [eax] mov temp_char , ebx cmp edx, [temp_char] je change It doesn’t go to change, although there are identical elements and it reads them like. Why not go over? - anon321

    or like this

     __asm { push eax ; Сохранить состояние регистра eax mov eax, b[0] ; Прочитать в него адрес первого элемента массива mov [eax], 's' ; Записать в память по оному адресу новое значение pop eax ; Восстановить состояние регистра eax } 
    • And what is the meaning of the replacement mov eax, [b] from the answer above to the fully equivalent mov eax, b[0] ? - AnT