Download presentation
Presentation is loading. Please wait.
Published byMaurice Charles Modified over 6 years ago
1
GCSE COMPUTER SCIENCE Computers 1.5 Assembly Language
2
Processor Families There are two families of processor, each family has a different instruction set. X86 Family ARM Family Use in most laptops, desktop and servers. Use in most smartphones and tablets. Watch this video to find out more about the ARM family of processors.
3
Machine Code Each type of CPU is designed to carry out a set of specific instructions. Each instruction is represented by binary number. This is called machines code. Machine Code Assembly Language MOV R0, #2 SUB R1, R3, #10 ADD R0, R0, R1 MUL R3, R4, R5 It is hard for humans to read and write machines code so assembly language was developed to make it easier.
4
Python Assembly language is an example of a low-level language. An advantage of low-level languages is it allows you to have direct control of the CPU. Python is an example of a high-level language. An advantage of high level language is that it is closely resembles natural language. High-level language instructions represent several CPU instructions, unlike machine code and assembly language.
5
Assembly Language (Low-level)
Activity 1 Draw and match the phrase to the correct part of the diagram. sum1 = num1 + num2 sum2 = num1 * num2 Compiler Assembler ADD R0, R0, R1 MUL R3, R4, R5 Machine Code Assembly Language (Low-level) Python (High-level)
6
Activity 2 Copy and match each assembly instruction with the correct action: ADD Load from memory address into a register SUB Branch to a marked position in the program MUL Move data to a register MOV Store data in a register CMP Subtract data in a register LDR Compare values in a register B Multiply data in a register STR Add data in a register
7
Instruction Format ADD R0, R1, #5 MOV R0, #5 SUB R2, R2, R4
This is the standard format for writing instructions in assembly language. opcode operand ADD R0, R1, #5 MOV R0, #5 SUB R2, R2, R4 operation destination input input
8
Example MOV R3, #5 SUB R1, R1, #2 MUL R0, R1, R3 ADD R1, R1, R0
Moves the value 5 into register location 3. MOV R3, #5 Register R0 30 R1 8 R2 R3 5 R4 6 36 Subtracts 2 from the value in R1 and stores the result in R1. SUB R1, R1, #2 Multiplies the values in R1 and R3 and stores the result in R0. MUL R0, R1, R3 Add the value in R1 to the value in R0 and stores the result in R1. ADD R1, R1, R0
9
What does this instruction ask the processor to do?
Activity 3 Label the assembly language instruction to show the opcode, destination and two input operands. opcode SUB R0 R1 R2 destination Input(s) QUESTION What does this instruction ask the processor to do?
10
Moves the value 1 into Register 5.
Activity 4 Test what you have learnt so far by answering these questions: Question Answer Write the instruction to add the value 8 to the contents of register R2 and store the result in register R4. ADD R4, R2, #8 Write the instruction to multiply the contents of register R1 by the contents of register R2 and store the result in register R0. MUL Ro, R1, R2 What does this instructions ask the processor to do? MOV R5, #1 Moves the value 1 into Register 5.
11
Show the contents of the registers as each instruction is executed:
Activity 5 Show the contents of the registers as each instruction is executed: Hint: the MOV command actually puts a copy of the data in the specified register. The original stays where it is. R0 R1 R2 5 3 MOV R0, R1 MOV R1, R2
12
Activity 6 Show the contents of the registers as each instruction is executed: Show the contents of the registers as each instruction is executed: Hint: the MOV command actually puts a copy of the data in the specified register. The original stays where it is. R0 R1 R2 9 5 3 MOV R0, #0 ADD R0, R0, R1 SUB R0, R0, R2 2 MUL R0, R1, R2 15
13
Show the contents of the registers as each instruction is executed:
Activity 7 Show the contents of the registers as each instruction is executed: R0 R1 R2 4 2 MUL R0, R1, R2 MUL R1, R0, R2 8 16 v
14
Show the contents of the registers as each instruction is executed:
Activity 8 Show the contents of the registers as each instruction is executed: R0 R1 R2 7 5 SUB R0, R1, #3 4 ADD R2, R2, #1 6 SUB R0, R1, R2 1
15
Conditions CMP R0, R1 ADD EQ R0, R0, #5,
This is the standard format for writing instructions in assembly language. CMP R0, R1 Codes EQ equal NE not equal GT greater than LT less than GE greater or equal to LE less than or equal to ADD EQ R0, R0, #5, opcode operands condition These instructions compare the values in R0 and R1, if they are equal the value 5 will added be to the value in R0 and the result will be stored in R0.
16
Activity 9 Explain what this piece of code does: CMP R0, R1
MOVGT R2, R0 Compares the values in R0 and R1. Moves R0 into R2 if R0 is Greater Than R2. Explain what each line of this code does: MOV R0, #5 Moves the value 5 into R0. MOV R2, #6 Moves the value 6 into R2. CMP R0, R2 Compares the values in R0 and R1. MOVEQ R3, R0 Moves R0 in R3 if they are equal. MOVNE R3, R2 Moves R2 into R3 if the values are not equal.
17
Activity 10 What will be the outcome of executing this piece of code if register R0 holds the value 9 and register R1 holds the value 15? CMP R0, R1 SUBGT R0, R1, R0 SUBLT R0, R1, R0 Compares the value of R1 (15) with R0 (9). If R0 is > R1 subtract R0 from R1 and stores in R0. False. If R0 is < R1 subtract R0 from R1 and store in R1. True, so 15-9 = 6. What will be the outcome of executing this piece of code if register R0 held the value 3 and register R1 held the value 3? CMP R0, R1 ADDGT R0, R0, R1 ADDLT R1, R1, R0 Compares the value of R0 (3) with R1 (3). If R1 is > R0 Add R1 to R0 and store in R0. False. If R0 is < R1 Add R0 to R1 and store in R1. False.
18
Activity 11 There are two methods of converting high-level code to machine code. Carry out some research and find a definition for each one. Compiler A compiler translates the whole program into machine code before the program is run. It can be difficult to test individual lines of compiled code compared to interpreted languages as all bugs are reported after the program has been compiled. Java and C++ are compiled programming languages. Interpreter An interpreter translates code into machine code, instruction by instruction - the CPU executes each instruction one at a time. Interpreted code will show an error as soon as it hits a problem, so it is easier to debug than compiled code. Interpreted code is slower to execute than compiled code. Interpreted languages include JavaScript, PHP, Python and Ruby.
19
Why Bother? Most software is NOT written in assembly language because:
It’s time-consuming to develop; It’s not portable across different types of processors. BUT, assembly language is useful because: It enables programmers to write very efficient, performance-critical code; It gives you a better insight into how the processor works; It can be used to debug code that isn’t working as expected.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.