Take_Care_
Take_Care_

Reputation: 2154

Getting ASCII number value

Hi Guys I got some annoying problem ,so I try to write a code just to reverse small string sequential

I Already got this :

    .section    .data   
string:
    .ascii "AAAAAABBBBBB"



length:
    .quad . -string     #Dot = 'here'

    .section    .text   


    .globl _start       #Make entry point visible to linker
_start:
    movl $4, %eax       #4=write
    movl $1, %ebx       #1=stdout
    movl $string, %ecx
    movl length, %edx
    int $0x80       #Call Operating System

    movl length,%edi    #counter
    shrl $1,%edi        #half of string
    movl $0,%ecx            #start from index one 
    movl length,%edx        #start from end

reverse:    
    movl string(,%ecx,1),%eax   
    movl string(,%edx,1),%ebx
    movl %eax,string(,%edx,1)
    movl %ebx,string(,%ecx,1)
    inc %ecx
    dec %edx
    dec %edi




    loop reverse   #looping 

    movl $4, %eax       #4=write
    movl $1, %ebx       #1=stdout
    movl $string, %ecx
    movl length, %edx
    int $0x80       #Call Operating System



    movl $0, %ebx       #Make program return syscall exit status
    movl $1, %eax       #1=exit
    int $0x80       #Call System Again

And it's not working correctly , cuz in gbd i get wrong values in registers after making

movl string(,%ecx,1),%eax or the next steps I think there should be in %eax value for A letter but its doesn't any ideas ?

Upvotes: 0

Views: 70

Answers (1)

Jester
Jester

Reputation: 58822

You should be processing bytes not longs, so use movb with 8 bit registers (al and bl, for example). Also, the LOOP instruction uses ECX automatically, you probably meant JNZ there to repeat until EDI reaches zero.

Upvotes: 1

Related Questions