Finding Smallest and Largest number from an Array in Assembly
Objective:
To enhance knowledge about how to write assembly program using branching.
Problem Statements:
- Write an assembly language program to find the smallest number from an array of following ten numbers. Explain each instruction of program and also provide/paste snapshot of your assemble and debug program result which will be run in AFD (A Full Screen Debugger) window showing the executed code final results in AX register.
Numbers : 20, 50, 30, 14, 19, 3, 5, 6, 40, 8
- Write an assembly language program to find the largest number from an array of following ten numbers. Explain each instruction of program and also provide/paste snapshot of your assemble and debug program result which will be run in AFD (A Full Screen Debugger) window showing the executed code final results in AX register.
Numbers : 10, 40, 20, 14, 19, 13, 50, 6, 60, 14
Solutions:
For Smaller numbers:
[ORG 100h] JMP START Num: DW 20, 50, 30, 14, 19, 3, 5, 6, 40, 8 L2: MOV AX, SI ; Save Small number in AX ADD BX, 2 ; bx +=2; Point to next character RET START: MOV BX, 0 MOV AX, 0 MOV AX, [Num + BX] MOV CX, 10 L1: CMP AX , [Num + BX] JLE L3 MOV AX, [Num + BX] ; AX contains Minimum number L3: ADD BX, 2 Loop L1 ; Poinyt next Numbetr MOV AX, 0x4c00 INT 0x21
Screenshot:
For Smaller numbers:
[ORG 100h] JMP START NUM: DW 10, 40, 20, 14, 19, 13, 50, 6, 60, 14 Result: DW 0 L2: MOV AX, SI ADD BX, 20 RET START: MOV AX, 0 MOV BX, 0 MOV AX, [NUM + BX] MOV CX, 10 L1 CMP AX, [NUM + BX] JGE L3 MOV AX, [NUM + BX] L3 ADD BX, 2 Loop L1 MOV [Result], AH MOV AX, [Result] MOV AX, 0X4C00 INT 0X21
Screenshot:
No comments: