Professional Web Applications Themes

Stack and "as" assembler in Xcode - Mac Programming

This is code assembled by "as" and disassembled by Xcode 0x0001b618 <+0000> mflr r0 0x0001b61c <+0004> stwu r0,-4(r1) 0x0001b620 <+0008> lwz r0,0(r1) 0x0001b624 <+0012> addi r1,r1,4 0x0001b628 <+0016> mtlr r0 The register just after mflr: r0 and lr are 0xb000 r1 is 0xf005fce0 At the stwu instruction gdb report Current language: auto; currently c warning: ppc_frame_chain_valid: stack pointer from 0xf005fcdc to 0xb000 grows upward; assuming invalid mi_cmd_stack_list_frames: Not enough frames in stack. mi_cmd_stack_list_frames: Not enough frames in stack. If the line stwu r0,-4(r1) is replaced by addi r1,r1,-4 stw r0,0(r1) the execution fail at the addi instruction and gdb report ...

  1. #1

    Default Stack and "as" assembler in Xcode

    This is code assembled by "as" and disassembled by Xcode

    0x0001b618 <+0000> mflr r0
    0x0001b61c <+0004> stwu r0,-4(r1)
    0x0001b620 <+0008> lwz r0,0(r1)
    0x0001b624 <+0012> addi r1,r1,4
    0x0001b628 <+0016> mtlr r0

    The register just after mflr:

    r0 and lr are 0xb000
    r1 is 0xf005fce0

    At the stwu instruction gdb report

    Current language: auto; currently c
    warning: ppc_frame_chain_valid: stack pointer from 0xf005fcdc to 0xb000
    grows upward; assuming invalid

    mi_cmd_stack_list_frames: Not enough frames in stack.
    mi_cmd_stack_list_frames: Not enough frames in stack.


    If the line

    stwu r0,-4(r1)

    is replaced by

    addi r1,r1,-4
    stw r0,0(r1)

    the execution fail at the addi instruction and gdb report the same message.

    Why lowered the stack pointer by only 4 bytes is wrong ?
    Is there anything I miss about calling assembler function from C.
    Do I need create my own stack space ?
    Alain Guest

  2. #2

    Default Re: Stack and "as" assembler in Xcode

    Alain Birtz wrote:
     

    See
    <http://developer.apple.com/doentation/DeveloperTools/Conceptual/MachORuntime/>

    Note that the stack pointer should have 16 byte (quad word) alignment,
    and the minimum stack frame size is 56 bytes (no, I've never understood
    how these are compatible).


    --
    Pull out a splinter to reply.
    Peter Guest

  3. #3

    Default Re: Stack and "as" assembler in Xcode

    In article <E0Kec.50949$news.prodigy.com>,
    Peter Ammon <com> wrote:
     

    Simple -- you can have a 56-byte stack frame as long as you don't call any
    functions that need to allocate their own stack frames below yours.

    meeroh

    --
    If this message helped you, consider buying an item
    from my wish list: <http://web.meeroh.org/wishlist>

    Miro Guest

  4. #4

    Default Re: Stack and "as" assembler in Xcode

    In fact the code is correct.

    The problem is gdb.

    It is the debugger itself that cause the error when stepping instruction.

    Working with break point only I found a small error in my code.

    Now everything run correctly.

    Be warn that gdb is bugged (for stepi). At least for code asssembled by "as".


    In article <168.1.3>, ca (Alain
    Birtz) wrote:
     
    Alain Guest

Similar Threads

  1. Replies: 2
    Last Post: December 24th, 11:21 AM
  2. "Start" "Program" "Menu" list is empty
    By Pete in forum Windows XP/2000/ME
    Replies: 2
    Last Post: July 10th, 10:42 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139