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
MapName6 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.
Best Answer
Step back and think about the whole problem. No, you haven't done A, B, and D yet. There are so many things wrong here that demonstrate such major misunderstanding that I don't know how to begin explaining. All I can do is enumerate some problems:
You need to step back and try to understand how compiled code gets run on the machine, what the subroutine linkage conventions are, and then how to implement them in assembler to make a C function that returns a byte. Try to understand the role of compiler, assembler, and linker and how they interact. You're nowhere near ready for this problem yet.