0% found this document useful (0 votes)
7 views

4.2 Assembly Language Student

The document provides an overview of assembly language, detailing its relationship to machine code and its role as a low-level programming language that uses mnemonics for easier human communication with CPUs. It explains the assembly process, including the use of single and two-pass assemblers, as well as various addressing modes and instruction sets. Additionally, it includes examples of assembly language instructions and their corresponding operations, along with tasks for practice.

Uploaded by

jaibirminecraft
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

4.2 Assembly Language Student

The document provides an overview of assembly language, detailing its relationship to machine code and its role as a low-level programming language that uses mnemonics for easier human communication with CPUs. It explains the assembly process, including the use of single and two-pass assemblers, as well as various addressing modes and instruction sets. Additionally, it includes examples of assembly language instructions and their corresponding operations, along with tasks for practice.

Uploaded by

jaibirminecraft
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Assembly Language

Communication with a
Computer
High level languages – closer to
C, how humans understand
Pascal, communication
Java, VB
Assembly
language Low level languages –
closer to how computers
understand communication
Machine code

Hardware
Assembly Language and
Machine Code
Machine code – the
binary programming
language that the
CPU understands

Assembly language –
a low level processor
chip specific
programming
language that uses
mnemonics.
Assembly Language Instruction
Set
You will need to familiarise with an assembly language
instruction set (the set on the right can be viewed in
OneNote).

As mentioned in the video, assembly language turns


binary/numerical instructions into mnemonic text
codes. These make communicating with the CPU more
accessible to humans.

Each instruction set is unique to a processor, this is a


generalised version.

The instruction set is made up of opcodes (short


operation code) and operands (identifies the data to be
used).
Assembly Language Instruction
Set
Data movement instructions allow data to be stored at one location to be copied in the
accumulator. This data can then be stored in another location, used in a calculation or used
for comparison or output
Assembly Language Instruction
Set
Input or output of data instructions allow data to be read from a keyboard or output to a
screen
Assembly Language Instruction
Set
Arithmetic operation instructions allow simple calculations to be performed on data in the
accumulator and store the data in the accumulator, overwriting the original data.
Assembly Language Instruction
Set
Unconditional and conditional instructions – JUMP means to change the PC to the address
specified, so the next instruction to be executed is the one stored at the specified address,
not the one stored at the next location in memory.
Assembly Language Instruction
Set
Compare instructions – components of the accumulator are always compared.
Assembly Language Instruction
Set
An example of how assembly language translates to machine code and then binary is
below:

Opcode Operand Opcode Operand

LDD Total 0140 00000000110000000


ADD 20 0214 00000001000011000
STO Total 0340 00000001110000000
Assembly Lang. Mnemonics Machine Code Hex. Machine Code Binary
Stages of Assembly Process
Similar to writing algorithms in high level languages, before assembly language can be
executed, it must be translated into the machine code for the processor to understand.

An assembler is used to translate assembly language into machine code and also checks
the syntax is correct. Checking the syntax is important to ensure the opcodes match the
instruction set being used by the processor.

There are two types of assembler – single pass and two pass. You need to know about two
pass assemblers.

A two pass assembler produces an object program that can be stored, loaded and then
executed at a later stage. This requires the use of a loader.

Two pass assemblers need to scan the source program twice, so they can replace the
labels in the assembly program with memory addresses in the machine code program
Stages of Assembly Process Pass 1 is like filtering the
executable components and
Pass 1 sorting the program into memory
• Read the assembly language program one line at a time. locations line by line.
• Ignore anything not required, such as comments.
• Allocate a memory address for the line of code. Pass 2 converts assembly code into
• Check the opcode is in the instruction set. object code before storing or
• Add any new labels to the symbol table with the address, if known. running.
• 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.
Label Memory address

LDD Total 0140


Assembly Lang. Mnemonics Machine Code Hex.
Modes of Addressing
Immediate addressing – the value of the operand only is used. E.g. LDM #200 would store 200 in the ACC.

Absolute/Direct addressing – contents of memory location in operand are used. E.g. if address location 200
contained 20, instruction LDD 200 would store 20 in ACC.

Indirect addressing – the contents of the contents of the memory location is used. E.g. if address 200
contained the value 20 and address 20 contains the value 5, LDI 200 would load 5 into the ACC.

Indexed addressing – contents of memory location found by adding the IR value to the address memory
location. E.g. if IR value was 4 and memory location 204 contained 17, LDX 200 would load 17 into ACC.

