.386 .model flat,stdcall.stack 4096 ExitProcess PROTO,dwExitCode:DWORD.data V1 WORD 1 V2 WORD 2 V3 WORD 3.code main PROCmov ax,V1 ;假设V1是最小值cmp ax,V2 ;如果AX小于等于V2jbe L1mov ax,v2 L1:cmp ax,V3jbe L2mov ax,V3 L2:INVOKE ExitProcess,0 main ENDP END main
2: 条件跳转应用,循环直到按下按键
.386 .model flat,stdcallinclude Irvine32.inc.stack 4096 ExitProcess PROTO,dwExitCode:DWORD.data char BYTE ?.code main PROCL1:mov eax,10call Delay ;10毫秒的延迟call ReadKey ;检查按键jz L1 ;如果没有按键就循环mov char,AL ;保存字符INVOKE ExitProcess,0 main ENDP END main
3: 条件跳转应用,顺序搜索数组
.386 .model flat,stdcallinclude Irvine32.inc.stack 4096 ExitProcess PROTO,dwExitCode:DWORD.data intArray SWORD 0,0,0,0,1,20,35,-12,66,4,0 noneMsg BYTE "A non-zero value was not found",0.code main PROCmov ebx,OFFSET intArraymov ecx,LENGTHOF intArray L1:cmp WORD PTR[ebx],0jnz foundadd ebx,2loop L1jmp notFound found:movsx eax,WORD PTR[ebx]call WriteIntjmp quit notFound:mov edx,OFFSET noneMsgcall WriteString quit:call CrlfINVOKE ExitProcess,0 main ENDP END main
.386 .model flat,stdcall.stack 4096 ExitProcess PROTO,dwExitCode:DWORD.data array SWORD -3,-6,-1,-10,10,30,40,4 sentinel SWORD 0.code main PROCmov esi,OFFSET arraymov ecx,LENGTHOF array L1:test WORD PTR[esi],8000h ;测试符号位pushfd ;标志位入栈add esi,TYPE array ;移动到下一个位置popfdloopnz L1 ;当ZF=0时继续循环 jnz quit ;没有发现非负数sub esi,TYPE array ;ESI指向数值 quit:INVOKE ExitProcess,0main ENDP END main
6: loopz 条件循环指令使用,查找数组第一个负数
.386 .model flat,stdcall.stack 4096 ExitProcess PROTO,dwExitCode:DWORD.data array SWORD 3,6,1,10,-10,-30,-40,-4 sentinel SWORD 0.code main PROCmov esi,OFFSET arraymov ecx,LENGTHOF array L1:test WORD PTR[esi],8000h ;测试符号位pushfd ;标志位入栈add esi,TYPE array ;移动到下一个位置popfdloopz L1 ;当ZF=1时继续循环 jz quit ;没有发现非负数sub esi,TYPE array ;ESI指向数值 quit:INVOKE ExitProcess,0main ENDP END main
7: if语句编写汇编时的情况
.386 .model flat,stdcall.stack 4096 ExitProcess PROTO,dwExitCode:DWORD;if(al > bl)&(bl > cl) ; X =1.data X DWORD ?.code main PROCINVOKE ExitProcess,0 main ENDPproc_1 PROCcmp al,blja L1jmp nextL1:cmp bl,clja L2jmp nextL2:mov X,1next: proc_1 ENDP;如果将ja 换成 jbe,代码减少2条 proc_2 PROCcmp al,bljbe nextcmp bl,cljbe nextmov X,1next:proc_2 ENDPEND main
8: if语句编写汇编时的情况
.386 .model flat,stdcall.stack 4096 ExitProcess PROTO,dwExitCode:DWORD.data X DWORD ?;if(al > bl)||(bl > cl) ;X =1.code main PROCcmp al,blja L1cmp bl,cljbe next L1: mov X,1 next:INVOKE ExitProcess,0 main ENDP END main
9: while语句编写汇编时的情况
.386 .model flat,stdcall.stack 4096 ExitProcess PROTO,dwExitCode:DWORD.data val1 DWORD 10 val2 DWORD 20;while(val1 < val2) ;{ ; val1 &#43;&#43;; ; val2 --; ;}.code main PROCmov eax,val1 beginwhile:cmp eax,val2jnl endwhileinc eaxdec val2jmp beginwhile endwhile:mov val1,eaxINVOKE ExitProcess,0 main ENDP END main
10&#xff1a; 循环内的if语句嵌套
.386 .model flat,stdcall.stack 4096 ExitProcess PROTO,dwExitCode:DWORD.data sum DWORD 0 sample DWORD 50;计算数组所有大于sample的数之和 array DWORD 10,60,20,33,72,89,45,72,18 arraySize &#61;($ - array)/TYPE array.code main PROCmov eax,0mov edx,samplemov esi,0mov ecx,arraySize L1:cmp esi,ecxjl L2jmp L5 L2:cmp array[esi*4],edxjg L3jmp L4 L3:add eax,array[esi*4] L4:inc esijmp L1 L5:mov sum,eaxINVOKE ExitProcess,0 main ENDP END main