From: Frank K. <fbk...@zy...> - 2008-10-20 02:43:40
|
Tyler Littlefield wrote: > Hello, > I've spent the last couple hours trying to debug this, and haven't found > much. > I"m writing a proc that would take what is in eax, and run through that and > print byte-by-byte the message supplied in eax, > here's the code--assistance would be awesome if possible. > section .data > buff db "Hello world!",0 ;the message we're going to print > section .text > global _start: > _start: > mov eax,buff ;moves the buffer address to eax for the call. > call write ;will write what ever is stored at eax byte by byet. > call exit ;exits > > write: > mov esi,eax ;get what's stored in eax (hopefully an address) and store it in > esi. > jmp .wloop > .wloop: ;the loop. > call pc > mov cl,[esi] ;moves the dereferenced esi to cl. > movzx ecx, byte [esi] > cmp cl,0 ;is the byte a null character? This is okay... but for sys_write, you want the address of what to print in ecx, not "the character". So... mov ecx, esi > je .wend > mov eax,4 > mov ebx,1 > mov edx,1 > int 80h ;print the character. > inc esi ;move the pointer to the next char in the buffer. > jmp .wloop ;restart the loop > .wend: > ret > > exit: > mov eax,1 > mov ebx,1 > int 80h > ret > > pc: > mov eax,4 > mov ebx,1 > mov ecx,'d' Likewise, this isn't going to work... > mov edx,1 > int 80h > ret > > Thanks, > Tyler Littlefield > email: ty...@ty... > web: tysdomain-com > Visit for quality software and web design. > skype: st8amnd2005 Calling the kernel for each character is horribly inefficient, but if that's what you wanna do... the single change above should fix it. You could do "cmp byte [esi], 0" to see if you're at the end of the string, and avoid putting "the character" in cl to "cmp"... Likewise, putting "d" in ecx will segfault. The "d' wants to be in a buffer, and ecx the address of the buffer. We can use the stack for our "buffer"... push 'd' mov ecx, esp mov edx, 1 ; (one character) mov ebx, 1 ; (stdout) mov eax, 4 ; (__NR_write) int 80h add esp, 4 ; (clean up stack!) ... Or something like that... Best, Frank |