Periodic table: Difference between revisions

68000 Assembly solution
m (→‎{{header|Raku}}: pruned paren pair)
(68000 Assembly solution)
Line 59:
<br><br>
 
=={{header|68000 Assembly}}==
A lookup table is the most sensible solution, as the data of interest doesn't have a pattern that a computer can take advantage of easily.
 
The table consists of 118 16-bit values. The high byte is the row number, the low byte is the column number. Both are stored as binary-coded decimal (i.e. hex values that look like base 10 numbers.)
 
<lang 68000devpac>Lookup:
;input: D0.W = the atomic number of interest.
LEA PeriodicTable,A0
ADD.W D0,D0 ;we're indexing a table of words, so double the index.
MOVE.W (A0,D0),D0 ;D0.W contains row number in the high byte and column number in the low byte.
RTS
 
PeriodicTable:
DC.W $FFFF ;padding since arrays start at zero in assembly.
DC.W $0101 ;HYDROGEN
DC.W $0118 ;HELIUM
DC.W $0201 ;LITHIUM
DC.W $0202 ;BERYLLIUM
DC.W $0213 ;BORON
DC.W $0214 ;CARBON
DC.W $0215 ;NITROGEN
DC.W $0216 ;OXYGEN
DC.W $0217 ;FLUORINE
DC.W $0218 ;NEON
;etc.</lang>
 
=={{header|ALGOL 68}}==
1,489

edits