Hello All!

I'm new at X86_64 assembly, and I am trying to implement a brk memory management program, but I'm having some issues with some lines of the code.

.data part:

.section .data

heap_start: .double 0

.equ HDR_AVAIL_OFFSET, 0
.equ HDR_SIZE_OFFSET,4
.equ UNAVAILABLE, 0
.equ AVAILABLE, 1
the text section part with the issue:

.text
alloc:
movq heap_start, %rdx
loop:
movq HDR_AVAIL_OFFSET(%rdx), %rcx
cmpq $UNAVAILABLE, %rcx
jne found_space
loop2:
movq HDR_PROX(%rdx), %rdx
cmpq %rdx, heap_start
jne loop
jmp new_brk
found_space:

cmpq HDR_SIZE_OFFSET(%rdx), %rdi
jg loop2

The problem is, that HDR_AVAIL_OFFSET(%rdx) should load the contents addressed by 0 on heap_start. However, it is returning a completely different memory address into %rcx.

heap_start points to the start of the memory array I want to check, and the first element is 0. When I use x/nfu to examine memory on gdb, it shows the following:

(gdb) x/nfu $rdx
0x602001: 0
but after

movq HDR_AVAIL_OFFSET(%rdx), %rcx
the %rcx is:

(gdb) print $rcx
$1 = 429496729600

Can anyone tell me what am I doing wrong?
Thank you!