MC9S08KA2 - Programming

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

MC9S08KA2 - Programming

2,008件の閲覧回数
amit_kumar
Contributor I
I am new to asm programming.
Can anyone tell the asm code for following pseudo code.
 
I am using PORT 0, and PORT 1 as digital  i/p.
the trying ti write some condiitions ..
If(PORT_0 == 1 && PORT_1 == 0)
{
      DO SOMETHING
}
ELSEIF(PORT_0 == && PORT_1 == 0)
{
     DO SOMETHING
}
ELSE(PORT_0 ==  0 && PORT_1 == 1)
{
      DO SOMETHING
}
 
I want to use IF - ELSE in my code, if there is any instruction for this then kindly answer me.
or tell me syntax to use IF - ELSE loop
 
kindly, try to answer urgently.
thanks. 
ラベル(1)
0 件の賞賛
返信
4 返答(返信)

662件の閲覧回数
amit_kumar
Contributor I
Thanx Peg !!
It really good to use this trick rather than trying BRSET, BRCLR that i was trying before.
 
but still I am searching for IF else loop because somewher i found that.
MODE : equ 0
IFNE MODE
---do something
ELSE
 do something
 
anyway, still i am happy to use above trick given by u.
thank u once again !!
 
Regards,
Amit
0 件の賞賛
返信

662件の閲覧回数
bigmac
Specialist III
Hello,


amit.kumar wrote:
 
but still I am searching for IF else loop because somewher i found that.
MODE : equ 0
IFNE MODE
---do something
ELSE
 do something
 

I think what you may have previously observed are called "conditional assembly" directives.  These directives tell the assembler/compiler to assemble one block of code, or alternatively another block of code in place of the first block, depending on the value of a control parameter.  This has nothing to do with branching operations within the assembled code.
 
Yet another possibility, to that outlined by Peg, is to make use of the CBEQ instruction.
   lda    PORT             ; Read current input port status
      and    #%00000011       ; Mask bits to be tested
     cbeqa  #%00000011,lab1  ; Branch if first value
      cbeqa  #%00000001,lab2  ; Branch if second value
    ; Default case:
     ...
      bra    continue
lab1: ; First value code:
     ...
      bra    continue
lab2: ; Second value code:
     ...
continue:
     ; Further code here
Regards,
Mac


Message Edited by bigmac on 2008-03-10 01:22 AM
0 件の賞賛
返信

662件の閲覧回数
peg
Senior Contributor IV
Hi again amit.kumar,

If you have seen if-else structures then its not truly assembler put some form of high level language or use of macros etc.
Assembler is simply using mnemonics to represent the opcodes from the set given in the processor core manual. In this case HCS08RMV1.pdf.
So the only options you have are given in this document.
Various assemblers will allow different directives but that is about it.
Anything else is compiled down to machine code which has a 1 to 1 relationship with assembly, so whatever you use you end up basically with it anyway.
The method I have shown is basically the same layout and just as readable as a C switch statement anyway.
Of course when you need to use complex BRSET/BRCLR combinations to get the job done the ability to quickly analyse the programme flow for a given set of input values quickly goes out the window.
Hope that helps

0 件の賞賛
返信

662件の閲覧回数
peg
Senior Contributor IV
Hello and welcome to the forums amit.kumar,

Firstly, if you make a mistake like an empty posting you can just go and edit it if you do it within an hour or so.

Now to your question.
First I presume you are testing bits 0 and 1 of the same port.
You can do it with an ugly combination of BRSET's and BRCLR's
or you can do it like I show below.
Code:
      lda    PORT             ;get current input port status      and    #%00000011       ;mask out irrelevant bits      bne    lab1             ;branch if other than 00      do something when 00
      bra    lab3

lab1  cmp    #%00000001       ;test for bit 0 only on      bne    lab2             ;branch if not so      do something when 01      bra    lab3
lab2  cmp    #%00000010       ;test for bit 1 only on      bne    lab3             ;branch if not so      do something when 10lab3  .....

 

0 件の賞賛
返信