0% found this document useful (0 votes)
56 views13 pages

Assembly Language Notes

The document provides an overview of assembly language, highlighting its machine dependency and low-level nature. It explains the role of the assembler in translating assembly language into machine language, as well as various addressing modes and types of instructions such as data transfer, arithmetic, logic, and branching. Additionally, it covers unconditional and conditional branching instructions, detailing how they affect program execution flow.

Uploaded by

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

Assembly Language Notes

The document provides an overview of assembly language, highlighting its machine dependency and low-level nature. It explains the role of the assembler in translating assembly language into machine language, as well as various addressing modes and types of instructions such as data transfer, arithmetic, logic, and branching. Additionally, it covers unconditional and conditional branching instructions, detailing how they affect program execution flow.

Uploaded by

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

Computer Studies Form 5 Assembly Language

Ms Chantelle Grech 1
Computer Studies Form 5 Assembly Language

Assembly Language
Assembly language program is also machine dependent, program developed on one
computer cannot be used on another computer, so it is called as low level language.
Some programming tasks require a programmer to program in a way that reflects the
CPU design. The programmer may need, for example, to directly manipulate memory
addresses or the CPU's registers. This is often true when a device driver for a piece of
hardware is being written or when a translator is being written for a high level language.

High-level languages generally would not be the first choice, because their focus is more
on solving application-based problems. The first choice would be assembly languages.
Assembly Language instructions are very close to machine code itself.
These languages use mnemonics, which are reasonably easily remembered codes for
instructions.

Instruction Meaning
Divide the contents of the accumulator by 18 and store the result in
DIV 18
the accumulator
Get the contents of address 3000 and move them to the accumula-
LDA (3000)
tor.
Get the contents of address 5000 and subtract them from the accu-
SUB (5000)
mulator. Store the result in the accumulator
Examples include:

Each instruction has an instruction part and an address part. The address part refers to
an address where the CPU needs to look in RAM.
The instruction part of an assembler instruction is usually known as the operation
code, or opcode for short. The address part of the instruction is usually known as
the operand.

Ms Chantelle Grech 2
Computer Studies Form 5 Assembly Language

The assembly instruction in fig. 1 contains two new features in addition to those already
mentioned.
 comments: comments are brief descriptions used by programmers to help them
remember and communicate what specific lines of code in the program do.
 labels: labels are used to refer to specific lines or data in the program, and
therefore, specific memory locations in the code segment or data segment of the
RAM. By using labels, programmers avoid the trouble of having to remember
memory addresses or values.

The Assembler
Computer cannot execute a program written in assembly language because computer
understands only machine language. So, it should be translated in machine language,
this translation is done by the Assembler.
Assembler is system software. It is a translator program, which translates Assembly
language program into machine
language. It translates one Assembly
language instruction into one
machine language instruction. After
translation the program is ready for
execution.

Ms Chantelle Grech 3
Computer Studies Form 5 Assembly Language

Types of Addressing Modes


The addressing mode is the method to specify the operand of an instruction. The job of a
microprocessor is to execute a set of instructions stored in memory to perform a specific
task. Operations require the following:
 The operator or opcode which determines what will be done
 The operands which define the data to be used in the operation

1. Immediate Addressing Mode


