• slider image 442
  • slider image 477
  • slider image 479
  • slider image 480
  • slider image 481
  • slider image 482
:::


Browsing this Thread:   1 Anonymous Users






Re: 關於IF ELSE ENDIF
#8
新會員
新會員


查看用戶資訊
我瞭解了
謝謝

發表於: 2004/6/14 18:26
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 關於IF ELSE ENDIF
#7
版主
版主


查看用戶資訊
1. 我想你可能誤會了 IF 的使用方式,你把這個 IF 當作C語言的 IF 來看待。
在組合語言中,if 屬於條件組譯,它是一種輔助用的虛指令,並不會產生任何程式碼。
然而在C語言中,if 是一種程式敘述(也可以硬說是指令)它會被翻譯成程式碼的。

2. 如果在組合語言(PIC)裡想要比較大小,基本上是要執行減法後,在去判斷 C & Z 旗號,
如只想知道是否相等只要在執行兩數相減後立即檢查Z旗號是否被設為1就可知道兩數是否相等。

3. 所以說,寫組合語言是很令人敬佩的,如果可以的話還是用C來寫會比較簡單。

發表於: 2004/6/14 16:59
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 關於IF ELSE ENDIF
#6
版主
版主


查看用戶資訊
if, els, endif是所謂的directive,不是真正的指令。它的動作在組譯的時候就已經做完了,不可能還能在程式執行的時候「動態」地去判讀PORTD。

version是常數,不是變數,當然watch不到。

PORTD 在.inc檔裏頭,被定義=8,自然一定執行一。

若想判斷PORTD,藉以執行不同的程式,可以類似用以下的程式:
MOVLW D'8' ;或其它值,如D'20'
XORWF PORTD,W
BTFSC STATUS,Z
GOTO PORTD_IS_8
PORTD_NOT_8:
........
PORTD_IS_8:
........

發表於: 2004/6/14 16:53
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 關於IF ELSE ENDIF
#5
新會員
新會員


查看用戶資訊
再請教
#define version 90 ;version定義為90,就不能在改變了

我用Watch看version
ADDRESS是空的
VALUE顯示Symbol Not Found
version是存放在何處

另外若我想判斷PORTD的值是否符合條件要如何做
movlw h'55'
movwf PORTD
if PORTD == 8 ;PORTD的ADDRESS
執行一
else
執行二
endif
結果是RUN 執行一


發表於: 2004/6/14 15:43
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 關於IF ELSE ENDIF
#4
版主
版主


查看用戶資訊
但執行結果卻都是執行IF 至 ELSE
不會執行ELSE 至 ENDIF

回答:
因為條件都成立,所以就不會執行else以後的組合語言了。

發表於: 2004/6/14 14:15
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 關於IF ELSE ENDIF
#3
版主
版主


查看用戶資訊
當欲使用條件式的組譯用來判斷事件是否成立,以控制 MPASM 的組譯流程時, 可利用 IF , ELSE , ENDIF
等這些條件判斷指令來達成

IF 的語法為 ;

IF <條件判斷>
{當條件成立(TRUE) 時則執行 IF 之下區塊之組譯}
ELSE
{用來處理當 IF 的條件不成立時(FALSE)的狀況}
ENDIF ; 用於結束 IF .. ELSE 的條件式組譯區塊 。

例如 :

#define Motor_Type 50
:
:
call Table_Read
:
:
Table_Read:
IF Motor_Type == 50
retlw 0xC0
ELSE
retlw 0x40
ENDIF

此時修改Motor_Type的值就會有不同的組譯結果。

發表於: 2004/6/14 14:11
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 關於IF ELSE ENDIF
#2
版主
版主


查看用戶資訊
可以啊!以下是我試的程式內容:

list p=16c57c
#include <p16c5x.inc>

#define version 90

org 0h
;
movlw b'00000000'
tris PORTB
;
if version == 100; check current version
movlw 0x55
movwf PORTB
else
movlw 0x0aa
movwf PORTB
endif
loop:
goto loop
end

發表於: 2004/6/14 11:37
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


關於IF ELSE ENDIF
#1
新會員
新會員


查看用戶資訊

請問IF ELSE ENDIF這虛指令是否可用
因為組譯時並沒有錯誤
但執行結果卻都是執行IF 至 ELSE
不會執行ELSE 至 ENDIF

發表於: 2004/6/12 10:48
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------