Re: A86: I need help in 86 ASM...


[Prev][Next][Index][Thread]

Re: A86: I need help in 86 ASM...



On Fri, 1 Aug 1997 QmH@aol.com wrote:

> Okay, I want to make a Periodic Table program that would input the symbol and
> tell you what the Element name is, atomic weight, number, etc and vice versa.
>  Can someone help me out on this?  Like, tell me how can you make it
> search... I can't seem to figure that out..

The way to search depends on your data organization.  Fixed-length records
are the easiest.  For this example, let's say your records are ordered by
atomic number, and they look like this:

	.db "H "	; this is the symbol, always 2 bytes
	.dw 101		; this is 100*atomic mass, always a word
	.dw strH	; this is a pointer to the full name

You don't want to include the full name in the records because it makes
them different lengths, which makes searching more difficult.

So now, to search for a specific symbol, like "Mo", load it into a 
register--let's say DE.  (Since TI hasn't released the info on user input,
I'm not going to explain it now, so you'll have to save this whole email
for later.)  Back to the example:

	DE contains the symbol to find, "Mo", $4D6F (I think)

You need to step through the table from the beginning to the end,
retrieving each symbol name in another register and comparing it to DE
until you find one that matches.  Something like this:

	ld hl,TableStart
FindSymLoop:

	ld b,(hl)	; load the symbol into BC
	inc hl
	lc c,(hl)
	inc hl

	ex de,hl	; we can't compare BC to DE, so swap HL and DE
	or a		; this makes the carry flag 0
	sbc hl,bc	; this compares HL (input) to BC (table value)
	jr z, SymFound	; if HL=BC, the symbol matches
	add hl,bc	; restore HL to its former glory
	ex de,hl	; swap HL and DE again
	jr FindSymLoop

SymFound:
	ex de,hl	; bring address back into HL
			; now HL points to the atomic weight of the proper
			; entry, so you can load that, display it, and
			; then move to the name pointer to display the
			; name

Please note that this code would not work if the user entered a symbol not
in the table.

If you want more general asm information, try going to your local library
and finding some books on the TRS-80 (if they haven't thrown them out by
now).  It's also good to read through well-documented source code.
Unfortunately, there's not a whole lot of that floating around.  By now
there should be a lot of TI-85 info on the 'net.  The instruction set is 
the same, and since you're just getting started with the basics, it should
be helpful.

--------
Dan Eble (mailto:eble@cis.ohio-state.edu)
         (http://www.cis.ohio-state.edu/~eble)


Follow-Ups: References: