Reputation: 1
I'm writing bubble sort in x86 assembly. I used DDD to figure out registers status and stack info.
I steped through the program, and I ran into the error 0x00000000004000e7 in ?? ()
. I want to figure out why this happened.
This is my bubble_sort.s
.section .text
.global _start
_start:
movq $0, %rsi #i = 0;
movq $0, %rdi #j = 0;
movq $4, %rbx #N = 4;
subq $40,%rsp
movq $4, (%rsp) #a[0] = 4;
movq $3, 4(%rsp) #a[1] = 3;
movq $2, 8(%rsp) #a[2] = 2;
movq $1, 12(%rsp) #a[3] = 1;
subq $1, %rbx #N = N - 1
cmpq %rsi, %rbx #i - (N-1)
jge .DONE1
.LOOP1:
movq %rbx, %r15 #%rdx: N - 1
subq %rsi, %r15 #%rbx: N-1-i
cmpq %rdi, %r15 #if(j < N-1-i)
jge .DONE2
.LOOP2:
movq (%rsp, %rdi, 4), %r8
xchg %r8, 1(%rsp, %rdi, 4)
movq %r8, (%rsp, %rdi, 4)
addq $1, %rdi #j = j+1
cmpq %rdi, %r15 #compare j with N-1-i
jl .LOOP2
.DONE2:
addq $1, %rsi
cmpq %rsi, %rbx #i - (N-1)
jl .LOOP1
.DONE1:
I stepped through. When I run movq %rbx, %r15 #%rdx: N - 1
, ddd showed me 0x00000000004000e7 in ?? ()
.
Then I run the next line, ddd showed me Cannot find bounds of current function
.
I am puzzled, and I have not figure out why this happened. Could you please tell me what mistake I have made?
Upvotes: 0
Views: 104