disp proc push ebx push ecx mov ecx,8 ; 8λ dhw1: rol eax,4 mov ebx,eax and al,0fh ; ת»»ÎªASCIIÂë add al,30h cmp al,'9' jbe dhw2 add al,7
dhw2: call dispc mov eax,ebx loop dhw1 pop ecx pop ebx ret disp endp
£¨2£© ; Êý¾Ý¶Î
wvar word 307281AFH temp word ? ; ´úÂë¶Î£¬Ö÷³ÌÐò mov eax,wvar mov temp,eax call disp mov al,'H' call dispc ; ´úÂë¶Î£¬×Ó³ÌÐò disp proc push ebx push ecx mov ecx,8 ; 8λ mov eax,temp dhw1: rol eax,4 mov ebx,eax and al,0fh ; ת»»ÎªASCIIÂë add al,30h cmp al,'9' jbe dhw2 add al,7
dhw2: call dispc ; ÏÔʾһ¸ö×Ö·û mov eax,ebx loop dhw1 pop ecx pop ebx ret
disp endp £¨3£© ; Êý¾Ý¶Î
wvar word 307281AFH ; ´úÂë¶Î£¬Ö÷³ÌÐò push wvar call disp add esp,4 mov al,'H' call dispc ; ´úÂë¶Î£¬×Ó³ÌÐò disp proc push ebp mov ebp,esp push ebx push ecx mov ecx,8 ; 8λ mov eax,[ebp+8] dhw1: rol eax,4 mov ebx,eax and al,0fh ; ת»»ÎªASCIIÂë add al,30h cmp al,'9' jbe dhw2 add al,7
dhw2: call dispc mov eax,ebx loop dhw1 pop ecx pop ebx pop ebp ret disp endp
¡²Ï°Ìâ4.27¡³
ÅäºÏÀýÌâ4-11µÄ¼òµ¥¼ÓÃܽâÃܳÌÐò£¬Éè¼ÆÒ»¸öÊäÈëÃÜÂëµÄ³ÌÐò£¬½«ÊäÈëµÄÈô¸É×Ö·û¾¹ýÊʵ±Ëã·¨µÃµ½Ò»¸ö×Ö½ÚÁ¿ÃÜÂë¡£ ¡²½â´ð¡³ ;ex0427.asm include io32.inc .data key byte ?
msg0 byte 'Enter your password:',0 passw byte 50 dup(0)
errormsg byte 'Password error, input again!',13,10,0 bufnum = 255
buffer byte bufnum+1 dup(0) ; ¶¨Òå¼üÅÌÊäÈëÐèÒªµÄ»º³åÇø msg1 byte 'Enter messge: ',0
msg2 byte 'Encrypted message: ',0
msg3 byte 'Original messge: ',0 .code start: mov eax,offset msg0 ; ÌáʾÊäÈë¼ÓÃÜÃÜÂë call dispmsg mov eax,offset passw ; ÉèÖÃÈë¿Ú²ÎÊýEAX call readmsg ; µ÷ÓÃÊäÈë×Ö·û´®×Ó³ÌÐòÊäÈëÃÜÂë mov ecx,eax dec ecx xor ebx,ebx mov al,passw[ebx] again0: inc ebx xor al,passw[ebx] ;ʹÓüòµ¥µÄÒì»ò·½·¨µÃµ½¼ÓÃܹؼü×Ö loop again0 mov key,al ; ±£´æ¼ÓÃܹؼü×Ö mov eax,offset msg1 ; ÌáʾÊäÈë×Ö·û´® call dispmsg mov eax,offset buffer ; ÉèÖÃÈë¿Ú²ÎÊýEAX call readmsg ; µ÷ÓÃÊäÈë×Ö·û´®×Ó³ÌÐò push eax ; ×Ö·û¸öÊý±£´æ½øÈë¶ÑÕ» mov ecx,eax ; ECX£½Êµ¼ÊÊäÈëµÄ×Ö·û¸öÊý£¬×÷Ϊѻ·µÄ´ÎÊý xor ebx,ebx ; EBXÖ¸ÏòÊäÈë×Ö·û encrypt: mov al,key ; AL£½¼ÓÃܹؼü×Ö xor buffer[ebx],al ; Òì»ò¼ÓÃÜ inc ebx dec ecx ; µÈͬÓÚÖ¸Áloop encrypt jnz encrypt ; ´¦ÀíÏÂÒ»¸ö×Ö·û mov eax,offset msg2 call dispmsg mov eax,offset buffer ; ÏÔʾ¼ÓÃܺóµÄÃÜÎÄ call dispmsg call dispcrlf ;
again: mov eax,offset msg0 ; ÌáʾÊäÈë½âÃÜÃÜÂë call dispmsg mov eax,offset passw ; ÉèÖÃÈë¿Ú²ÎÊýEAX call readmsg ; µ÷ÓÃÊäÈë×Ö·û´®×Ó³ÌÐòÊäÈëÃÜÂë mov ecx,eax dec ecx xor ebx,ebx mov al,passw[ebx] again1: inc ebx xor al,passw[ebx] ;ʹÓüòµ¥µÄÒì»ò·½·¨µÃµ½¼ÓÃܹؼü×Ö loop again1 cmp key,al ; ÓëÔ¼ÓÃܹؼü×Ö±È½Ï jz next ; ÃÜÂëÏàͬ£¬Ôò½øÐнâÃÜ mov eax,offset errormsg ; ÌáʾÊäÈë½âÃÜÃÜÂë´íÎó
call dispmsg jmp again
next: pop ecx ; ´Ó¶ÑÕ»µ¯³ö×Ö·û¸öÊý£¬×÷Ϊѻ·µÄ´ÎÊý xor ebx,ebx ; EBXÖ¸ÏòÊäÈë×Ö·û decrypt: mov al,key ; AL£½½âÃܹؼü×Ö xor buffer[ebx],al ; Òì»ò½âÃÜ inc ebx dec ecx jnz decrypt ; ´¦ÀíÏÂÒ»¸ö×Ö·û mov eax,offset msg3 call dispmsg mov eax,offset buffer ; ÏÔʾ½âÃܺóµÄÃ÷ÎÄ call dispmsg ¡²Ï°Ìâ4.28¡³
Éè¼ÆÒ»¸ö¼òµ¥µÄÁ½¸öÕûÊýµÄ¼Ó·¨Æ÷³ÌÐò¡£ ¡²½â´ð¡³ ;ex0428.asm include io32.inc .data
msg1 byte 'Enter the integers:',13,10,0
msg2 byte 13,10,'Enter space to continue! Enter any other key to exit!',13,10,0 .code start: mov eax,offset msg1 call dispmsg call readsid mov ebx,eax mov al,'+' call dispc call dispcrlf call readsid add ebx,eax mov al,'=' call dispc mov eax,ebx call dispsid call dispcrlf mov eax,offset msg2 call dispmsg call readc cmp al,20h je start exit 0