簡體   English   中英

ARM Assembly:如何為執行一條指令設置多個比較?

[英]ARM Assembly: How to set more than one comparing for executing a instruction?

我嘗試將此代碼更改為ARM而不使用Jump指令:

if a == 0 || b == 1 then c:=10  else c:=20;

if d == 0 && e == 1 then f:=30  else c:=40;

我這樣做是為了進行fisrt循環。 但是我不確定。 是真的嗎

CMP r0, #0    ; compare if a=0
CMP r1, #1    ; compare if b=0
MOVEQ r3, #10
MOVNE r3, #20

第二個怎么辦?

if a == 0 || b == 1 then c:=10  else c:=20;

您要在此處做的是比較條件的一部分。 如果該部分為真,則整個條件為真,因為x OR y為真,只要xy中的至少一個為真即可。 如果第一部分為假,則計算第二部分。 這樣就變成:

CMP r0, #0      ; compare a with 0
CMPNE r1, #1    ; compare b with 1 if a!=0
MOVEQ r3, #10   ; a is 0, and/or b is 1 -> set c = 10
MOVNE r3, #20   ; a is not 0, and b is not 1 -> set c = 20

if d == 0 && e == 1 then f:=30  else c:=40;

在這里,您要計算條件的一​​部分,然后僅在第一部分為真時才計算第二部分。 如果兩個部分都為真,則整個條件為真,否則為假:

CMP r0, #0      ; compare d with 0
CMPEQ r1, #1    ; compare e with 1 if d==0
MOVEQ r3, #30   ; d is 0, and e is 1 -> set f = 30
MOVNE r3, #40   ; d isn't 0, and/or e isn't 1 -> set f = 40

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM