参考资料
数组找最大值
从键盘输入10个数据,存入一维数组中,并求出该数组中最大的数并显示在屏幕上。
.386 .MODEL FLAT
ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD
INCLUDE io.h
cr EQU 0dh Lf EQU 0ah
.STACK 4096 .DATA intro1 BYTE 'this program will tell you the max which is in you input',cr,Lf BYTE 'please input numbers: ',0 intro2 BYTE 'next:',0 numArr DWORD 20 dup (?) numElts DWORD 20 dup (?) midnum DWORD 20 dup (?) maxnum DWORD 20 dup (?) .CODE _start: output intro1 mov numElts,0 mov maxnum,0 lea ebx,numArr whilePos: input midnum,20 atod midnum mov [ebx],eax cmp maxnum,eax jle setmax jmp asusual setmax: mov maxnum,eax asusual: inc numElts cmp numElts,10 jge endWhile add ebx,4 output intro2 jmp whilePos endWhile: mov eax, maxnum dtoa maxnum,eax output maxnum
INVOKE ExitProcess, 0 PUBLIC _start
END
|
统计平均值
从键盘输入15个数据,存入一维数组中,统计其中大于平均值的数据并显示在屏幕上。
.386 .MODEL FLAT
ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD
INCLUDE io.h
cr EQU 0dh Lf EQU 0ah
.STACK 4096
.DATA string1 BYTE "please input fifteen numbers: ",cr,Lf,0 string2 BYTE "the avg: " avg BYTE 20 DUP(?) outend BYTE cr,Lf,0 string3 BYTE "the result:",cr,Lf,0
number BYTE 20 DUP(?) array DWORD 20 DUP(?) eltsit DWORD 20 DUP(?) outValue BYTE 11 DUP(?),cr,Lf,0
.CODE _start: output string1 lea ebx,array whiles: input number,20 atod number mov [ebx],eax inc Eltsit cmp Eltsit,15 jge whileed add ebx,4 jmp whiles whileed: mov eax,0 lea ebx,array mov ecx,eltsit forsum: add eax,[ebx] add ebx,4 loop forsum
cdq idiv eltsit lea ebx,array mov ecx,eltsit dtoa avg,eax output string2 output outend output string3 forupsum: cmp [ebx],eax jng endfor dtoa outValue,[ebx] output outValue endfor: add ebx,4 loop forupsum
INVOKE ExitProcess, 0 PUBLIC _start
END
|
统计奇数偶数
从键盘输入一组数据,存入一维数组中(要求数组的数据占据一个字的空间),统计偶数和奇数并分别显示在屏幕上。
.386 .MODEL FLAT
ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD
INCLUDE io.h
cr EQU 0dh Lf EQU 0ah
.STACK 4096
.DATA string1 BYTE "please input numbers: (input # to end)",cr,Lf,0 number WORD 20 DUP(?) array WORD 100 DUP(?) eltsit DWORD 20 DUP(?) eltsit2 DWORD 20 DUP(?) num DWORD 2 midnum DWORD 20 DUP(?) outodd DWORD 20 DUP(?),0 string3 BYTE "is odd numbers:" string4 BYTE "is even numbers:",cr,Lf,0 endall BYTE cr,Lf,0
.CODE _start: output string1 lea ebx,array mov eltsit,0
whiles: input number,11 cmp number,'#' je whileed atod number mov [ebx],eax inc eltsit add ebx,4 jmp whiles whileed: lea ebx,array output string3
forjudge1: mov eax,[ebx] mov edx,0 idiv num cmp edx,1 je odd1 jmp endodd1 odd1: mov edx,[ebx] dtoa midnum,edx output midnum endodd1: add ebx,4 dec eltsit inc eltsit2 cmp eltsit,0 je judgeed1 jmp forjudge1 judgeed1: output endall output string4 lea ebx,array forjudge: mov eax,[ebx] mov edx,0 idiv num cmp edx,0 je odd jmp endodd odd: mov edx,[ebx] dtoa midnum,edx output midnum endodd: add ebx,4 dec eltsit2 cmp eltsit2,0 je judgeed jmp forjudge judgeed: output endall INVOKE ExitProcess, 0 PUBLIC _start
END
|
栈输入输出数据
从键盘输入一组数据,按照输入的倒叙显示这一组数组在屏幕上(利用堆栈完成)。
例如:输入 4,-30 ,5,6
显示:6,5,-30,4
.386 .MODEL FLAT
ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD
INCLUDE io.h
cr EQU 0dh Lf EQU 0ah
.STACK 4096
.DATA allnum WORD 20 dup (?),0 num1 WORD 20 dup (?),0 num2 WORD 20 dup (?),Lf,0 .CODE _start:
mov allnum,0 sectorA: input num1,20 cmp num1,'#' je sectorB atod num1 push eax inc allnum jmp sectorA sectorB: pop ebx dtoa num2,ebx output num2 dec allnum cmp allnum,0 je sectorBend jmp sectorB sectorBend:
INVOKE ExitProcess, 0 PUBLIC _start
END
|
杨辉三角
从键盘输入一个数据,显示输出该数据行数的‘*’图形。
例如: 输入3,输出三行杨辉三角
.386 .MODEL FLAT
ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD
INCLUDE io.h
cr EQU 0dh Lf EQU 0ah
.STACK 4096
.DATA star BYTE 42,0 konge2 BYTE 32,0 num1 BYTE 13 dup (?) cont DWORD 4 dup (?) endall BYTE cr,LF,0 .CODE _start: input num1,13 atod num1 mov ecx,eax dec eax mov edx,1 loopp: mov ebx,edx mov cont,eax sectorD: cmp cont,0 je sectorB output konge2 dec cont jmp sectorD sectorB: cmp ebx,0 je sectorA output star dec ebx jmp sectorB sectorA: output endall dec eax add edx,2 loop loopp
INVOKE ExitProcess, 0 PUBLIC _start
END
|