How to resolve the algorithm Long literals, with continuations step by step in the 68000 Assembly programming language
How to resolve the algorithm Long literals, with continuations step by step in the 68000 Assembly programming language
Table of Contents
Problem Statement
This task is about writing a computer program that has long literals (character literals that may require specifying the words/tokens on more than one (source) line, either with continuations or some other method, such as abutments or concatenations (or some other mechanisms).
The literal is to be in the form of a "list", a literal that contains many words (tokens) separated by a blank (space), in this case (so as to have a common list), the (English) names of the chemical elements of the periodic table.
The list is to be in (ascending) order of the (chemical) element's atomic number: ... up to the last known (named) chemical element (at this time).
Do not include any of the "unnamed" chemical element names such as:
To make computer programming languages comparable, the statement widths should be restricted to less than 81 bytes (characters), or less if a computer programming language has more restrictive limitations or standards. Also mention what column the programming statements can start in if not in column one.
The list may have leading/embedded/trailing blanks during the declaration (the actual program statements), this is allow the list to be more readable. The "final" list shouldn't have any leading/trailing or superfluous blanks (when stored in the program's "memory"). This list should be written with the idea in mind that the program will be updated, most likely someone other than the original author, as there will be newer (discovered) elements of the periodic table being added (possibly in the near future). These future updates should be one of the primary concerns in writing these programs and it should be "easy" for someone else to add chemical elements to the list (within the computer program). Attention should be paid so as to not exceed the clause length of continued or specified statements, if there is such a restriction. If the limit is greater than (say) 4,000 bytes or so, it needn't be mentioned here.
Show all output here, on this page.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Long literals, with continuations step by step in the 68000 Assembly programming language
Source code in the 68000 programming language
HelloString:
DC.B "Hello World" ;no null terminator
GoodbyeString:
DC.B "Goodbye World!",0
EVEN
PrintString HelloString ;unimplemented macro.
NullElement:
DC.L nullString
Elements:
; this is typed in a compact manner to save on typing, however putting each on its own line with a
; "DC.L" directive in front will produce the same result. A comment with the element number on each line will aid in
; adding new elements to the list.
DC.L hydrogen,helium,lithium,beryllium,boron,carbon,nitrogen,oxygen,fluorine
DC.L neon,sodium,magnesium,aluminum,silicon,phosphorous,sulfur,chlorine,argon
DC.L potassium,calcium,scandium,titanium,vanadium,chromium,manganese,iron
DC.L cobalt,nickel,copper,zinc,gallium,germanium,arsenic,selenium,bromine
DC.L krypton,rubidium,strontium,yttrium,zirconium,niobium,molybdenum
DC.L technetium,ruthenium,rhodium,palladium,silver,cadmium,indium,tin
DC.L antimony,tellurium,iodine,xenon,cesium,barium,lanthanum,cerium
DC.L praseodymium,neodymium,promethium,samarium,europium,gadolinium,terbium
DC.L dysprosium,holmium,erbium,thulium,ytterbium,lutetium,hafnium,tantalum
DC.L tungsten,rhenium,osmium,iridium,platinum,gold,mercury,thallium,lead
DC.L bismuth,polonium,astatine,radon,francium,radium,actinium,thorium
DC.L protactinium,uranium,neptunium,plutonium,americium,curium,berkelium
DC.L californium,einsteinium,fermium,mendelevium,nobelium,lawrencium
DC.L rutherfordium,dubnium,seaborgium,bohrium,hassium,meitnerium,darmstadtium
DC.L roentgenium,copernicium,nihonium,flerovium,moscovium,livermorium
DC.L tennessine,oganesson
Elements_End:
nullString:
DC.B 0
EVEN
hydrogen:
DC.B "hydrogen",0
EVEN
helium:
DC.B "helium",0
EVEN
lithium:
DC.B "lithium",0
EVEN
;etc.
RevisionDate:
DC.B "2021-Sep-20th",0
EVEN
Finally:
DC.B "elements, the last is",0
EVEN
ElementCount equ (Elements_End-Elements)/4
; a constant value that cannot change at runtime.
; This counts the number of bytes between the two labels, and automatically adjusts when the size of the list changes.
; The division by 4 gets the actual element count since each address is 4 bytes long.
LEA RevisionDate,A3 ; the printing routine uses A3 as input
JSR PrintString ; unimplemented printing routine
JSR NewLine ; unimplemented new line routine
MOVE.B ElementCount,D0
JSR ConvertHex2BinDec ; converts a hexadecimal value to a trio of BCD digits
JSR PrintBCD ; unimplemented printing routine for numeric values
MOVE.B #' ',D0 ; ASCII for spacebar
JSR PrintChar
LEA Finally,A3
JSR PrintString
MOVE.B #' ',D0 ; ASCII for spacebar
JSR PrintChar
MOVE.W ElementCount,D1
LSL.W #2,D1 ; multiply by 4, we are indexing into a table of longs
LEA NullElement,A2
; load the base of the lookup table into A2. This is the table's "true base"
; since the "ElementCount" constant doesn't account for zero-indexing
MOVEA.L (A2,D1),A3
;dereference the pointer, offsetting by D1. This retrieves the address of the desired element in the list.
JSR PrintString
You may also check:How to resolve the algorithm Deepcopy step by step in the Lasso programming language
You may also check:How to resolve the algorithm Gamma function step by step in the jq programming language
You may also check:How to resolve the algorithm Extreme floating point values step by step in the NetRexx programming language
You may also check:How to resolve the algorithm Digital root step by step in the AppleScript programming language
You may also check:How to resolve the algorithm Jump anywhere step by step in the Phix programming language