用匯編語言解釋if語句
假如c語言程序如下:
short a=1;
if (a>1) {
//do sth No.1
} else if (a==1) {
//do sth No.2
} else if (a<1) {
//do sth No.3
}
答案應該是這樣的
MOV AX,A
CMP AX,1
JNZ NO1;不等于1
;等于1的程序段
JMP OUT
NO1:CMP AX,1
JL XIAOYU
;大于1的程序段
JMP OUT
XIAOYU: ;小于1的程序段
OUT:
用匯編語言解釋if語句
假如c語言程序如下:
short a=1;
if (a>1) {
//do sth No.1
} else if (a==1) {
//do sth No.2
} else if (a<1) {
//do sth No.3
}
答案應該是這樣的
MOV AX,A
CMP AX,1
JNZ NO1;不等于1
;等于1的程序段
JMP OUT
NO1:CMP AX,1
JL XIAOYU
;大于1的程序段
JMP OUT
XIAOYU: ;小于1的程序段
OUT:
匯編語言怎樣表示像C語言一樣的if else選擇語句
匯編語言中沒有專門的類似if else的語句或指令,程序的調整條件一般圍繞以“位”來控制的。這些“位”都在狀態寄存器PSW中。舉例說明:
比如C語言中:
if(a>b)x=1;
else x=2;
用匯編來實現如下:
cjne a,b,cont //判斷a,b是否相等
cont:
jc small //小于轉samll
mov x,2 //大于等于處理
ret
small:
mov x,1 //小于處理
ret
用ARM匯編語言程序段實現下面的if語句.
ADR r4,a; 讀取變量a的地址LDR r0,[r4]; 讀變量a的內容到r0ADR r4,b; 讀取變量b的地址LDR r1,[r4]; 讀變量b的內容到r1CMP r0,r1;BGE fblock; 如果a>=b,跳轉到fblockADR r4,x;MOV r0,#5;STR r0,[r4]; 令x=5ADR r4,c; 讀取變量c的地址LDR r0,[r4]; 讀變量c的內容到r0ADR r4,d; 讀取變量d的地址LDR r1,[r4]; 讀變量d的內容到r1ADD r0,r0,r1;ADR r4,y; 讀取變量y的地址STR r0,[r4];B after;fblock: ADR r4,c ;讀取變量c的地址 LDR r0,[r4] ;讀c的內容到r0 ADR r4,d ;讀取變量d的地址到r4 LDR rl,[r4] ;讀變量d的內容到r1 SUB r0,r0,rl ;計算a – b 結果保存在r0 ADR r4,x ;讀取變量x的地址 STR r0,[r4] after:。
匯編語言偽指令 “ if ” 和 “ .if ” 有什么區別
Syntax: .IF condition ifstatements [.ELSEIF] condition elseifstatements . . . [.ELSE] elsestatements .ENDIF For "condition" see Comparison run-time operators Description: Used for clear coding of common control-flow blocks. Generates comparison and conditional jump instructions so that if is true, the processor executes the instructions following .IF until the next .ELSEIF, .ELSE, or .ENDIF. .IF statements can be nested. The .ELSEIF statement is used to create a code block that is executed if the preceding .IF and .ELSEIF conditions are false, and the current .ELSEIF condition is true. There can be several .ELSEIF blocks within a .IF block. The .ELSEIF statement performs the same function as a .IF inside a .ELSE but does not create another nesting level of .IFs. .ELSE specifies an alternate code block if the matching .IF and previous .ELSEIF expressions are false. .ENDIF closes the current .IF, .ELSEIF, or .ELSE code block. The assembler optimizes to get the best possible code. For example, .IF ax==0 performs the comparison with: or ax,ax which is more efficient than: cmp ax, 0 ================================================================= Syntax: IF cond expression ifstatements [ELSEIF] cond expression elseifstatements - - - [ELSE] elsestatements ENDIF Description: The IF block format can be used to create a source file that will generate a variety of programs, depending on constants or environment variables. For example, you can create a single source file that generates code for different memory models and operating environments. IF blocks can be nested up to 20 levels but cannot span include files or structure, union, or macro definitions. The statements following the ELSE directive are assembled only if the preceding IF directive was found to be false (zero). Only one ELSE statement is allowed in each IF block, although there can be several ELSEIF statements. IFcond is one of the conditional assembly directives beginning with "IF" (such as IF, IFE, and IFB). There is an optional ELSEIFcond corresponding to each IFcond. The , , and are each a series of one or more assembly-code statements. The respective conditions determine which block is assembled, if any. The ELSE and ELSEIF blocks are optional. =========================================================== 帶點的if和高級語言中的if一樣,不帶點的if好像是條件編譯。
用ARM匯編語言程序段實現下面的if語句.
ADR r4,a; 讀取變量a的地址
LDR r0,[r4]; 讀變量a的內容到r0
ADR r4,b; 讀取變量b的地址
LDR r1,[r4]; 讀變量b的內容到r1
CMP r0,r1;
BGE fblock; 如果a>=b,跳轉到fblock
ADR r4,x;
MOV r0,#5;
STR r0,[r4]; 令x=5
ADR r4,c; 讀取變量c的地址
LDR r0,[r4]; 讀變量c的內容到r0
ADR r4,d; 讀取變量d的地址
LDR r1,[r4]; 讀變量d的內容到r1
ADD r0,r0,r1;
ADR r4,y; 讀取變量y的地址
STR r0,[r4];
B after;
fblock: ADR r4,c ;讀取變量c的地址
LDR r0,[r4] ;讀c的內容到r0
ADR r4,d ;讀取變量d的地址到r4
LDR rl,[r4] ;讀變量d的內容到r1
SUB r0,r0,rl ;計算a – b 結果保存在r0
ADR r4,x ;讀取變量x的地址
STR r0,[r4]
after:。