x86 - Assembly, registers and return values -m32 / linux -


i'm trying make simple codes in assembly can understand more. start want make function takes parameter.

i want add value parameter, example letter 'a', (has value 65 in ascii). want function return a, since eax holds 4 bytes , letter needs 1 byte, i'm trying use al part of eax register.

the problem here function doesn't work when use it. 4 strange-looking characters return value. knows why?

this how code looks like:

        .globl  letterprinter # name:             letterprinter # synopsis:         prints character 'a' (or @ least, supposed to) # c-signature:      int letterprinter(unsigned char *res); # registers:        %edx: argument supposed value #                   %eax: return value(s) #    letterprinter:                      # letterprinter      pushl       %ebp                # start of     movl        %esp, %ebp          # function      movl        8(%ebp), %edx       # first argument      movl        $65, %dl            # value 'a' in lowest part of edx, dl      movb        (%dl), %al          # moves return register eax     jmp     exit                    # ending function  exit:      popl        %ebp                # popping - standard end of function                                     # 0-byte ? should there one?     ret                             # return 

                    .globl  char  # name:         char # synopsis:         simplified sprintf # c-signature:      int sprinter(unsigned char *res, unsigned char); # registers:        %edx: first argument #               %ebx: second argument #    char:                   # char      pushl       %ebp            # start of     movl        %esp, %ebp      # function      movl        8(%ebp), %edx           # first argument     movl        12(%ebp), %eax          # second argument   add_res:     movb        %al, (%edx)     # eax low gets val @ edx     movb        $65, (%edx)     # puts string     jmp     exit            # jump exit    exit:      popl        %ebp            # popping standard end of function     movb        $0,1(%edx)      # adds zero-byte @ end                          ret                 # return 

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 -