You write that line numbers are needed, but when you use labels, line numbers (i.e. Look for instance at this implementation which uses 75 mailboxes.
LITTLE MAN COMPUTER CODE
The code is not very concise: it uses 98 mailboxes, excluding the storage needed for the input data. This LMC is a variant on the original LMC, which had 3-digit numbers, while you seem to be working with one that uses 4-digit numbers. LdaInstruction DAT 5000 // LDA instruction
StoInstruction DAT 3000 // STO instruction Location DAT 500 // initial list location Previous DAT // A value (also used for swapping)Ĭurrent DAT // A value (also used for swapping)Ĭount DAT // count variable (input and output) HLT // (Should never hit this instruction) STO instruction // increment manipulated instructionĮxitLoopOutput BR start // Branch to top of loop (embedded) LoopOutput LDA instruction // load manipulated instruction (used as counter)īRZ exitLoopOutput // GOTO END OUTPUT LOOP StoreCurrent DAT // Store in A (instruction is manipulated) StorePrevious DAT // Store in A (instruction is manipulated) LDA stoInstruction // load STO instruction code SUB previous // A – A (swap if not positive) LoadCurrent DAT // load A (instruction is manipulated) LoadPrevious DAT // load A (instruction is manipulated) LDA ldaInstruction // load LDA instruction numeric code StoreInput DAT // manipulated instruction (store input in list)ĪDD one // increment store instruction (to next list location)īRZ exitLoopI // if(I = count - 1) GOTO END I LOOPīRP exitLoopJ // If I = j, then GO END J LOOP LoopInput LDA storeInput // Load manipulated instruction (using as counter)īRZ exitInputLoop // If last count, go to END INPUT LIST
STO i // Store STO + LOC + Count to determine end STO storeInput // Overwrite STO instruction for list Lines that are not the target of any operation can go without labels.
Just use the comments as inspiration for the labels.
LITTLE MAN COMPUTER UPDATE
000 IN 9001 // input countĠ03 ADD 095 1095 // Determine first locationĠ04 STO 011 3011 // Overwrite STO instruction for listĠ06 STO 092 3092 // Store STO + LOC + Count to determine endĠ07 LDA 011 5013 // Load manipulated instruction (using as counter)Ġ09 BRZ 016 7016 // If last count, go to END INPUT LISTĠ11 DAT 0 // manipulated instruction (store input in list)Ġ13 ADD 098 1098 // increment store instruction (to next list location)Ġ14 STO 011 3011 // Update STO instructionĠ24 BRZ 061 7061 // if(I = count - 1) GOTO END I LOOPĠ30 BRP 057 8057 // If I = j, then GO END J LOOPĠ31 LDA 097 5097 // load LDA instruction numeric codeĠ33 ADD 093 1093 // set to LDA or AĠ35 SUB 098 2098 // set to LDA or AĠ37 DAT 0 // load A (instruction is manipulated)Ġ39 DAT 0 // load A (instruction is manipulated)Ġ41 SUB 088 2088 // A – A (swap if not positive)Ġ43 LDA 096 5096 // load STO instruction codeĠ47 SUB 098 2098 // set to STO Ġ50 DAT 0 // Store in A (instruction is manipulated)Ġ52 DAT 0 // Store in A (instruction is manipulated)Ġ67 STO 092 3092 // store unreachable instructionĠ68 LDA 071 5071 // load manipulated instruction (used as counter)Ġ75 STO 071 3071 // increment manipulated instructionĠ77 BR 0 6000 // Branch to top of loop (embedded)Ġ78 HLT 0 // (Should never hit this instruction)Ġ88 DAT 0 // A value (also used for swapping)Ġ89 DAT 0 // A value (also used for swapping)Ġ90 DAT 0 // count variable (input and output) Only the line number, labels, Mnemonic Data and comments. I'm not sure what label names to use to improve maintainability. This is the program but I would like to use Labels for all constants, variables, and branch target locations where the branch would go to to help simplify the code and make it more readable. This code is a Little Man Computer program that Bubblesorts and uses input, output, and sorts itself and then repeats.