[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

write z80 program to find largest number in a table

Posted on 2009-02-15
3
Medium Priority
?
1,021 Views
Last Modified: 2012-08-13
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

0
Comment
Question by:Timmy904
  • 2
3 Comments
 
LVL 63

Expert Comment

by:☠ MASQ ☠
ID: 23648258
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.
0
 

Author Comment

by:Timmy904
ID: 23649552
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.
0
 
LVL 63

Accepted Solution

by:
☠ MASQ ☠ earned 2000 total points
ID: 23650360
If you are using a loop you only need to store one number
Programatically you need to code:

Put zero in the put value location
Start Loop
Grab number from table value X
Bigger than number in put value? Put X in put value location
Else we are going back in the loop
End loop
Push the number in put value location to display the final result
 
Can you code the insertion of "0" before the loop and then the comparison?
0

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question