Searching \ for '[PIC]: Assembler 101 question...' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'Assembler 101 question...'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Assembler 101 question...'
2001\01\24@163029 by McIlvaine, Robert

flavicon
face
Hi all,

You can write the following code in MPASM:

       org     0x000A
       data    0x01, 0x02, 0x03, 0x04

When you assemble it, starting at 000A, in code space, you get:

000A    0001
000B    0002
000C    0003
000D    0004


How does one access this data? In other words how does one load the value
from code space address 000A into the w register?


TIA,
Mac

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\24@165107 by Thomas C. Sefranek

face picon face
   MOVF    0X000A,W

"McIlvaine, Robert" wrote:

{Quote hidden}

--
 *
 |  __O    Thomas C. Sefranek  spam_OUTtcsTakeThisOuTspamcmcorp.com
 |_-\<,_   Amateur Radio Operator: WA1RHP
 (*)/ (*)  Bicycle mobile on 145.41, 448.625 MHz

ARRL Instructor, Technical Specialist, VE Contact.
hamradio.cmcorp.com/inventory/Inventory.html
http://www.harvardrepeater.org

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\24@170143 by David VanHorn

flavicon
face
At 04:49 PM 1/24/01 -0500, Thomas C. Sefranek wrote:
>     MOVF    0X000A,W

Isn't that going to put the contents of file reg 0Ah into W?

--
Where's dave? http://www.findu.com/cgi-bin/find.cgi?kc6ete-9

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\24@171641 by Olin Lathrop

face picon face
>         org     0x000A
>         data    0x01, 0x02, 0x03, 0x04
>
> When you assemble it, starting at 000A, in code space, you get:
>
> 000A    0001
> 000B    0002
> 000C    0003
> 000D    0004
>
>
> How does one access this data? In other words how does one load the value
> from code space address 000A into the w register?

You don't, on most PICs at least.  On the 16Fxxx and 18xxx series you can do
"table read" to directly read program memory locations.  For most other PICs
you can only store data in program memory by encoding it into the immediate
field of some instructions.  RETLW is usually used for tables on these PICs.


*****************************************************************
Olin Lathrop, embedded systems consultant in Devens Massachusetts
(978) 772-3129, .....olinKILLspamspam@spam@embedinc.com, http://www.embedinc.com

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\24@174159 by Douglas Wood

picon face
On the 17Cxxx and 18Cxxx PICs, you can access program memory via the 'table
read' instructions.

On the 16Fxxx PICs, you can access program memory via a set of SFR (special
function registers).

On all other PICs, you'll have to use a 'computed GOTO/RETW-style' table.

Douglas Wood
Software Engineer
dbwoodspamKILLspamkc.rr.com

Home of EIS (Enhanced Instruction Set) for the PIC

{Original Message removed}

2001\01\24@174415 by Drew Vassallo

picon face
> >         org     0x000A
> >         data    0x01, 0x02, 0x03, 0x04
> >
> > When you assemble it, starting at 000A, in code space, you get:
> >
> > 000A    0001
> > 000B    0002
> > 000C    0003
> > 000D    0004
> >
>You don't, on most PICs at least.  On the 16Fxxx and 18xxx series you can
>do
>"table read" to directly read program memory locations.  For most other
>PICs
>you can only store data in program memory by encoding it into the immediate
>field of some instructions.  RETLW is usually used for tables on these
>PICs.

More specifically, typically you access data tables through a call and
modification of a program counter.  For Microchip's MPLAB or MPASM, the
instruction for "data" that is used is "dt" followed by your data, which
will automatically be assembled into a data table, one line for each byte of
data.

;;Call with byte to retrieve in W (in this case, W in range of 0-3)
SimpleTable
     addwf PCL
dt 0x01, 0x02, 0x03, 0x04

--Andrew
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\24@193109 by Dwayne Reid

flavicon
face
At 04:26 PM 1/24/01 -0500, McIlvaine, Robert wrote:
>Hi all,
>
>You can write the following code in MPASM:
>
>         org     0x000A
>         data    0x01, 0x02, 0x03, 0x04
>
>When you assemble it, starting at 000A, in code space, you get:
>
>000A    0001
>000B    0002
>000C    0003
>000D    0004
>
>
>How does one access this data? In other words how does one load the value
>from code space address 000A into the w register?

