登录

Assembly Language

Opcode

Operand

Explanation

LDM

#n

Immediate addressing. Load the number n to ACC

LDD

<address>

Direct addressing. Load the contents of the location at the given address to ACC

LDI

<address>

Indirect addressing. The address to be used is at the given address. Load the contents of this second address to ACC

LDX

<address>

Indexed addressing. Form the address from <address> + the contents of the index register. Copy the contents of this calculated address to ACC

LDR

n

Immediate addressing. Load the number n to IX

MOV

<register>

Move the contents of the accumulator to the given register (IX)

STO

<address>

Store the contents of ACC at the given address

ADD

<address>

Add the contents of the given address to the ACC

ADD

#n/Bn/&n

Add the number n to the ACC

SUB

<address>

Subtract the contents of the given address from the ACC

SUB

#n/Bn/&n

Subtract the number n from the ACC

INC

<register>

Add 1 to the contents of the register (ACC or IX)

DEC

<register>

Subtract 1 from the contents of the register (ACC or IX)

JMP

<address>

Jump to the given address

CMP

<address>

Compare the contents of ACC with the contents of <address>

CMP

#n

Compare the contents of ACC with number n

CMI

<address>

Indirect addressing. The address to be used is at the given address. Compare the contents of ACC with the contents of this second address

JPE

<address>

Following a compare instruction, jump to <address> if the compare was True

JPN

<address>

Following a compare instruction, jump to <address> if the compare was False

IN

Key in a character and store its ASCII value in ACC

OUT

Output to the screen the character whose ASCII value is stored in ACC

END

Return control to the operating system

提示
  • All questions will assume there is only one general purpose register available (Accumulator) ACC denotes Accumulator

  • IX denotes Index Register

  • <address> can be an absolute or symbolic address

  • # denotes a denary number, e.g. #123

  • B denotes a binary number, e.g. B01001010 & denotes a hexadecimal number, e.g. &4A

Assembly language and machine code

  • The only programming language that a CPU can use is machine code.

  • Every different type of computer/chip has its own set of machine code instructions.

  • A computer program stored in main memory is a series of machine code instructions that the CPU can automatically carry out during the fetch-execute cycle.

  • The first programming language to be developed was assembly language, this is closely related to machine code and uses mnemonics instead of binary.

Stages of assembly

  • Before a program written in assembly language (source code) can be executed, it needs to be translated into machine code.

  • The translation is performed by a program called an assembler.

  • An assembler translates each assembly language instruction into a machine code instruction.

  • An assembler also checks the syntax of the assembly language program to ensure that only opcodes from the appropriate machine code instruction set are used.

  • A two pass assembler produces an object program in machine code that can be stored, loaded then executed at a later stage.

  • This requires the use of another program called a loader.

  • Two pass assemblers need to scan the source program twice, so they can replace labels in the assembly program with memory addresses in the machine code program.

Pass 1

  • Read the assembly language program one line at a time.

  • Ignore anything not required, such as comments.

  • Allocate a memory address for the line of code.

  • Check the opcode is in the instruction set.

  • Add any new labels to the symbol table with the address, if known.

  • Place address of labelled instruction in the symbol table.

Pass 2

  • Read the assembly language program one line at a time.

  • Generate object code, including opcode and operand, from the symbol table

generated in Pass 1.

  • Save or execute the program.

Assembly language and machine code
填空题
ID:113

The only programming language that a CPU can use is .

machine code
[0/1]

Assembly language and machine code
填空题
ID:114

The translates each assembly language instruction into a machine code instruction.

[0/1]

Assembly language instructions

Data movement instructions

Opcode

Operand

Explanation

LDM

#n

Immediate addressing. Load the number n to ACC

LDD

<address>

Direct addressing. Load the contents of the location at the given address to ACC

LDI

<address>

Indirect addressing. The address to be used is at the given address. Load the contents of this second address to ACC

LDX

<address>

Indexed addressing. Form the address from <address> + the contents of the index register. Copy the contents of this calculated address to ACC

LDR

n

Immediate addressing. Load the number n to IX

MOV

<register>

Move the contents of the accumulator to the given register

STO

<address>

Store the contents of ACC at the given address

Input and output of data instructions

Opcode

Operand

Explanation

IN

Key in a character and store its ASCII value in ACC

OUT

Output to the screen the character whose ASCII value is stored in ACC

No opcode is required as a single character is either input to the accumulator or output

