Programming in Little Man Computer (LMC)

11.5.1.3 analyze a simple program written in the language of assembler 

Programming in Little Man Computer (LMC)

LMC online is a simulator for getting to know the low-level programming language Assembler.

1 - space for a typing program

2 - button for compiling the program

3 - button RUN the whole program, STEP - line by line

4 - registers of CPU

5 - the memory location

6 - input data

7 - output data

LMC contains a set of commands called mnemonics.

Mnemonic Code

Numeric Code
XX is the cell number in the memory compartment.

Instruction
INP 901 Input data
OUT 902 Output data
ADD 1XX Add data
SUB 2XX Subtract data
STA 3XX Store data
LDA 5XX Load data
BRA 6XX Branch to a specified cell
BRZ 7XX If 0, branch to a specified cell
BRP 8XX If 0 or positive, branch to a specified cell
HLT 000 Break execution
DAT   Treat content as data

Simple program:

Task #1

Write a program that asks for a number and prints it out.

00 INP input number to accumulator
01 STA 06 store number from the accumulator to a memory location (address) 10
02 OUT output number from the accumulator
03 HLT stop program

Memory location after the execution of the program:

Using memory location define what will be displayed
  • Answer: 23

Format of a machine code instruction

Opcode (Operation Code):

  • Specifies the operation to be performed.
  • It's a unique set of bits that corresponds to each operation, such as ADD, SUB, LDA, STA, etc.

Operand(s):

  • These specify the data or the location of data on which the operation will act.
  • Operands can be:
    • Immediate values: Direct values to be used in the operation. For example, in the instruction ADD 5, the number 5 is an immediate operand.

Task #2

Write a program that stores a pair of numbers in variables called FIRST and SECOND.   The two numbers should be added together. The answer should be stored in a variable called ANSWER and then output. 

00 INP input 1st number to accumulator
01 STA FIRST store number from the accumulator to a memory location (address) FIRST (08)
02 INP input 2nd number to accumulator
03 STA SECOND store number from the accumulator to a memory location (address) SECOND (09)
04 ADD FIRST add a number from memory location FIRST (9) to number in the accumulator
05 STA ANSWER store number from the accumulator to a memory location (address) ANSWER (10)
06 OUT output number from the accumulator
07 HLT stop program
08 FIRST DAT  
09 SECOND DAT  
10 ANSWER DAT  

Task #3

Write a program that stores two numbers and prints out the largest number. 

00 INP input 1st number to accumulator
01 STA FIRST store number from the accumulator to a memory location (address) FIRST (12)
02 INP input 2nd number to accumulator
03 STA SECOND store number from the accumulator to a memory location (address) SECOND (13)
04 SUB FIRST subtract a number from memory location FIRST (12) from the number in the accumulator
05 BRP SECBIG if an accumulator value is more than 0, go to label SECBIG (09)
06 LDA FIRST load to accumulator a number from memory location FIRST (12)
07 OUT output number from the accumulator
08 HLT stop program
09 SECBIG LDA SECOND load to accumulator a number from memory location SECOND (13) if in (05) incorrect condition
10 OUT output number from the accumulator
11 HLT stop program
12 FIRST DAT  
13 SECOND DAT  

Questions:

1. What is the mnemonic code?

2. Name mnemonics of LMC and explain each.


Exercises:

Ex. 1 Fill the gaps

Ex. 2 Write a LMC program (Author: Litvinova Olga - CS teacher of NIS Pavlodar)

Ex. 3 Define values of the memory location (Author: Litvinova Olga - CS teacher of NIS Pavlodar)

Ex. 4 Fill the trace table

Ex. 5 Fill the trace table

Ex. 6 Write a program in LMC for calculating (A-C)+(B-D).


Exam questions:

 

Категория: Programming languages | Добавил: bzfar77 (22.09.2020)
Просмотров: 10582 | Теги: Input, Output, substract, BRZ, store, BRP, Add, Halt, Bra, low level programming language | Рейтинг: 5.0/1
Всего комментариев: 0
avatar