============================================= Demonstrate LMC 3 column and 5 column formats ============================================= - Ian! D. Allen - idallen@idallen.ca - www.idallen.com Assembly language programmers code programs using mnemonics and labels in a three-column format: LABEL, MNEMONIC, OPERAND. They let the assembler program calculate and keep track of the locations of labels when the assembler generates the actual machine code that gets loaded into the computer. The assembler program generates a 5-column "listing" file format that shows exactly what codes get assigned to every address. Algorithm for the LMC program below: ----------------------------------- Pseudo-code to input and accumulate numbers entered by the user until they enter the number: 999: set result to zero set continue to zero while continue is not equal to 999 { input num add num to result output result input continue } stop 3 Column Format ("assembly language program" file) -------------------------------------------------- - Assembly-language mnemonic code format using LABELS, MNEMONICS, and OPERANDS. ; This is the typical format for an assembly language source program, where ; the programmer lets the assembler do the work of assigning and remembering ; the memory locations for all the instructions. ; ;LABEL Mnemonic Operand ;===== ======== ======= while LDA continue ; while( continue != 999 ) SUB QUIT SKZ ; can this code be simplified using SKNZ? JMP inputNum JMP endwhile inputNum IN ; Input a number ADD result ; Acccumulate and display STO result OUT IN ; Continue ?? (999 = no) STO continue JMP while endwhile HLT quit DAT 999 ; constant continue DAT 000 ; variable result DAT 000 ; variable 5 Column Format ("listing" file) -------------------------------- - Includes the mailbox (address) and the LMC machine code instruction values. ; This is the typical format for a "listing" file generated by an assembler ; program. The assembler has determined all the memory addresses and the ; listing file shows exactly what codes get assigned to every address. ; A sixth column giving the source file input line number may be used so ; that error messages can refer to errors in the program by input line number. ; MB = "LMC mailbox", i.e. memory location ; code = "LMC machine code", i.e. the 3-digit value in that mailbox ; ;line| MB code: LABEL Mnemonic Operand ;==== == ==== ===== ======== ======= 0001 | 00 114 : while LDA continue ; while( continue != 999 ) 0002 | 01 413 : SUB QUIT 0003 | 02 801 : SKZ ; can this code be simp... 0004 | 03 905 : JMP inputNum 0005 | 04 912 : JMP endwhile 0006 | : 0007 | 05 500 : inputNum IN ; Input a number 0008 | 06 315 : ADD result ; Acccumulate and display 0009 | 07 215 : STO result 0010 | 08 600 : OUT 0011 | 09 500 : IN ; Continue ?? (999 = no) 0012 | 10 214 : STO continue 0013 | 11 900 : JMP while 0014 | : 0015 | 12 700 : endwhile HLT 0016 | : 0017 | 13 999 : quit DAT 999 ; constant 0018 | 14 000 : continue DAT 000 ; variable 0019 | 15 000 : result DAT 000 ; variable -- | Ian! D. Allen - idallen@idallen.ca - Ottawa, Ontario, Canada | Home Page: http://idallen.com/ Contact Improv: http://contactimprov.ca/ | College professor (Free/Libre GNU+Linux) at: http://teaching.idallen.com/ | Defend digital freedom: http://eff.org/ and have fun: http://fools.ca/