Hey guys for my second year Computer Science project we were tasked with creating a garbage collector in 32-bit nasm assembly. I managed to get everything running fine except one thing. We are suppose to mimick the gclib sbrk function using the system call to brk.
Here is my working version:
.if2:
mov eax, 0
push eax
call abrk
add esp, 4
mov ecx, eax
mov edx, num_units
shl edx, 3
push edx
call sbrk
add esp, 4
cmp eax, -1
je .if2body
mov vp, ecx
jmp .cont1
.if2body:
mov eax, 0x00
jmp .return
now to get rid of the sbrk i did the following which causes a segfault in a completely different function:
.if2:
mov eax, 0
push eax
call abrk
add esp, 4
mov ecx, eax
mov edx, num_units
shl edx, 3
add eax, edx
push eax
call abrk
add esp, 4
cmp eax, ecx
je .if2body
mov vp, ecx
jmp .cont1
.if2body:
mov eax, 0x00
jmp .return
Here is the abrk function:
%define SYS_brk 0x2d
%define addr [ebp+8]
abrk:
push ebp
mov ebp, esp
push ebx
mov eax, SYS_brk
mov ebx, addr
int 0x80
.end:
pop ebx
mov esp, ebp
pop ebp
ret
I have no idea what could be wrong, I've asked my lecturer and he could not find a fault either.
Also the version that does not work worked on my universities lab pcs but not on mine could it be caused by difference in ubuntu versions? Thanks for the help.