汇编语言-008(条件跳转应用 、loopnz 条件循环指令使用 、loopz 条件循环指令使用 、 if语句编写汇编时 、while语句编写汇编时 、循环内的if语句嵌套)
生活随笔
收集整理的這篇文章主要介紹了
汇编语言-008(条件跳转应用 、loopnz 条件循环指令使用 、loopz 条件循环指令使用 、 if语句编写汇编时 、while语句编写汇编时 、循环内的if语句嵌套)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1: 條件跳轉應用,三個數中最小數
.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 main2: 條件跳轉應用,循環直到按下按鍵
.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 main3: 條件跳轉應用,順序搜索數組
.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 main4: 條件跳轉應用,簡單字符串加密
.386 .model flat,stdcall.stack 4096 ExitProcess PROTO,dwExitCode:DWORDinclude Irvine32.incKEY = 239 BUFMAX = 128.data sPrompt BYTE "Enter the plain text:",0 sEncrypt BYTE "Cipher text: ",0 sDecrypt BYTE "Decrypted: ",0 buffer BYTE BUFMAX+1 DUP(0) bufSize DWORD ?.code main PROCcall InputTheStringcall TranslateBuffermov edx,OFFSET sEncryptcall DisplayMessagecall TranslateBuffermov edx,OFFSET sDecryptcall DisplayMessageINVOKE ExitProcess,0 main ENDP;提示用戶輸入一個純文本字符串 ;保存字符串和它的長度 ;接收:無 ;返回:無 InputTheString PROCpushadmov edx,OFFSET sPromptcall WriteStringmov ecx,BUFMAXmov edx,OFFSET buffercall ReadStringmov bufSize,eaxcall Crlfpopadret InputTheString ENDP;顯示加密或解密消息 ;接收:EDX指向消息 ;返回:無 DisplayMessage PROCpushadcall WriteStringmov edx,OFFSET buffercall WriteStringcall Crlfcall Crlfpopadret DisplayMessage ENDP;字符串的每個字符與密鑰字節進行異或實現轉換 ;接收:無 ;返回:無 TranslateBuffer PROCpushadmov ecx,bufSizemov esi,0 L1:xor buffer[esi],KEYinc esiloop L1popadret TranslateBuffer ENDP END main5: loopnz 條件循環指令使用,查找數組第一個非負數
.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 main6: 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 main7: 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 main8: 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 main9: while語句編寫匯編時的情況
.386 .model flat,stdcall.stack 4096 ExitProcess PROTO,dwExitCode:DWORD.data val1 DWORD 10 val2 DWORD 20;while (val1 < val2) ;{ ; val1 ++; ; val2 --; ;}.code main PROCmov eax,val1 beginwhile:cmp eax,val2jnl endwhileinc eaxdec val2jmp beginwhile endwhile:mov val1,eaxINVOKE ExitProcess,0 main ENDP END main10: 循環內的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 = ($ - 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總結
以上是生活随笔為你收集整理的汇编语言-008(条件跳转应用 、loopnz 条件循环指令使用 、loopz 条件循环指令使用 、 if语句编写汇编时 、while语句编写汇编时 、循环内的if语句嵌套)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 我们还能在一起吗剧情介绍
- 下一篇: 摩尔庄园农夫怎么升级