From: Frank K. <fbk...@zy...> - 2008-10-20 06:53:26
|
Tyler Littlefield wrote: > hello, > thanks; I'll do that. > I'd origenally wanted to do a strlen type thing, and then just put the > message or something in, and then run the call, so that I wouldn't have > to define messages for everything in the .data, if there would be an > efficient way of doing it. > So, I would send "hello world." to the stack, then pop it off in the > write func and use the strlen for edx. Something like? global _start section .data msg db "Hello world!", 10, 0 section .text _start: nop push msg call print_zero_terminated_string add esp, 4 ... mov eax, 1 int 80h print_zero_terminated_string: mov ecx, [esp + 4] ; buffer in ecx xor edx, edx ; get length in edx .getlen: cmp byte [ecx + edx], 0 jz .gotlen inc edx jmp .getlen .gotlen: mov ebx, 1 ; stdout mov eax, 4 ; __NR_write int 80h ret Of course, Nasm will calculate the length for you... msg db "Hello world", 10 msg_len equ $ - msg ...saving you having to walk down the string byte-by-byte looking for the zero. There's an algorithm around for scanning a string a dword at a time - worthwhile if you've got long strings, or a lot of them - but it's long and complicated. Fastest way is to not do it. If you're interfacing with C, you may be stuck with zero-terminated strings, but it isn't the most efficient data structure... Or maybe that's not what you had in mind... Best, Frank |