加强题(一)
include irvine32.inc
.data
dat dword -5,-7,8,4,-8,-6,0,1
max dword ?
flag byte '0'
.code
main proc
call find
mov eax, max
call writeint ;输出最小负偶数
call crlf
lea edx,flag
call writestring ;输出flag的值
exit
main endp
;find子过程
find proc
xor esi,esi
xor edx,edx
mov ecx,lengthof dat
again:
mov ebx, dat[esi*type dat]
cmp ebx,0
jge next ;判断是否<0
mov eax,ebx
and ebx, 01h
cmp ebx,0
jne next ;判断是否为偶数
inc edx
cmp edx,1
ja next1
mov max,eax ;找到第一个负偶数,赋值给max
next1:
cmp eax, max
jle next
mov max,eax
mov flag,'1'
next:
inc esi
loop again
ret
find endp
end main
此类题最好先写一个c++程序,如下
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a[5]={-5,-7,8,4,-8,-6,0,1};
int max,counter=0;
for(int i=0;i<5;i++)
{
if(a[i]<0)
{
if(!(a[i]&1))
{
counter++;
if(counter==1) max=a[i];
if(a[i]>max&&counter>1) max=a[i];
}
}
}
cout<<max;
}