.if HEAP_DEBUG
hp_print_free:
- push temp4
- push temp3
+ push r15
+ push r14
push temp2
push temp
printstring ", bytes free: "
- lds temp3,hp_top
- lds temp4,hp_top+1
+ lds r14,hp_top
+ lds r15,hp_top+1
ldi temp,0
ldi temp2,0
- sub temp,temp3
- sbc temp2,temp4
- ldi temp3,0
- ldi temp4,0
+ sub temp,r14
+ sbc temp2,r15
+ clr r14
+ clr r15
rcall print_ultoa
printstring " "
pop temp
pop temp2
- pop temp3
- pop temp4
+ pop r14
+ pop r15
ret
-.endif
+.endif
; Init heap
printnewline
printstring "Heap init: Start: "
rjmp hp_dbg1
-.endif
+.endif
heap_release:
.if HEAP_DEBUG
printnewline
printstring "Heap release: Start: "
hp_dbg1:
-.endif
+.endif
sts hp_top,temp
sts hp_top+1,temp2
.if HEAP_DEBUG
rcall printhexw
rcall hp_print_free
-.endif
+.endif
ret
; Get memory block from heap.
; return 0 if not enough space
heap_get:
- push temp4
- push temp3
+ push r15
+ push r14
.if HEAP_DEBUG
push temp2
push temp
printnewline
printstring "Heap get: "
- ldi temp3,0
- ldi temp4,0
+ clr r14
+ clr r15
rcall print_ultoa
pop temp
- pop temp2
-.endif
- lds temp3,hp_top
- lds temp4,hp_top+1
- add temp,temp3
- adc temp2,temp4
+ pop temp2
+.endif
+ lds r14,hp_top
+ lds r15,hp_top+1
+ add temp,r14
+ adc temp2,r15
brcs hp_full
-
+
; zero flag clear here
sts hp_top,temp
sts hp_top+1,temp2
- movw temp,temp3
+ movw temp,r14
rjmp hp_get_ex
hp_full:
clr temp
printstring "Error: "
hp_get_dbg1:
rcall hp_print_free
- mov temp3,temp ;restore zero flag
- or temp3,temp2
+ mov r14,temp ;restore zero flag
+ or r14,temp2
.endif
- pop temp3
- pop temp4
+ pop r14
+ pop r15
ret
; vim:set ts=8 noet nowrap
-