Hi,    I am learning HC08GP32. I have an assembly program...

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Hi,    I am learning HC08GP32. I have an assembly program...

4,437 Views
zen
Contributor I
Hi,
   I am learning HC08GP32. I have an assembly programming question. That is how to load an address to A (accumulator), not the data hold in that address. For example:
....
TEMP1  EQU $8800
......
LDA TEMP1
 
The second instruction use TEMP1 as an address of data. If I want the address itself to be loaded to A, is there a better way than "LDA $8800" ? 
 
       Thanks!
                                    zen
Labels (1)
0 Kudos
Reply
12 Replies

2,352 Views
zen
Contributor I
Thank you all,
     I now understand that for HC08 the accumulator is 8 bit width and each address is 16 bit width.
 
     I  encounter another problem. please take a look at my code below
 
DATA_RISE:           equ  $00000107
DATA_OVFL:          equ  $00000113  ;RAMStart+19
DATA_CNTL:          equ  $00000118  ;RAMStart+24
 
; data sample control
                      org DATA_CNTL
                      sp_num_now: rmb 1    ; quantity of captured samples in BYTE
                      sp_num_req: rmb 1      ; quantity of needed sampels in BYTE, 6 samples equal 12 bytes.
                      ov_num_req: rmb 1       ; overflow data number requirement
                      temp1: rmb 1                 ; temperary data station
                                                                        
Init_data:                                                ; subroutine to initiate variables
                      mov #12,sp_num_req
                      mov #0,sp_num_now
                      mov #0,temp1
                      .........
 
      when simulating with CW, there was a warning of " A13003: Value is truncated to one byte" and this warring was located at at line of
 
                      "mov #12,sp_num_req "
 
      I checked the the instruction of RMB in  HC08ASMRM.pdf. But didnot find a solution.  Please help check this problem.
  
      Thanks!
       zen
0 Kudos
Reply

2,352 Views
peg
Senior Contributor IV
Hi Zen,

The MOV instruction only works in page zero. (direct addressing)
It works with 16-bit indexed no offset post increment but not along with immediate.
you have DATA_CNTL at $118 (i.e. page 1)
For example equating it to $F0 would make it work.
otherwise you could leave it in page 1 and use:
  LDA #12
  STA sp_num_rqd




Message Edited by peg on 2008-05-06 05:09 PM
0 Kudos
Reply

2,352 Views
zen
Contributor I
Thanks Peg,
     Page 0 is from $0000 to $00FF and can be used by direct address mode. Then how about page1,2,3  and FLASH memory. are they the same as far as the addressing mode is concerned? By the way, could you tell me the address ranges for Page 1,2 and 3?
 
Regards
zen
0 Kudos
Reply

2,352 Views
peg
Senior Contributor IV
Hi again Zen,

There is probably some mangling of terms here which can easily lead to confusion.
The smaller 8-bit controllers we are talking about here are not paged or segmented but have a simple 16-bit address space. Page zero here refers to that memory that can be addressed with only 8 bits. This is called direct addressing and has speed/space advantages in that only one byte is required to store the address within the programme. Using page 1, 2 etc with these controllers is probably wrong but could be used to indicate, Page 1 is $100 plus ($00 to $FF), Page 2 is $200 plus.......
Once your address is in the range $100 to $FFFF there is no difference throughout this range you need 16 bits or two bytes to store it.

0 Kudos
Reply

2,352 Views
zen
Contributor I
Peg,
       Thanks for your instructions.
        
           zen
 
 
0 Kudos
Reply

2,352 Views
zen
Contributor I
Thanks, 
The question is solved by myself. I forgot that I can use the simulation/debug function of codewarrior to try to find a soltion to a question. I found that attaching a "#" to an address tells the assembler that it is an immediate number, in this case, the number of the address itself.  The code I used is
 
            LDA #2
            STA Z_RAMStart
            LDA Z_RAMStart        ;  Z_RAMStart:         equ   $00000040
            LDA #Z_RAMStart 
 
 
zen
0 Kudos
Reply

2,352 Views
fabio
Contributor IV
Zen,

Don't forget that A is an 8-bit register and it can't hold a 16-bit address (necessary to address any memory address).

Note that doing LDA #10 loads A with 10 decimal, but LDA #1000 will not load A with 1000! In fact A will be loaded with 232 decimal...

Also, HC08 addressing modes are related to X and H:X registers (not to A). So, you should use H:X to hold 16-bit addresses and use the indexed addressing mode to access memory, as in the following example:

LDHX #Z_RAMStart ; loads H:X with the address of Z_RAMStart
LDA ,X   ; loads A with the content of the address pointed to by H:X

Or you can use just X to hold 8-bit addresses (mostly for direct page access):

CLRH
LDX  #Z_RAMStart
LDA ,X

Best regards,




0 Kudos
Reply

2,352 Views
peg
Senior Contributor IV


fabio wrote:
Zen,

Note that doing LDA #10 loads A with 10 decimal, but LDA #1000 will not load A with 1000! In fact A will be loaded with 232 decimal...




Hello,

Note that the first example quoted above assumes the base or radix of the assembler is set to 10. It may well load 16 if it were set to hexadecimal (the default of some).

In the second example, if your assembler produces code that loads 232 into A, get another assembler! This should not get past the assembler without an error!



Message Edited by peg on 2008-05-06 08:35 AM
0 Kudos
Reply

2,352 Views
fabio
Contributor IV
Hi Peg,

I agree with you with regard to the radix.

Regarding the truncation, the assembler (CW) assemble that line without errors (just warnings, as expected).

The purpose of that line was to show that the desired operation can't be done in such way and the result is not what it was expected to be.

Best regards,
0 Kudos
Reply

2,352 Views
peg
Senior Contributor IV
Hi Fabio,

To me this is an error. Other assemblers halt on the first pass with an error.
To me a warning is when you might want to let it slip by. Some truncations only warrant a warning as the outcome is still what the programmer intended. I fail to see how the outcome here (when the value does not fit in a byte) could be what the programmer intended.

0 Kudos
Reply

2,352 Views
PeterHouse
Contributor I
Very important information when using the h:x as a pointer in your code:

The h register is NOT saved during normal interrupt processing - you MUST save h in any interrupt code where you might change the value in h or you will have strange intermitent errors!

Good Luck,

Peter House
0 Kudos
Reply

2,352 Views
bigmac
Specialist III
Hello Zen,
 
I am not sure what you are trying to achieve.  But keep in mind that the accumulator can only hold an 8-bit value, whereas an address will generally be a 16-bit value (unless specifically accessing page-0 peripheral registers, or RAM).
 
For your initial example,
 
   TEMP1  EQU $8800
   ......
   LDA TEMP1
 
This will load the contents of (flash) address $8800 to the accumulator.  The following sequence will achieve a similar result.
 
   LDHX  #TEMP1  ; H:X = sddress of TEMP1
   LDA   ,X      ; Contents of TEMP1
 
The second method is useful when attempting to read successive bytes in a data table, where only the start of the table needs to be identified by a label.
 
Regards,
Mac
 
0 Kudos
Reply