flat assembler
Message board for the users of flat assembler.
Index
> Windows > how to cute a buff? |
Author |
|
LocoDelAssembly 11 Dec 2006, 22:35
Well actually at run-time the formal parameters look like this
procedure copy(var:string; index, length:integer; var result: string); This conversion from function to procedure is required because a string obviously doesn't fit in a CPU register (the same happens when you don't return simple types). Well after the conversion this is one way Code: proc copy, var, index, length, result push esi edi mov esi, [var] mov edi, [result] add esi, [index] mov ecx, [length] rep movsb pop edi esi ret endp Please note that the proc I written is unsafe since it doesn't checks if index is beyond the last character nor checks if length is too large. So assuming that the string are ASCIIZ (null terminated like in C) here another proc Code: proc copy, var, index, length, result push esi edi mov esi, [var] mov edi, [result] mov ecx, [index] test ecx, ecx jz .done .checkZero: lodsb test al, al jz .exit dec ecx jnz .checkZero .done: mov ecx, [length] test ecx, ecx jz .exit .copyChars: lodsb stosb test al, al jz .return dec ecx jnz .copyChars .exit: mov byte[edi], 0 .return: pop edi esi ret endp [edit]Actually the Pascal-like procedure declaration of my ASM codes is: procedure copy(const var: string; index, length: integer; var result: string); {string type actually is ASCIIZ in my code}[/edit] |
|||
11 Dec 2006, 22:35 |
|
RedGhost 11 Dec 2006, 23:15
Almost none of the mem/string instructions in C/C++ are safe, don't feel bad . Damn NULL pointers.
_________________ redghost.ca |
|||
11 Dec 2006, 23:15 |
|
crossbr 12 Dec 2006, 01:12
thanks to help! =P
|
|||
12 Dec 2006, 01:12 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.