190 likes | 302 Views
IF ((x < y) and (z > t)) or (a <>b) then. Compiler Generated Code mov cl, 1 mov ax, x cmp ax, y jl istrue mov cl, 0 ; if false set cl =0 istrue: mov ax, z cmp ax, t jg andtrue mov cl, 0 ; if false set cl =0. IF ((x < y) and (z > t)) or (a <>b) then.
E N D
IF ((x < y) and (z > t)) or (a <>b) then • Compiler Generated Code mov cl, 1 mov ax, x cmp ax, y jl istrue mov cl, 0 ; if false set cl =0 istrue: mov ax, z cmp ax, t jg andtrue mov cl, 0 ; if false set cl =0 Lecture 27
IF ((x < y) and (z > t)) or (a <>b) then andtrue: mov al, a cmp al, b je orfalse mov cl, 1 ; if true set cl =1 orfalse: cmp cl,1 jne endif then: ……. ……. endif: Lecture 27
IF ((x < y) and (z > t)) or (a <>b) then • Optimized Code mov ax, a cmp ax, b jne then mov ax, x cmp ax, y jnl endif Lecture 27
IF ((x < y) and (z > t)) or (a <>b) then mov ax, z cmp ax, t jng endif then: ……… ……… endif: Lecture 27
If (a=b) then c=d else b=b+1 mov ax, a cmp ax, b jne else mov ax, d mov c, ax jmp endif else: inc b endif: IF THEN ELSE statement Lecture 27
While Loop • Do while (op1 < op2) • ……….. • ……….. • enddo Lecture 27
i = 0 while (i < 100) do i=i+1 mov i, 0 whilelp: cmp i, 100 jge whiledone inc i jmp whilelp whiledone: While Loop Lecture 27
do while (op1 < op2) Statement1 If (op2=op3) then Statement2 Statement3 else statement4 endif enddo whiledo: cmp op1, op2 jnl whiledone statement1 cmp op2, op3 jne else statement2 statement3 jmp endif If statement nested in a While Loop Lecture 27
do while (op1 < op2) Statement1 If (op2=op3) then Statement2 Statement3 else statement4 endif enddo else: statement4 endif: jmp whiledo whiledone: If statement nested in a While Loop Lecture 27
Repeat Loop • Repeat • Statement1 • Statmenet2 • Statement3 • Until (op1 = op2) Lecture 27
Repeat Statement1 Statement2 Statement3 Until (op1=op2) or (op1 > op3) repeat: Statement1 Statement2 Statement3 test1: cmp op1,op2 je endrepeat Repeat Loop Lecture 27
Repeat Statement1 Statement2 Statement3 Until (op1=op2) or (op1 > op3) test2: cmp op1,op3 jng repeat endrepeat: Repeat Loop Lecture 27
Case statement (switch) • Case I of • 0: statement1 • 1: statement2 • 2: statement3 • end Lecture 27
Case statement (switch) • if i=0 then statement1 • else if i=1 then statement2 • else if i=2 then statement3 Lecture 27
Case statement (switch) • mov bx, i • shl bx, 1 • jmp cs: jmptbl[bx] • jmptbl word stmt0, stmt1, stmt2 • stmt0: ……… • ……… • jmp endcase • stmt1: ……… • ……… • jmp endcase • stmt2: ……… • ……… • endcase: Lecture 27
Case I of 5: statement1 8: statement2 10: statement3 12: statement4 15: statement5 otherwise statement6 end mov bx, i cmp bx, 5 jl otherwise cmp bx, 15 jg otherwise shl bx, 1 jmp cs: jmptbl-10[bx] Non consecutive case Lecture 27
Non consecutive case • otherwise: • statement6 • jmp case done • jmptbl word stat1, otherwise, otherwise, stat2 • word otherwise, stat3, otherwise, stat4 • word otherwise, otherwise, stat5 Lecture 27
Case I of 0: statement1 1: statement2 2: statement3 100: statement4 otherwise statement5 end mov bx, i cmp bx, 100 je is100 cmp bx, 2 ja otherwise shl bx, 1 jmp cs:jmptabl[bx] Non consecutive case Lecture 27