Relative addressing – the memory address used is the current memory address added to the operand. E.g.
JMR #5 would transfer control to the instruction 5 locations after the current instruction.

Symbolic addressing – only used in assembly language programming. Uses a label for a memory location
instead of a value. Similar to how a variable is used in HLL.
Assembly Language Examples
Consider this HLL instruction:
total = first + second + third

Now look at how it could be written in assembly language:

Label Opcode Operand


start: LDD first
ADD second
ADD third
STO total
END

first: #20
second: #30
third: #40
total: #0

The program will be loaded into memory address 100. We will produce a symbol table and trace table from
this.
Label Opcode

Assembly Language Examples


Operand
start: LDD
first
ADD
First a symbol table: Label Address second
ADD
start 100 third
first 106 STO
total
second 107 END

third 108 first: #20


total 109 second: #30
third: #40
total: #0
And now to trace the program:

CIR Opcode Operand ACC first 106 second 107 third 108 total 109

100 LDD first 20 20 30 40 0


Label Opcode

Assembly Language Examples


Operand
start: LDD
first
ADD
First a symbol table: Label Address second
ADD
start 100 third
first 106 STO
total
second 107 END

third 108 first: #20


total 109 second: #30
third: #40
total: #0
And now to trace the program:

CIR Opcode Operand ACC first 106 second 107 third 108 total 109

100 LDD first 20 20 30 40 0


101 ADD second 50
Label Opcode

Assembly Language Examples


Operand
start: LDD
first
ADD
First a symbol table: Label Address second
ADD
start 100 third
first 106 STO
total
second 107 END

third 108 first: #20


total 109 second: #30
third: #40
total: #0
And now to trace the program:

CIR Opcode Operand ACC first 106 second 107 third 108 total 109

100 LDD first 20 20 30 40 0


101 ADD second 50
102 ADD third 90
Label Opcode

Assembly Language Examples


Operand
start: LDD
first
ADD
First a symbol table: Label Address second
ADD
start 100 third
first 106 STO
total
second 107 END

third 108 first: #20


total 109 second: #30
third: #40
total: #0
And now to trace the program:

CIR Opcode Operand ACC first 106 second 107 third 108 total 109

100 LDD first 20 20 30 40 0


101 ADD second 50
102 ADD third 90
103 STO total 90
Label Opcode

Assembly Language Examples


Operand
start: LDD
first
ADD
First a symbol table: Label Address second
ADD
start 100 third
first 106 STO
total
second 107 END

third 108 first: #20


total 109 second: #30
third: #40
total: #0
And now to trace the program:

CIR Opcode Operand ACC first 106 second 107 third 108 total 109

100 LDD first 20 20 30 40 0


101 ADD second 50
102 ADD third 90
103 STO total 90
104 END
Assembly Language Examples
Consider this HLL algorithm:
FOR counter = 1 TO 3
total = total + number[counter]
NEXT counter
Label Opcode Operand Comment
The same algorithm in LDM #0 Load 0 into
assembly language will ACC
STO total Store 0 in total
need to use the IX. STO counter Store 0 in counter
LDR #0 Set IX to 0
It could look like this: loop: LDX number Load the number indexed by IX
into ACC
ADD total Add total to ACC
STO total Store result in
total
Task: Produce a truth INC IX Add 1 to
contents of IX
table for the assembly LDD counter Load counter into
program to the right. ACC
INC ACC Add 1 to ACC
STO counter Store the result in
counter
CMP #3 Compare with
3
Assembly Language Examples
Tasks:
1. a) State the contents of the accumulator after the following instructions have been executed. The memory location
within the address 200 contains 300, the memory location with address 300 contains 50.
i) LDM #200
ii) LDD 200
iii) LDI 200 Label Opcode
Operand
LDD
b) Write an assembly language instruction to: number1
i) compare the accumulator with 5 SUB
ii) jump to address 100 if the comparison is true number2
ADD
2. a) Create a symbol table for the assembly program on the right starting at address 100. number3
b) Complete a trace table for the program on the right. CMP
#10
c) State the task that this program performs.
JPE
nomore
3. a) Using the assembly language program provided, write an assembly ADD
language program to output the ASCII character of each element of an array number4
of four elements. nomore: STO
total
b) Produce a symbol table for your algorithm. Assume that the translated END
program will begin at memory address 100.
c) Complete a trace table to show the execution of your algorithm. number1: #30
number2: #40

You might also like