0% found this document useful (0 votes)
65 views7 pages

4.2 Assembly Language

Computer science assembly language

Uploaded by

aburishabhtate
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views7 pages

4.2 Assembly Language

Computer science assembly language

Uploaded by

aburishabhtate
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

ASSEMBLY LANGUAGE

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. Each machine code instruction performs one simple task, for example,
storing a value in a memory location at a specified address. Machine code is binary, it is
sometimes displayed on a screen as hexadecimal so that human programmers can understand
machine code instructions more easily.
Writing programs in machine code is a specialised task that is very time consuming and often
error prone, as the only way to test a program written in machine code is to run it and see what
happens. In order to shorten the development time for writing computer programs, other
programming languages were developed, where the instructions were easier to learn and
understand. Any program not written in machine code needs to be translated before the CPU can
carry out the instructions, so language translators were developed.
The first programming language to be developed was assembly language, this is closely related
to machine code and uses mnemonics instead of binary.
Assembly language mnemonics Machine code hexadecimal Machine code binary

LDD TOTAL 0140 00000000110000000

ADD 20 0214 00000001000011000

STO TOTAL 0340 00000001110000000

The structure of assembly language and machine code instructions is the same. Each instruction
has an opcode that identifies the operation to be carried out by the CPU. Most instructions also
have an operand that identifies the data to be used by the opcode.
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. This speeds up the development
time, as some errors are identified during translation before the program is executed.
The assembler generates instructions by evaluating the mnemonics (symbols) in the operation
field and finding the value of symbols and literals to produce machine code.
On the basis of this functionality, assembler has two types:
Single-Pass Assembler: If an assembler does all this work in one scan then it is called a single-
pass assembler.
Multiple-Pass Assembler: If it does it in multiple scans then called a multiple-pass assembler.
A single pass assembler puts the machine code instructions straight into the computer memory to
be executed.
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 (i.e. the operations) and operand (i.e. the data), from
the symbol table generated in Pass 1.
» Save or execute the program.
The second pass is required as some labels may be referred to before their address is known. For
example, Found is a forward reference for the JPN instruction.
If the program is to be loaded at memory address 100, and each memory location contains 16
bits, the symbol table for this small section of program would look like this:
Assembly language instructions
There are different types of assembly language instructions. Examples of each type are given
below.
Data movement instructions
These instructions allow data stored at one location to be copied into the accumulator. This data
can then be stored at another location, used in a calculation, used for a comparison or output.
Input and output of data instructions
These instructions allow data to be read from the keyboard or output to the screen.

Arithmetic operation instructions


These instructions perform simple calculations on data stored in the accumulator and store the
answer in the accumulator, overwriting the original data.
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, if the memory location with address 200 contained the value 20, the assembly language
instruction LDD 200 would store 20 in the accumulator.
Direct addressing – the contents of the memory location in the operand are used. For example,
if the memory location with address 200 contained the value 20, the assembly language
instruction LDD 200 would store 20 in the accumulator. Absolute and direct addressing are the
same.
Indirect addressing – the contents of the contents of the memory location in the operand are
used. For example, if the memory location with address 200 contained the value 20 and the
memory location with address 20 contained the value 5, the assembly language instruction LDI
200 would store 5 in the accumulator.
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, if
IR contained the value 4 and memory location with address 204 contained the value 17, the
assembly language instruction LDX 200 would store 17 in the accumulator
Immediate addressing – the value of the operand only is used. For example, the assembly
language instruction LDM #200 would store 200 in the accumulator.
Relative addressing – the memory address used is the current memory address added to the
operand. For example, JMR #5 would transfer control to the instruction 5 locations after the
current instruction.
Symbolic addressing – only used in assembly language programming. A label is used instead of
a value. For example, if the memory location with address labelled MyStore contained the value
20, the assembly language instruction LDD MyStore would store 20 in the accumulator. Labels
make it easier to alter assembly language programs because when absolute addresses are used
every reference to that address needs to be edited if an extra instruction is added, for example.

You might also like