欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

32位汇编语言 在一段数组中找最大数 x86 汇编语言 asm文件 irvine32 intel 汇编语言

程序员文章站 2024-02-02 16:02:46
...

题目:

Create a procedure named FindLargest that receives two parameters: a pointer to a signed doubleword array, and a count of the array’s length. The procedure must return the value of the largest array member in EAX. Use the PROC directive with a parameter list when declaring the procedure. Preserve all registers(except EAX) that are modified by the procedure. Write a test program that calls FindLargest and passes three different arrays of different lengths. Besure to include negative values in your arrays. Create a PROTO declaration for FindLargest.
创建一个名为FindLargest的过程,该过程接收两个参数:指向有符号双字数组的指针和数组长度的计数。该过程必须返回EAX中最大数组成员的值。在声明过程时,将PROC指令与参数列表一起使用。保留由过程修改的所有寄存器(EAX除外)。编写一个测试程序,调用FindLargest并传递三个不同长度的数组。请确保在数组中包含负值。为FindLargest创建PROTO声明。

代码:

; author: BoPang 
; email: 1275189619@qq.com
; 2021/7/11
include Irvine32.inc 
 FIndLargest PROTO,  pArray: ptr SDWORD, 
   arrayLength: DWORD
 .data 
 Array SDWORD 5, 3, -2, 4, 8
 ;arrayLength DWORD 5
 .code 

 main PROC  
 INVOKE FindLargest, ADDR Array, lengthof Array-1
 call WriteDec
 exit
   main ENDP 

   FindLargest PROC,
   pArray: ptr SDWORD, 
   arrayLength: DWORD
   push esi
   push ecx
   ;dec arrayLength
   mov ecx, arrayLength
   mov esi, pArray
   mov eax, [esi]
   ADD esi,4
   L1:
   mov ebx,[esi]
   cmp eax, ebx;[esi]
   jge A1
   mov eax, ebx;[esi]
   A1:
   add esi,4
   loop L1
   pop ecx
   pop esi
   ret
   FindLargest ENDP
  END main 

初学汇编语言,如有错误请多指正!