Wednesday, December 23, 2009

Delete Entry

Delete entry was straight forward. I had most of the code from read_value already.

delete_value
; Takes offset of value to be deleted in R3.
; Returns 1 in R3 if there is a problem.
; Returns 0 in R3 for success.

LDR R4, =Heap_Manager ; Set R4 to Heap_Manager base.
MOV R3, R3, LSL#2 ; Multiply R3 by 4: Heap manager uses words, not bytes
ADD R4, R4, R3 ; Get address of heap_manager entry.
MOV R3, #0 ; Set heap manager entry to 0
STR R3, [R4]
BX R14 ; Return

This sets the specified entry to 0. I documented a return value of 1 as an error, but there are no error conditions.

This addition does bring up a problem: What happens if you now try to read from the spot you just deleted? Well, the way the read routine worked, it would have returned the first byte below the heap memory.

Yes, before the heap memory. It's a side effect of the decrement approach.

I added an exit with error code to the read function.

CMP R2, #0 ; Check for 0 value, meaning read is not valid
BEQ error_out
...
error_out LDR R3, =0xFFFFFFFF
BX R14


Testing seems to work, but I'm sticking with pretty straight-forward test cases.

No comments:

Post a Comment