Please use x86 Assembly Language (use 32-bit Visual Studio) 1.(5 points) Write a
ID: 3740798 • Letter: P
Question
Please use x86 Assembly Language (use 32-bit Visual Studio)
1.(5 points) Write an assembly program to find the smallest element by searching an array
int ary[] = {11,15,-3,-4, 0, 60,11,-1,18,-4,-6, 9,-20}
int index = 0;
int min = ary[0];
int arraySize = sizeof array / sizeof min
while (index < arraySize) {
if (ary[index] < min)
min = ary[index];
}
- Do not use loop instruction.
Make sure you understand what int represent in C and assembly language.
- Also, make sure that variables declared and defined in C has to be in the .data section in assembly
- Use cmp instruction and the appropriate jump instruction (signed or unsigned) to translate the if and while statements.
- Use $ operator (see chapter 3) to calculate the size of the array.
- Run your program using the debugger to verify your answers.
Explanation / Answer
The code would be
.model tiny
.386
.data
arr dd 11,15,-3,-4, 0, 60,11,-1,18,-4,-6, 9,-20,'$'
min dd ?
.code
.startup
lea si,arr
cld
mov ebx,[arr]
mov min,ebx
x1: lodsd
cmp eax,'$'
je x2
cmp eax,min
jge x1
mov min,eax
jmp x1
x2:
.exit
end
Do give a thumbs up