PLEASE COMMENT CODE AND TEST THAT IT WORKS:
Write a assembly program to find the largest item in an array and store it in a AX.
Hint: Use both Jump and loop instruction to write the program.
logic:
Assume that the first item of the array is the minimum and store it in AX
Write a loop. Inside the loop, compare the each array item with the AX
If the array item is less than the AX, update AX with that variable
USE THIS CODE TO START:
.386
.model flat,stdcall
.stack4096
ExitProcess proto,dwExitCode:dword
.data
Array WORD 10, 2, 23, 45, 21, 11
MINIMUM WORD ?
.code
"insert code here"
invoke ExitProcess,0
main endp
end main
// The code given below provides the min and max, both elements in the array...
// Assembly language program to read an array of numbers and find the minimal and maximal elements.
DATA SEGMENT
ARR DB 10, 2, 23, 45, 21, 11
LEN DW $-ARR
MIN DB?
MAX DB?
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA CS:CODE
START:
MOV AX,DATA
MOV DS,AX
LEA SI,ARR
MOV AL,ARR[SI]
MOV MIN,AL
MOV MAX,AL
MOV CX,LEN
REPEAT:
MOV AL,ARR[SI]
CMP MIN,AL
JL CHECKMAX
MOV MIN,AL
CHECKMAX:
CMP MAX,AL
JG DONE
MOV MAX,AL
DONE:
INC SI
LOOP REPEAT
MOV AH,4CH
INT 21H
CODE ENDS
END START
Get Answers For Free
Most questions answered within 1 hours.