From: Paul P. <ppr...@gm...> - 2010-04-05 00:32:56
|
Hello All, I'm a newbie at Nasm and trying to get my chops wet. In fact my asm isn't stellar at all, but trying to learn it as a hobbyist. I've decided to start off with a very simple subroutine, attempting to get that working first but I'm running into lots of problems. I was able to write my function in Gnu's Assembler which worked fine, however I don't like it's syntax, hence the reason for attempting to write it in Nasm which I like better. The c library function I am attempting to mimic is bzero. In short it's "void bzero(char *addr, unsigned int len)". I would have thought this would be quite easy but alas. ############################### section .text global bzero ; void bzero(char *s, unsigned int len); bzero: enter 0, 0 .loop: cmp [esp + 12], 0 ; If length is zero je .done ; we are done mov eax, [ebp + 8] ; Move address of pointer into eax mov [eax], 0 ; 0 out location referenced in eax add [ebp + 8], 1 ; add 1 to the address sub [ebp + 12], 1 ; subtract 1 from value of length jp .loop ; continue with loop .done: leave ret ############################### I've tried prefixing the some of the addresses with the keyword 'byte' but that didn't help much either. (Ex: "add byte [ebp + 8], 1") Also, I'd like to include the Gas example that did work that I'm trying to convert into Nasm style syntax. ############################### bzero: pushl %ebp movl %esp, %ebp .loop: cmpl $0, 12(%ebp) je .done movl 8(%ebp), %eax movb $0, (%eax) addl $1, 8(%ebp) subl $1, 12(%ebp) jmp .loop .done: popl %ebp ret ############################### If this is the wrong list, I apologize in advance and would like an appropriate pointer to the correct list. Thanks, -- Paul __________________ :(){ :|:& };: |