Back to the 2025 paper

Module 3: Instruction Set and Programming

20257m

Write a program to find the largest number in an array using 8051 assembly language.

Worked SolutionAI Assisted

Program to Find Largest Number in Array (8051 Assembly)

ORG 0000H
MOV R0,#30H   ; array start 30H
MOV R1,#08H   ; count 8 example (adjust)
MOV A,@R0
MOV B,A       ; B holds max
INC R0
DEC R1
LOOP: MOV A,@R0
      CJNE A,B,NEXT ; compare
NEXT: JNC SKIP ; if A >= B (carry 0) -> new max
      SJMP CONT
SKIP: MOV B,A   ; update max
CONT: INC R0
      DJNZ R1,LOOP
      MOV 40H,B ; store result at 40H
      SJMP $
END

Algorithm: Initialize max with first element, iterate, if element > max update max. CJNE + JNC handles unsigned compare. For signed, handle OV.

C:

char arr[8]={12,45,23,78,34,56,90,11};
char max=arr[0];
for(i=1;i<8;i++) if(arr[i]>max) max=arr[i];

Similar questions

Official AppAndroid App

PYQDeck for Android

Solve BEU previous-year exam papers anywhere, anytime. Fast search, offline paper viewing, and step-by-step solutions designed specifically for your phone.