4.47

    A.

    Change into pointer version

    1. !INCLUDE './code/bubble-sort/bubble-sort-pointer.c'

    B.

    Compile bubble-sort-pointer.c

    1. gcc -S -Og bubble-sort-pointer.c

    get gas file

    1. !INCLUDE './code/bubble-sort/bubble-sort-pointer.s'

    Change it into ys version

    1. !INCLUDE './code/bubble-sort/bubble-sort-pointer.ys'

    main difference is second param of function is long* end instead of
    long count for convinient, long* end marks the position of last element.

    using yas assemble it and yis run it, see output

    1. ../sim/misc/yas bubble-sort-pointer.ys
    2. ../sim/misc/yis bubble-sort-pointer.yo
    3. Stopped in 117 steps at PC = 0x13. Status 'HLT', CC Z=1 S=0 O=0
    4. Changes to registers:
    5. %rax: 0x0000000000000000 0x0000000000000020
    6. %rsp: 0x0000000000000000 0x0000000000000200
    7. %rsi: 0x0000000000000000 0x0000000000000018
    8. %rdi: 0x0000000000000000 0x0000000000000018
    9. %r9: 0x0000000000000000 0x0000000000000001
    10. %r10: 0x0000000000000000 0x0000000000000002
    11. Changes to memory:
    12. 0x0018: 0x0000000000000004 0x0000000000000001
    13. 0x0020: 0x0000000000000003 0x0000000000000002
    14. 0x0028: 0x0000000000000002 0x0000000000000003
    15. 0x0030: 0x0000000000000001 0x0000000000000004
    16. 0x01f0: 0x0000000000000000 0x0000000000000055
    17. 0x01f8: 0x0000000000000000 0x0000000000000013

    initial array order is 4,3,2,1, now 1,2,3,4