CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Hcs12

  1. #1
    Join Date
    Nov 2005
    Posts
    79

    Hcs12

    Hi,

    I am learning assembly for the micro controller MC9S12C32 with the compiler code warrior.

    I would like to know if there someone that can help me. I have some problems with my codes and other questions regarding some instructions.

    I read the earlier posts and it seems that there are the same instructions,
    But I am not sure.

    Please let me know

    Thank you
    B

  2. #2
    Join Date
    Dec 2006
    Posts
    72

    Re: Hcs12

    Hi Brad Sue,

    Most of postings in this section regard Intel x86 architecture (specially 16 and 32 bit).

    You may find similar instructions between Intel and the architecture you work with, but in order to help you it would be necessary to know the details and syntax of assembly language for that architecture.

    The good news is that once you learn assembler for one architecture, it will be much easier to get started with other architectures. This is because most (if not all) architectures are based on the same concepts.

    Good luck.

  3. #3
    Join Date
    Nov 2005
    Posts
    79

    Re: Hcs12

    Thank you,

    OK. My program has two sections. My problem is first more about the organization of the code.

    The first part is supposed to do the following:

    The first section of the program should perform the following steps:

    1 - Copy the data array into the Read-Write area of memory.
    data contains only upper and lower case letters, spaces, and the digits 0-9, all ASCII. The array is terminated by a null (zero) byte. The array, including the null, is no more than 100 bytes long

    2 - Search that array, converting each letter (a-z or A-Z) to a 1, each digit (0-9) to a 0, and leave the spaces unchanged.

    3 - When the entire array has been processed, I continue with Section 2 of the program.

    Here is what I did:

    Code:
    ; copy array data into ROM
    
              ldx       #data
       repeat:
    
                 ldaa   0,x   ;  get data entry into accumulator A
                 inx             ; increment x
                 [b]; here I don’t know how to check for null byte[/] 
                 bne    repeat
    
                ; done copy data array
    
                ;now converting part:
                ; for value > 9 convert to 1 otherwise convert to 0
                ; special case for  space  character
    
         loop:
    
               ; case of space. Maybe misplace
               cmpy   #$20   ; compare with the  hex “space” value($20)
               sty       #$20
    
    
                ldy       0,x     ; get the data entry into Y register
               cmpy     #9     ; compare the current value> 9
               bls          L1    ; if not skip to L1
               sty          #0     ; if not store 0 into Y
    
          L1:
                sty       #1      ; store 1 into Y
                iny                 ; increment  Y   
                ;here don’t know how to check for the end of  x
                 bra       loop
    
                 bra        SECTION2
    
         SECTION2:
          ……..
    I'd appreciate your help.

    Thank you
    B.

  4. #4
    Join Date
    Feb 2008
    Posts
    2

    Re: Hcs12

    I wonder which school teaches Hcs12 assembly?

    I have never coded HCS12, but it is very like MC6809.

    [QUOTE=brad sue]Thank you,

    OK. My program has two sections. My problem is first more about the organization of the code.

    The first part is supposed to do the following:

    The first section of the program should perform the following steps:

    1 - Copy the data array into the Read-Write area of memory.
    data contains only upper and lower case letters, spaces, and the digits 0-9, all ASCII. The array is terminated by a null (zero) byte. The array, including the null, is no more than 100 bytes long

    2 - Search that array, converting each letter (a-z or A-Z) to a 1, each digit (0-9) to a 0, and leave the spaces unchanged.

    3 - When the entire array has been processed, I continue with Section 2 of the program.

    Here is what I did:



    Quote Originally Posted by brad sue
    ; copy array data into ROM
    The above comment is wrong, I would count off if I read it.
    You can not copy data into ROM; you likely mean RAM.

    Quote Originally Posted by brad sue
    Code:
              ldx       #data
       repeat:
    
                 ldaa   0,x   ;  get data entry into accumulator A
                 inx             ; increment x
                 [b]; here I don’t know how to check for null byte[/]
    I suggest trying cmpa #0 or cmpa #$0

    I fail to see the code that copies the data to RAM.

    Quote Originally Posted by brad sue
    Code:
                 bne    repeat
    
                ; done copy data array
    
                ;now converting part:
                ; for value > 9 convert to 1 otherwise convert to 0
                ; special case for  space  character
    
         loop:
    
               ; case of space. Maybe misplace
               cmpy   #$20   ; compare with the  hex “space” value($20)
               sty       #$20
    I suggest looking up what the above instruction does; I think it would not compile. You are trying to store the value in the Y registor into a constant value of 20 hex.

    Quote Originally Posted by brad sue
    Code:
                ldy       0,x     ; get the data entry into Y register
               cmpy     #9     ; compare the current value> 9
               bls          L1    ; if not skip to L1
               sty          #0     ; if not store 0 into Y
    I suggest looking up what the above instruction does; I think it would not compile. You are trying to store the value in the Y registor into a constant value of 0 hex.

    Quote Originally Posted by brad sue
    Code:
          L1:
                sty       #1      ; store 1 into Y
                iny                 ; increment  Y   
                ;here don’t know how to check for the end of  x
                 bra       loop
    
                 bra        SECTION2
    
         SECTION2:
          ……..
    I'd appreciate your help.

    Thank you
    B.
    Last edited by stahta01; February 12th, 2008 at 11:41 AM. Reason: Forgot to Code Block it

  5. #5
    Join Date
    Feb 2008
    Posts
    2

    Re: Hcs12

    From http://en.wikipedia.org/wiki/HCS12#A..._of_the_68HC12

    The X and Y are still both 16 bit registers.

    Code:
               ldy       0,x     ; get the data entry into Y register
               cmpy     #9     ; compare the current value> 9
    That Y is 16 bit means the code above will not work right in my opinion.


    Tim S

    I would suggest using http://www.embeddedrelated.com/groups/68hc12/1.php for HCS12 Q/A.

  6. #6
    Join Date
    Nov 2005
    Posts
    79

    Re: Hcs12

    Thank you stahta01,
    I am actually rewriting the code. I hope I will do better. I tried the suggestion for a week but I have not had a response.

    I will post back when I have done.

  7. #7
    Join Date
    Nov 2005
    Posts
    79

    Re: Hcs12

    I have redone the program.

    It compiles but the case for the space case and I a bit not sure with the my use of load and store instructions.

    Code:
    ; Code Section Start
    Code:       SECTION
    Entry:
    main:
    ; Initialization
    ; Initialize stack pointer
                lds      #__SEG_END_SSTACK
                
                ldx      data
                ldy      NewData
     Loop:
                ldaa      1,x+            ; load value array in a
                cmpa     END_ARRAY        ;check if enf of array
                bne      space_sub
                bra      SECTION2         ;skip to section 2
     ;case space 
     space_sub:          
                cmpa     #$20
                bne      Number_sub        ;bne
                ldy      #$20
                sty      0,x
                iny
                bra      Loop
     Number_sub:
                
                cmpa     #$9
                bgt      Letter_sub
                ldy      #0
                sty      0,x
                iny
                bra      Loop
                
     Letter_sub:
             
                ;cmpa     #9
                ldy      #1 
                sty      0,x
                iny
                bra      Loop                     
     
                
     ;All done                 
                bra       *               ;spin here
    
    
    ;******************************************
    ; Constant data in ROM
    Const:      SECTION
     ;Constant data for section 1
    data:        DC.B     " On January 29 2008 there were 25 students"
                    DC.B     0
    
    ;******************************************
    ; Variable data in RAM
    Data:       SECTION
    NewData:     DS.B        TABLEN        ;table to fill
    
    
     SECTION2:
    Thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured