Link to home
Start Free TrialLog in
Avatar of Timmy904
Timmy904

asked on

write z80 program to find largest number in a table

hello experts,

I need to write a z80 program to find largest number from a table of integers. I need to store the table of numbers in location 0080h and the largest number in 00E0h. I managed to store the numbers, however I end up putting the final number in location 00E0h. I need help on how to store the largest number instead..Btw, I'm using Z80 Simulator IDE v9.30.

Thank Q experts!
;a program to demonstrate use of DB to initialise series of
;numbers and then accept each number one after another.
 
 
 
          	LD HL, TABLE		;STORE NUMBERS IN HL
             	LD B,(HL)		        ;PUT NO. OF COUNTER I.E. 6 INTO B
             	INC HL			;MOVE POINTER TO THE NEXT LOCATION
AGAIN:	LD A,(HL)		;STORE TABLE OF NUMBERS IN A
              	DEC B			;MINUS EVERY COUNTER BY 1
        	INC HL			;MOVE TO THE NEXT NUMBER IN TABLE
           	JP NZ,AGAIN		;JUMP TO 'AGAIN' IF B IS NOT EQUAL TO 0.
                                                ;I assume this is where the code to 'compare' the numbers
	       CALL DISP
	       HALT
 
DISP:        	PUSH AF			;this part only display d final number in the table.
        	        PUSH BC
	                LD (00E0H),A
	                POP BC
	               POP AF
	               RET
 
 
                	ORG 0080H		;LOCATION WHERE THE NUMBER WILL BE STORED
TABLE:	DB 7,3,8,25,6,10,13,4

Open in new window

Avatar of ☠ MASQ ☠
☠ MASQ ☠

The code seems to do what it says - what doesn't seem to be happening is storing the largest number as the routine loops.
perhaps you need to store your first number, then check if the next number is bigger, if not then get the next number, if the next number is bigger than the stored number then store that instead etc..
Currently you seem to store each number in turn so when you finish the routine whaterver the last number is returned.
 
If this is part of an assignment experts here can't do your homework for you but can help point you in the right direction.
Avatar of Timmy904

ASKER

Hello..

thank u 4 your reply. Yes I can see that I am storing them in sequence but if there's any expert who can show me a way or a code in z80 for getting the largest number in a table I would really appreciate it.
ASKER CERTIFIED SOLUTION
Avatar of ☠ MASQ ☠
☠ MASQ ☠

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial