I created a program in C to generate a char* processedData. I send to my assembly program and put it in a register:
mov edx, [ebp+12]
mov edi, edx
How can i write a char into it. I know i need to Write a char and inc edi... that in a loop. But how can i write a char, i already have the value into another register. But if i do mov edx, 49; char code i'll lose the pointer. I want to do something like
for(p=malloc(100*sizeof(char*)); p!=NULL;p++){
*p=//my char code
}
Assembly for linux (DEBIAN) x86
edx
is the address of the destination of the char. That is, edx
is a pointer to the location you want to write to. Therefore, do this:
mov byte ptr ds:[edx], 49
This might even work:
mov byte ptr ds:[edx], '1'
You say your character is already in some register. I assume it is an 8 bit register ( ah/al/bh/bl/ch/cl/dh/dl
), in which case you can just do:
mov [edx], ah
The assembler can infer the size of the data [edx]
is pointing to in this case.
I'm on Windows right now so this code is for VC++. It demonstrates copying a string:
#include <stdlib.h>
#include <stdio.h>
char src[] = "hello";
char dest[8];
int main( void )
{
__asm
{
xor ecx, ecx
mov eax, offset src
mov edx, offset dest
loop_dest:
mov bh, byte ptr ds:[eax+ecx]
mov [edx+ecx], bh
inc ecx
cmp ecx, size src
jnz loop_dest
}
printf("%s\n", dest);
return EXIT_SUCCESS;
}
If your assembler uses AT&T syntax, you'll need to do some minor translation, but hopefully this points you in the right direction.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.