Assembler and C programming linux -m32 (char-byte from register in assembler) -


i'm new assembly programming, wrote function in c need call function in assembly. seems register wants give 4 characters (bytes) instead of one, want.

ignore code after jump, since jump skip part of code until make work properly.

this supposed part of own simplified version of sprintf in c. removed of code things work. it's supposed return first parameter %. so, when call assembler function in c, can write printf("%s", res); (or %c in example) , prints %:

.globl printpercent  # name:        printpercent # synopsis:    simplified sprintf # c-signature: int printpercent(unsigned char *res, unsigned char *format, ...); # registers:   %eax: first argument #              %ebx: second argument  printpercent:                       # sprinter     pushl       %ebp        # start of     movl        %esp, %ebp  # function      movl        8(%ebp), %eax   # first argument     movl        12(%ebp), %ebx  # second argument  loop:     movb        $37, %bl        # lowest bits %     movb        %bl, %al     jmp         exit     movb        (%ebx), %dl     #      cmp         $0, %dl         # check if 0      je              exit        # if 0 -> exit      cmp     $37, %dl            # check '%'        movb        %dl, (%eax)     # if doesnt equal above/or default                                 # add register %eax      jmp     loop                # jump start of loop   exit:     popl        %ebp            # popping standard end of function                                 # 0-byte ?     ret                         # return 

your function returns int of course compile alayws take full register return value. after int == 4 bytes in environment. have to clear eax ,make sure there no random values in it.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -