Wednesday, January 11, 2012

Assembly - Add 2 interger number

Using AT&T syntax. First, is integer to string. We will divide 10 and push remainderto stack. Finish when result by 0. Pop from stack, and add 48 to convert to ascii charater. Now, you can print number:
.data
a:
    .int 123
b:
    .int 10
c:
    .int 0
thuong:
    .int 0
du:
    .int 0
Enter:
    .int 10
s:
    .ascii "1"
.text

.globl _start
_start:
    #nap so can in vao eax
    movl a,%eax   
    movl $0,%ecx
    #tach so
tach:
    movl $0,%edx
    #chia cho 10
    divl b
    #push so du vao
    addl $48,%edx
    pushl %edx
    inc %ecx
    cmp $0,%eax
    jne tach


in:
    popl %eax
    #luu ecx
    movl %ecx,c
   
    #in
    movl %eax,du   
    movl $4,%eax
    movl $1,%ebx
    movl $du,%ecx
    movl $1,%edx
    int $0x80
   
    #tra ecx
    movl c,%ecx
    loop in
   

    exit:
    movl $1,%eax
    movl $0,%ebx
    int $0x80

Soure: http://www.mediafire.com/?m8hzcrvum926878

And full source to print negative number: http://www.mediafire.com/?72h14t4h30ydf94

------------------------------------------------------------
Thanks for reading
--------------------------------------------------------------------------
All my Lab:
Linux Lab -- window and Cisco Lab
to be continued - I will update more.

No comments:

Install Xposed Inspector and Frida on Genymotion

Today i had some work with android. So i need trace application. I found 2 nice tool can help me: Xposed Inspector and Frida. To setup ther...