Thread: Assembly question

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    15

    Assembly question

    Hi,

    Can you please explain what the following program does?
    Code:
    Execution begins at address 0
            .pos 0
    init:   irmovl Stack, %esp      # Set up Stack pointer
            irmovl Stack, %ebp      # Set up base pointer
            jmp Main                # Execute main program
    
    # Array of 4 elements
            .align 4
    array:  .long 0xd
            .long 0xc0
            .long 0xb00
            .long 0xa000
    
    Main:   irmovl $4,%eax
            pushl %eax      # Push 4
            irmovl array,%edx
            pushl %edx      # Push array
            call rSum       # Sum(array, 4)
            halt
    
    /* $begin rsum-ys */
            # int Sum(int *Start, int Count)
    rSum:   pushl %ebp
            rrmovl %esp,%ebp
            pushl %ebx           # Save value of %ebx
            mrmovl 8(%ebp),%ebx  # Get Start
            mrmovl 12(%ebp),%eax # Get Count
            andl %eax,%eax       # Test value of Count
            jle L38              # If <= 0, goto zreturn
            irmovl $-1,%edx
            addl %edx,%eax       # Count--
            pushl %eax           # Push Count
            irmovl $4,%edx
            rrmovl %ebx,%eax
            addl %edx,%eax
            pushl %eax           # Push Start+1
            call rSum            # Sum(Start+1, Count-1)
            mrmovl (%ebx),%edx
            addl %edx,%eax       # Add *Start
            jmp L39              # goto done
    L38:    xorl %eax,%eax       # zreturn:
    L39:    mrmovl -4(%ebp),%ebx # done: Restore %ebx
            rrmovl %ebp,%esp     # Deallocate stack frame
    popl %ebp            # Restore %ebp
            ret
    /* $end rsum-ys */
            .pos 0x400
    Stack:  # The stack goes here
    Last edited by Salem; 11-01-2007 at 10:11 AM. Reason: Added code tags - use them!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assembly question
    By geek@02 in forum Tech Board
    Replies: 8
    Last Post: 08-11-2008, 06:48 AM
  2. Assembly Language Question
    By John_L in forum Tech Board
    Replies: 2
    Last Post: 03-13-2008, 07:44 PM
  3. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM
  4. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  5. C/C++ vs assembly: speed comparison
    By Just in forum C++ Programming
    Replies: 11
    Last Post: 11-25-2002, 03:33 PM