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 typing program

2 - button of compiling program

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

4 - registers of CPU

5 - memory location

6 - input data

7 - ouput 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 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 accumulator to memory location (address) 10
02 OUT output number from accumulator
03 HLT stop program

Memory location after the execution of the program:

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

 

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 accumulator to memory location (address) FIRST (08)
02 INP input 2st number to accumulator
03 STA SECOND store number from accumulator to memory location (address) SECOND (09)
04 ADD FIRST add number from memory location FIRST (9) to number in accumulator
05 STA ANSWER store number from accumulator to memory location (address) ANSWER (10)
06 OUT output number from accumulator
07 HLT stop program
08 FIRST DAT  
09 SECOND DAT  
10 ANSWER DAT  

Questions:

Exercises:

Ex. 1 (Author: Litvinova Olga - CS teacher of NIS Pavlodar)

Ex. 2 (Author: Litvinova Olga - CS teacher of NIS Pavlodar)

Ex. 3

Ex. 4

Exam questions:

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