I have just started into RTSP and was looking at the assembly code in Microchip's RTSP examples. There are two files rtsp_api.h
and rtsp_api.s
. I wanted to know how are the return values fetched and how does that work.
For example, there is a function in rtsp_api.h
which is declared as follows
/******************************************************************************
* Function: int16_t FlashPageRead(uint16_t nvmAdru, uint16_t nvmAdr, int16_t *pageBufPtr);
*
* PreCondition: None
*
* Input: nvmAdru - Selects the upper 8bits of the location to program or erase
in program flash memory
nvmAdr - Selects the location to program or erase in program flash
memory. It must be aligned to 512 instruction boundary,
LSB 10bits of address must be zero
pageBufPtr- Pointer to the data array in which read data will be stored
*
* Output: Function returns ERROREE (or -1), if it is not successful,
Function return ZERO, if successful
*
* Side Effects: None
*
* Overview: This function provides the interface to read the flash.
*****************************************************************************/
int16_t FlashPageRead( uint16_t nvmAdru, uint16_t nvmAdr, int16_t *pageBufPtr );
and its definition in rtsp_api.s
is as follows
/******************************************************************************
Flash Page Read
Read EIGHT rows (PAGE) of memory, upper PM byte is discarded
*******************************************************************************/
_FlashPageRead:
push TBLPAG
mov w0, TBLPAG
mov #1024, w3
readNext:
tblrdl [w1],[w2++]
tblrdh [w1++],w6 ; Discard PM upper byte
dec w3, w3
bra nz, readNext
clr w0
pop TBLPAG
return
The code documentation says that the function returns -1 on failure.
Refering to the X16 Compiler User Guide section 13.8.2, I saw that the return valus are kept in W0 Register, but the code above clears the W0 register before returning.
Then how would the code return -1 ? Could this be a bug or is it my extremely limited knowledge of assembly ?