From 0eeff3634c48e92207f9b25611eaa1cb90ea8bd2 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Mon, 20 Apr 2026 23:59:46 +0200 Subject: [PATCH] avr: added Heap_AllocAndZero --- avr/modules/heap/main.asm | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/avr/modules/heap/main.asm b/avr/modules/heap/main.asm index fa9fadd..a3938ac 100644 --- a/avr/modules/heap/main.asm +++ b/avr/modules/heap/main.asm @@ -86,6 +86,39 @@ Heap_Alloc: +; --------------------------------------------------------------------------- +; @routine Heap_AllocAndZero +; +; Allocates data on the heap and presets all bytes with zero. +; +; @param r25:r24 number of bytes to alloc +; @return CFLAG set of okay, cleared otherwise +; @return X start of allocated memory +; @clobbers r16, r17, r18, r19, r24, r25, X + +Heap_AllocAndZero: + push r24 + push r25 + rcall heapAllocFirstFit + pop r25 + pop r24 + brcc Heap_AllocAndZero_ret + push xl + push xh + clr r18 +Heap_AllocAndZero_loop: + st X+, r18 + sbiw r25:r24, 1 + brne Heap_AllocAndZero_loop + pop xh + pop xl + sec +Heap_AllocAndZero_ret: + ret +; @end + + + ; --------------------------------------------------------------------------- ; @routine heapAllocFirstFit