Arithmetic operation instructions

Opcode

Operand

Explanation

ADD

<address>

Add the contents of the given address to the ACC

ADD

#n/Bn/&n

Add the number n to the ACC

SUB

<address>

Subtract the contents of the given address from the ACC

SUB

#n/Bn/&n

Subtract the number n from the ACC

INC

<register>

Add 1 to the contents of the register (ACC or IX)

DEC

<register>

Subtract 1 from the contents of the register (ACC or IX)

Answers to calculations are always stored in the accumulator

Unconditional and conditional instructions

Opcode

Operand

Explanation

JMP

<address>

Jump to the given address

JPE

<address>

Following a compare instruction, jump to <address> if the compare was True

JPN

<address>

Following a compare instruction, jump to <address> if the compare was False

END

Return control to the operating system

Jump means change the PC to the address specified, so the next instruction to beexecuted is the one stored at the specified address, not the one stored at the next location in memory

Compare instructions

Opcode

Operand

Explanation

CMP

<address>

Compare the contents of ACC with the contents of <address>

CMP

#n

Compare the contents of ACC with number n

CMI

<address>

Indirect addressing. The address to be used is at the given address. Compare the contents of ACC with the contents of this second address

The contents of the accumulator are always compared

Addressing modes

  • Assembly language and machine code programs use different addressing modes depending on the requirements of the program.

  • Absolute addressing – the contents of the memory location in the operand are used. For example, LDD 200.

  • Direct addressing – the contents of the memory location in the operand are used. For example, LDD 200.

  • Indirect addressing – the contents of the contents of the memory location in the operand are used. For example, LDI 200.

  • Indexed addressing – the contents of the memory location found by adding the contents of the index register (IR) to the address of the memory location in the operand are used. For example, LDX 200.

  • Immediate addressing – the value of the operand only is used. For example, LDM #200.

  • Relative addressing – the memory address used is the current memory address added to the operand. For example, JMR #5.

  • Symbolic addressing – only used in assembly language programming. A label is used instead of a value. For example, LDD MyStore.

Simple assembly language programs

  • A program written in assembly language will need many more instructions than a program written in a high-level language to perform the same task.

  • In a high-level language, adding a list of numbers together and storing the answer would typically be written using a loop.

CIR

Opcode

Operand

ACC

IX

Counter 118

Total 119

100

LDM

#0

0

101

STO

total

0

0

102

STO

counter

0

0

0

103

LDR

#0

0

0

0

0

104

LDX

number

5

0

0

0

105

ADD

total

5

0

0

0

106

STO

total

5

0

0

5

107

INC

IX

5

1

0

5

108

LDD

counter

0

1

0

5

109

INC

ACC

1

1

0

5

110

STO

counter

1

1

1

5

111

CMP

#3

1

1

1

5

112

JPN

loop

1

1

1

5

104

LDX

number

7

1

1

5

105

ADD

total

12

1

1

5

106

STO

total

12

1

1

12

107

INC

IX

12

2

1

12

108

LDD

counter

1

2

1

12

109

INC

ACC

2

2

1

12

110

STO

counter

2

2

2

12

111

CMP

#3

2

2

2

12

112

JPN

loop

2

2

2

12

104

LDX

number

3

2

2

12

105

ADD

total

15

2

2

12

106

STO

total

15

2

2

15

107

INC

IX

15

3

2

15

108

LDD

counter

2

3

2

15

109

INC

ACC

3

3

2

15

110

STO

counter

3

3

3

15

111

CMP

#3

3

3

3

15

112

JPN

loop

3

3

3

15

113

END

Assembly language and machine code
填空题
ID:115

State the contents of the accumulator after the following instructions have been executed. The memory location with address 200 contains 300, the memory location with address 300 contains 50.

  • LDM #200 (ACC: )

  • LDD 200 (ACC: )

  • LDI 200 (ACC: )

[0/1]

Assembly language and machine code
填空题
ID:116

Write an assembly language instruction to:

  • compare the accumulator with 5:

  • jump to address 100 if the comparison is true:

[0/2]

Assembly language and machine code
填空题
ID:117

What is the value of total in the end?

Label

Opcode

Operand

LDD

number1

SUB

number2

ADD

number3

CMP

#10

JPE

nomore

ADD

number4

nomore:

STO

total

END

number1:

#30

number2:

#40

number3:

#20

number4:

#50

total:

#0

[0/3]

登录