(symbol #): In this mode data is
present in address field of
instruction

2. Direct Addressing Mode (symbol [ ]) : (Absolute addressing


mode) When using direct addressing mode, the address of the
operand is specified in the instruction. The processor will
retrieve the data directly from the address specified in the
instruction.

3. Symbolic addressing Mode: When a memory location is referred to using a name


instead of a memory address or data. Symbolic addressing are used to represent operands
using a more memorable textual form. For example, The assembly instruction in Fig. 1
may be written thus:
(In this case, the operand '15' has been replaced by the symbol 'Num'.)

Line 1: ADD Num ; adds num to AX

Ms Chantelle Grech 4
Computer Studies Form 5 Assembly Language

Ms Chantelle Grech 5
Computer Studies Form 5 Assembly Language

Assembly Language Instructions


Data Transfer Instructions: LDA and STA are used to transfer data into and out of the
accumulator. LDA instructs the CU to load data into the accumulator. This data can be a
single number or ASCII code, or else data copied in from a single memory element in
RAM. The accumulator can be storing only one piece of data at any one time; thus LDA
causes the new data to overwrite the existing data. The data to load may be specified in
the operand field (immediate addressing); else, the address of the RAM element
containing the data to load in the accumulator is provided (direct addressing).
Otherwise, a symbol may be used (symbolic addressing). On the other hand, STA stores
the data contained in the accumulator into the memory address specified in the
operand field.

Arithmetic Instructions: ADD, SUB, MUL and DIV cause the ALU to add, subtract,
multiply or divide the contents of AX with/by the value specified (directly, immediately
or symbolically) in the operand field. The result is stored in AX itself, overwriting existing
data.

Ms Chantelle Grech 6
Computer Studies Form 5 Assembly Language

Logic Instructions: AND, ORA and NOT cause the ALU to perform the logic operations
and, or and not on AX. To understand how logic operations are carried out on AX, you
have to keep in mind that the register AX is just a memory element inside the CPU which
can hold a number of bits.

Shift Instructions: SHL and SHR move the bits in the accumulator by on position to the
left and one position to the right respectively.
The 'hanging' bit is dropped and the vacant place is filled with a 0. SHL and SHR are
demonstrated in the diagram below.

Ms Chantelle Grech 7
Computer Studies Form 5 Assembly Language

Branching
By now you are certainly aware that a computer program (be it written in machine code
or assembly language) is a sequence of instructions that are executed one line at a time,
starting from the top. Assembly code instructions JMP, JZE and JNZ, provide the facility to
break this sequence and ‘jump’ or ‘branch’ to any other line in the program.

Unconditional Branching

When a JMP instruction is encountered in a program, the CU will continue execution


form the instruction pointed to by the JMP operand.
In the example above, the CU fetches and
executes the first instruction, and then moves on
to the second one which is a JMP instruction. JMP
Label1 will cause the CU to disregard the third and
fourth instructions and continue executing from
the line pointed to by JMP’s operand (Label1).

Another example:
This program will load 20 in the accumulator and repeatedly increment its value by 1.
Note that in this case, the program is branching ‘up’. (The program will enter a
continuous loop and will terminate eventually with an overflow error when the value of
the accumulator becomes too large.) Thus, whenever a JMP instruction is executed,
control is transferred to another part of the program unconditionally.

Ms Chantelle Grech 8
Computer Studies Form 5 Assembly Language

Conditional Branching
Like JMP, instructions JZE and JNZ will cause the CU to continue executing from another
line in the program.
Unlike JMP however, JZE and JNZ will branch only if a certain condition is satisfied. For
this reason, these instructions are known as conditional branching instructions.
The conditions for branching are:

 JZE x : jump to line x only if the value stored in the accumulator is zero.
 JNZ x : jump to line x only if the value stored in the accumulator is not zero.

If the condition is not satisfied, the CU will continue executing the program from the next line after JZE/JNZ.

The first program (e.g. 1) will loop around the second and third line ten times, each time
deducting 1 from the accumulator (initially set to 10). After the 10th subtraction the
value stored in the accumulator will be 0 (zero), and JNZ (jump to Label1 if the
accumulator is not zero) will not branch again to Label 1 but will move on to the
next instruction (not shown).

The second program will load the contents of memory location 100 in the accumulator,
subtract 20 from the accumulator and jump to Label 1 only if the subtraction - and
therefore the content of the accumulator - results in zero.

Ms Chantelle Grech 9
Computer Studies Form 5 Assembly Language

Ms Chantelle Grech 10
Computer Studies Form 5 Assembly Language

Ms Chantelle Grech 11
Computer Studies Form 5 Assembly Language

Ms Chantelle Grech 12
Computer Studies Form 5 Assembly Language

Ms Chantelle Grech 13

You might also like