You enter it as a bunch of RETLW statements.  In other words,
000A  retlw  01
000B  retlw  02
000C  retlw  03
000D  retlw  04

To retrieve the data, simply 'call' that memory location.  Eg.
  call  000A
The data is returned in W.

Couple of things: 1) use descriptive labels for each constant.  2) make
sure that you are in the correct page before calling the subroutine (cause
that is what each of those statements is: a 1 line subroutine).

You can use a bunch of those statements in a lookup table as well.  But
sometimes its easier to explicitly name and retrieve each constant.

dwayne





Dwayne Reid   <.....dwaynerKILLspamspam.....planet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, AB, CANADA
(780) 489-3199 voice          (780) 487-6397 fax

Celebrating 17 years of Engineering Innovation (1984 - 2001)

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Do NOT send unsolicited commercial email to this email address.
This message neither grants consent to receive unsolicited
commercial email nor is intended to solicit commercial email.

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\24@225343 by Mitchell D. Miller

picon face
Don't know about the PICs, but the Ubicom SX has an IREAD command which
reads directly from program memory.

-- Mitch

{Original Message removed}

2001\01\25@104020 by jamesnewton

face picon face
www.piclist.com/techref/microchip/tables.htm

But it needs some sample code for the 17/18C's table read instruction and
the 16Fxxx SFR's.

Anyone care to contribute?

