Examples: Mailbox Numeric Code Operation Comments

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Examples

This software just requests input from the user and then reports the results.The program has been
loaded into RAM, and the numeric codes for the instructions can be seen in the first three memory
regions.

 By Using numeric instruction codes

This program (instructions from 901 to 000) is written entirely in digital code. The software accepts
two numbers as input and returns the difference. Note that execution starts with mailbox 00 and
ends with mailbox 07. The disadvantages of programming the LMC using digital code are explored
in more detail below.

Numeric
Mailbox Operation Comments
code

INPUT the first number, enter into calculator


00 901 Accumulator = Inbox
(erasing whatever was there)

Mailbox 08 = STORE the calculator's current value (to


01 308
Accumulator prepare for the next step...)

INPUT the second number, enter into


02 901 Accumulator = Inbox
calculator (erasing whatever was there)

Mailbox 09 = STORE the calculator's current value (again,


03 309
Accumulator to prepare for the next step...)

Accumulator = (Now that both INPUT values are STORED


04 508
Mailbox 08 in Mailboxes 08 and 09...)
LOAD the first value back into the calculator
(erasing whatever was there)

Accumulator = SUBTRACT the second number from the


05 209 Accumulator - calculator's current value (which was just set
Mailbox 09 to the first number)
OUTPUT the calculator's result to the
06 902 Outbox = Accumulator
OUTBOX
07 000 Halt HALT the LMC

 Using mnemonics and labels

Assembly language is a low-level programming language that uses mnemonics and labels instead
of numeric code. Although LMC uses only a limited set of mnemonics, the convenience of using
mnemonics for each instruction is evident from the assembly language of the same program shown
below - the programmer no longer needs to memorize a set of anonymous codes and can now
program with a set of mnemonic codes that are easier to remember. If the mnemonic is an
instruction that deals with a memory address (either a branch instruction or load/save data), then a
label is used to name the memory address.

INP
STA FIRST
INP
STA SECOND
LDA FIRST
SUB SECOND
OUT
HLT
FIRST DAT
SECOND DAT

You might also like