UDATA RES CBLOCK -- Practice versus Perfection

Status
Not open for further replies.

jpanhalt

Well-Known Member
Most Helpful Member
I found this thread quite interesting: https://www.microchip.com/forums/tm.aspx?m=375731
Be sure to check the links on page 2.

The authors are quite adamant that a directive such as, Flag equ 0x20 or its CBlock equivalent assigns the value 0x20 to the string "Flag," rather than assigning that label to a register. Nevertheless, examples show how it can be used successfully as if the register contents were identified by Flag. Problems are also illustrated.

If you are using absolute code, what do you do?

Is the practice of using Udata (and its variants) and Res to assign a register gaining in popularity even with absolute coders?

John
 

I've no idea what you're on about?.

"Flag equ 0x20" assigns the value 0x20 to Flag, and that's exactly what you want it to do - the GPR you want is at address 0x20.
 
That's a debarkle and no mistake!!! CBLOCK and EQU are only really used for readability ( labeling ). It would be a bind to use the reg locations manually.

I thought that UDATA and IDATA were C constraints... The use of RES is for allocating memory in ASM.....Am I wrong here.

I extensively use C rather than assembler, so I'd like to know if UDATA is an assembler directive.
 
This is the code to illustrate how an error can occur:

Example 1:
Code:
   movf   MYVAR,w   ; load W register with contents from RAM location 0x20

versus
Example 2:
Code:
   movlw  MYVAR     ; load W register with the value 0x20



Example 1 successfully accesses the contents of the register. Example 2 does not. In most cases it seems, new coders will want to access the contents of the register, not the value of its location. My take from Lathrop's advice is to use RES to ensure that occurs. In contrast, on ETO, it seems RES is used relatively infrequently compared to CBlock or Equ, even when it is the register contents that will be accessed.

Hence my question as to what is common practice today.

John
 
I suggest you try reading what the instructions actually mean

How can an 'error' occur if you use the completely wrong instruction? - it doesn't matter if you use Equ, or RES (or anything else) it stil won't work if you use the wrong instructions.
 
That was simply the first example from that entire thread. The differences between CBlock/Equ and Udata/Res are more fleshed out in the thread and in links given in the thread. In particular, Gooligum's tutorial (mid-level, lesson 2) was recommended by one of the respondents and is quite good on the subject.

My question had nothing to do with my reading of the instructions, and I am a bit offended by the suggestion that I haven't done that.

Let me rephrase my question again. On PicList it is common to find code that uses Res/Udata. On ETO, it is much less common. Why is that so?

John
 
John! I agree with Nigel the MPASM manual is quite comprehensive....AND the datasheets all have excellent descriptions.... the command MOVLW is quite easily understandable as MOVe Literal into W.

Whereas MOVF file,w is again quite understandably MOVe from File into W.

Its all down to education.

RES is not the same as EQU in the slightest.
 
Last edited:

So why post an example that is simply using the completely incorrect instruction?, and has no bearing whatsoever on the supposed 'problem' - as it wouldn't work under ANY circumstances.

Let me rephrase my question again. On PicList it is common to find code that uses Res/Udata. On ETO, it is much less common. Why is that so?

Presumably the PICList examples are relocatable, or have been clipped from relocatable code - I don't see as there's any use (or difference) in using them for absolute code.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…