---
James Newton (PICList Admin #3)
EraseMEjamesnewtonspam_OUTspamTakeThisOuTpiclist.com 1-619-652-0593
PIC/PICList FAQ: http://www.piclist.com or .org

{Original Message removed}

2001\01\25@123545 by Harold M Hallikainen

picon face
       On older PICs (prior to 18c or others with table instructions), you have
to use retlw to get data from a table in code space to data space.

Harold


On Wed, 24 Jan 2001 16:58:21 -0500 David VanHorn <dvanhornspamspam_OUTCEDAR.NET>
writes:
{Quote hidden}

FCC Rules Online at http://hallikainen.com/FccRules
Lighting control for theatre and television at http://www.dovesystems.com

________________________________________________________________
GET INTERNET ACCESS FROM JUNO!
Juno offers FREE or PREMIUM Internet access for less!
Join Juno today!  For your FREE software, visit:
dl.http://www.juno.com/get/tagj.

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email @spam@listservKILLspamspammitvma.mit.edu with SET PICList DIGEST in the body


2001\01\25@125206 by o-8859-1?Q?K=FCbek_Tony?=

flavicon
face
>But it needs some sample code for the 17/18C's table read instruction
and
>the 16Fxxx SFR's.

>Anyone care to contribute?


#define STRING_HOWDY    0
#define STRING_PICLIST  1
#define STRING_HELLO    2
#define STRING_NONSENSE 3
#define STRING_LAST     4

; use like
; MOVLW STRING_HELLO
; CALL  GET_STRING
; content in String...
;

;+++++
;       GET_STRING - Enter with string number in w, reads string from
memory until null detected
;       (  due to an request from James Newton )
;       For the 18Cxx series using the table read functions    
;       Replica of an multistring example by Scott Dattalo, but
converted to use table functions instead.
;       Handles upto 256 separate strings ( or data or text etc )
;       This version uses the following ram:
;       StringTmp  one byte
;       String  x amount of bytes, where to put the string, could be
replaced by an byte output
;               routine
;       By Tony Kübek, 2001-01-25
;       email: KILLspamtony.kubekKILLspamspamflintab.com
;      
GET_STRING
       ; we enter with string number in w
       MOVWF   StringTmp       ; save menu string index temporarily
       
       MOVLW   HIGH(STRING_PTR_TABLE)  ; get pointer high byte  to
string pointer table                                      ;
       MOVWF   TBLPTRH,A               ; setup high adress

       MOVF    StringTmp,W     ; get offset back
       ADDWF   StringTmp,F     ; multiply with two to get string
pointer offset
       
       ; test for overflow when doubling string pointer offset
       SKPNC                  
       INCF    TBLPTRH,F,A     ; inc high byte adress
               
       ADDLW   LOW(STRING_PTR_TABLE)   ; add offset to pointer to the
string low byte                                        ;
       MOVWF   StringTmp               ; save it
       SKPNC                   ; check if low byte generated overflow
       INCF    TBLPTRH,F,A     ; then add one to high byte
       ; clear upper adress ( we dont have that amount of program mem )
       CLRF    TBLPTRU,A

       MOVFF   StringTmp,TBLPTRL ; finally set low adress
       ; read the two bytes
       TBLRD*+         ; read low adress of menu and increment pointer
       MOVFF   TABLAT,StringTmp ; save it temporarily
       TBLRD*+         ; read high adress of string and increment
pointer
       MOVFF   TABLAT,TBLPTRH; set high adress for char loop
       MOVFF   StringTmp,TBLPTRL ; and set low adress
               
       ; setup fsr0 to point to menutext variable were we will put the
bytes
       ; could ofcource be omitted if putputting one byte at a time in
loop below
       MOVLW   HIGH(String)
       MOVWF   FSR0H
       MOVLW   LOW(String)
       MOVWF   FSR0L

GET_STRING_CHAR_LOOP    ; loop through the string ( until null detected
)
       TBLRD*+ ; read next byte and increment pointer
       MOVF    TABLAT,W,A      ; get byte into w
       ANDLW   0xFF
       SKPNZ           ; if byte is zero we have reached the end of
string
         GOTO  GET_STRING_NULL ; now get consecutive bytes
       ; save the byte in the string
       MOVWF   POSTINC0        ; save byte and increment fsr0 pointer
       GOTO    GET_STRING_CHAR_LOOP

GET_STRING_NULL
       ; end string with null
       MOVWF   INDF0
       ; now we can read other data located directly after the string
or just return...
       RETURN
       
;+++++
;       STRING_PTR_TABLE - the pointer table to the strings, two bytes
for each string
;      
STRING_PTR_TABLE
       DW STRING0
       DW STRING1
       DW STRING2
       DW STRING4
       ; etc..upto 255
       
;+++++
;       STRING_TABLE - all the strings...
;       Note if strings have fixed length then the pointer table above
is not necessary
;       then offset can be calculated instead
STRING_TABLE
STRING0:        DB   "HOWDY",0x00
STRING1:        DB   "PICLIST",0x00
STRING2:        DB   "HELLO WORLD",0x00
STRING3:        DB   "ALMOST THE LAST ONE",0x00
STRING3:        DB   "I'M THE LAST ONE",0x00



/Tony



Tony Kübek, Flintab AB            
²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²
E-mail: RemoveMEtony.kubekTakeThisOuTspamflintab.com
²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spamBeGonelistservspamBeGonespammitvma.mit.edu with SET PICList DIGEST in the body


2001\01\29@103031 by Bourdon, Bruce

flavicon
face
Mac, and others:

When I first became interested in the PIC16F87x I had read that the flash
program memory could be read and immedeatly thought of tables... weeks later
you asked this and I tried to find that statement, well I finally found it -
sorry for the delay (from DS30292B-page 44):

4.5 Reading the FLASH Program Memory
A program memory location may be read by writing two
bytes of the address to the EEADR and EEADRH reg-isters,
setting the EEPGD control bit (EECON1<7>)
and then setting control bit RD (EECON1<0>). Once
the read control bit is set, the microcontroller will use
the next two instruction cycles to read the data. The
data is available in the EEDATA and EEDATH registers
after the second NOP instruction. Therefore, it can be
read as two bytes in the following instructions. The
EEDATA and EEDATH registers will hold this value until
another read operation or until it is written to by the user
(during a write operation).

; EXAMPLE 4-3: FLASH PROGRAM READ
BSF STATUS, RP1 ;
BCF STATUS, RP0 ; Bank 2
MOVLW ADDRH ;
MOVWF EEADRH ; MSByte of Program Address to read
MOVLW ADDRL ;
MOVWF EEADR ; LSByte of Program Address to read
BSF STATUS, RP0 ; Bank 3
BSF EECON1, EEPGD ; Point to PROGRAM memory Required
BSF EECON1, RD ; EEPROM Read Sequence
NOP ; memory is read in the next two cycles after BSF EECON1,RD
NOP ;
BCF STATUS, RP0 ; Bank 2
MOVF EEDATA, W ; W = LSByte of Program EEDATA
MOVF EEDATH, W ; W = MSByte of Program EEDATA


{Original Message removed}

More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...