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

Assembly Language

This document discusses assembly language programming. It explains that machine code is the only language CPUs can understand, but writing programs in machine code is time-consuming and error-prone. Assembly language was developed to make programming easier by using mnemonics instead of binary. Assembly language instructions closely mirror the machine code instructions of the specific CPU. The document outlines different assembly language instruction types and addressing modes. It provides examples of assembly language code, including a counter program.

Uploaded by

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

Assembly Language

This document discusses assembly language programming. It explains that machine code is the only language CPUs can understand, but writing programs in machine code is time-consuming and error-prone. Assembly language was developed to make programming easier by using mnemonics instead of binary. Assembly language instructions closely mirror the machine code instructions of the specific CPU. The document outlines different assembly language instruction types and addressing modes. It provides examples of assembly language code, including a counter program.

Uploaded by

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

Assembly Language Programming

Assembly Language & Machine Code


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

Every different type of computer/chip has its own set of machine code
instructions.
• 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.
Assembly Language & Machine Code
• The first programming language to be developed was assembly language,
Assembly Language Programming

this is closely related to machine code and uses mnemonics instead of


binary.
Assembly Language & Machine Code
• The structure of assembly language and machine code instructions is the
Assembly Language Programming

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.
Assembly Language Instructions
• Data movement instructions These instructions allow data stored at one
Assembly Language Programming

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.
Assembly Language Instructions
Assembly Language Programming
Assembly Language Instructions
Input and output of data instructions
Assembly Language Programming

• These instructions allow data to be read from the keyboard or output to


the screen.
Assembly Language Instructions
Arithmetic operation instructions
Assembly Language Programming

These instructions perform simple calculations on data stored in the


accumulator and store the answer in the accumulator, overwriting the original
data.
Assembly Language Instructions
Compare Instructions
Assembly Language Programming
Assembly Language Instructions
Unconditional and conditional Instructions
Assembly Language Programming
Assembly Language Instructions
Unconditional and conditional Instructions
Assembly Language Programming
Addressing Modes
• Assembly language and machine code programs use different addressing
Assembly Language Programming

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.
Addressing Modes
Indirect addressing
Assembly Language Programming

• 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.
Addressing Modes
Immediate addressing
Assembly Language Programming

• 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
Addressing Modes
Symbolic addressing
Assembly Language Programming

• 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
Assembly Language Instructions – Example1
Assembly Language Programming

• LDD 103 the value 110 is loaded into the accumulator


• LDI 106 the value 208 from address 101 is loaded into the accumulator
• STO 106 the value 208 is stored in address 106
• LDD INDEXVALUE the value 3 is loaded into the accumulator
• MOV IX the value 3 from the accumulator is loaded into the index register
• LDX 102 the value 206 from address 105 is loaded into the accumulator
Assembly Language Instructions – Example 2
Assembly Language Programming

• LDD 105 the value 0001 0001is loaded into the accumulator
• LDX 101 content of index register converted into 3 , 101+3 =104, content of
104 0101 1101 is placed in the Accumulator.
• LDI 103 memory address of 103 contains the 107, so the content of 107,
1100 001 is placed in the accumulator.
Assembly Language Instructions – Example 3
Assembly Language Programming
Assembly Language Instructions – Example 4
Assembly Language Programming
Assembly Language Instructions – Example 3
Assembly Language Programming
Assembly Language Code – COUNTER
Assembly Language Programming

• Write an assembly language


program for the following MOV R0, #0
algorithm loop:
• Move #0 in to register 0
ADD R0, R0, #1
• Create a label called ‘loop’
B loop
• Add the values in register 0, #1
HLT
• Store in register 0
• Branch to the label loop.
COUNTER with Control
• Write an assembly language
Assembly Language Programming

program for the following


algorithm MOV R0, #0
• Move #0 in to register 0 loop:
• Create a label called ‘loop’ ADD R0, R0, #1
• Add the values in register 0, #1 CMP R0, #10
• Store in register 0 BNE loop
• Compare register 0 with #10 HLT
• Branch Not equal to the label
loop.
COUNTER with Control
Write an assembly language
Assembly Language Programming

program for the following


algorithm. MOV R0, #11
CMP R0, #10
INPUT number BGT GREATER
If number > 10 then B END
0UTPUT 1 GREATER:
ENDIF MOV R1, #1
END:
HLT
Assembly Language Programming
Data Movement with label
Assembly Language Programming
Data Movement with label
Data movement with label
Complete the trace table for the following assembly language program.
Assembly Language Programming
Data movement with label
Complete the trace table for the following assembly language program.
Assembly Language Programming

You might also like