开发者

Creating an ASM file that will return the characters located in 8 consecutive registers

I have to create an ASM file for the PIC18F452 that does the following:

(a) define the label MapName as the first of 8 consecutive registers containing a null-terminated string of not more than 7 characters. (b) access an 8-bit unsigned integer variable called MapIndex which was declared in a C file. (c) define an ASM function getMapChar which can be called from C using the function prototype char getMapChar(void). The function should return the appropriate character when the value of MapIndex is <= 7 or the value 255 if MapIndex is > 7. (d) make the labels MapName and getMapChar accessible to an external C file.

My code so far is shown below:

; Configuration word : WDT off, power-up timer on, code protect off, RC oscillator

list = p18f452

MapName     equ     0x20
MapName1    equ     0x21
MapName2    equ     0x22
MapName3    equ     0x23
MapName4    equ     0x24
MapName5    equ     0x25
MapN开发者_StackOverflow中文版ame6    equ     0x26
MapName7    equ     0x27
CurrentChar equ     0x28

extern  MapIndex

org 0x00
goto    getMapChar

getMapChar
    movlw   0x00
    movwf   MapName7

GLOBAL  getMapChar
GLOBAL  MapName

    END

I have already done parts (a), (b) and (d) but I am having some problems with writing the code that moves through each of the consecutive registers automatically using the value of MapIndex. Could anyone help me please? It would be much appreciated.


You can use one of FSR (file select registers) to address MapName file registers:

lfsr    0, MapName      ;Load 12bit file address pointer to FSR0
movf    MapIndex, w     ;Load MapIndex to WREG  ; or movff MapIndex, WREG
addwf   FSR0L, f        ;Add MapIndex to FSR0 low byte
movf    INDF0, w        ;Load MapName[MapIndex] to WREG

If all file registers of variable MapName aren't inside 8 bit address space then after adding MapIndex to FSR0L check Carry flag for overflow. If Carry is set increase also the FSR0H file register.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