diff --git a/include/util/arena_alloc.nasm b/include/util/arena_alloc.nasm index a77df0b..1b0a1dd 100644 --- a/include/util/arena_alloc.nasm +++ b/include/util/arena_alloc.nasm @@ -38,10 +38,28 @@ arena_init: ret ; size_t align_up(size_t x, size_t a) +; eax, ebx. ecx are all clobbered arena_align_up: __CDECL16_ENTRY .func: - ; align the mark to the nearest specified alignment + ; align x up to the nearest specified alignment (a) + ; (x + (a-1)) & ~(a-1) + mov eax, [bp + 4] ; x + + mov ebx, [bp + 6] ; a - 1 + sub ebx, 1 + + mov ecx, eax + add ecx, ebx ; x + (a+1) + + not ebx + and ecx, ebx ; ecx contains the result + + xor eax, eax + xor ebx, ebx + mov eax, ecx ; return result in eax + xor ecx, ecx + .endp: __CDECL16_EXIT ret