Presentation is loading. Please wait.

Presentation is loading. Please wait.

Machine code Recall that all a computer recognises is binary code.

Similar presentations


Presentation on theme: "Machine code Recall that all a computer recognises is binary code."— Presentation transcript:

1 Machine code Recall that all a computer recognises is binary code.
We now know that 0s and 1s can represent different things and so far have looked at representing numbers. 0s and 1s also represent machine instructions: That is, binary digits that represent the program in such a way that the processor can run it. The software instructions which make the hardware work. These machine instructions relate to a single processor, e.g. ARM Intel

2 central heating system
ARM inside… eReader Lego® Mindstorms® robot tablet smartphone smart glasses camera fitness band Raspberry Pi® Key points: Huge range of portable and mobile devices have ARM processors. ARM processors also used for embedded applications in cars, homes, hospitals, etc. digital TV car washing machine games console central heating system

3 Programming in machine code
The first programmers had to program in machine code. Binary code representing instructions Programming at the hardware level (the machine), the lowest level. Problems? Slow. Error-prone. Hard to remember. Each machine code is for a single machine.

4 Assembly language Uses mnemonics
i.e. abbreviations to represent the instructions, e.g. MOV – move data CMP – compare values Then following the instruction, the data is referenced: MOV R3, #5 which instructs the machine to move 5 to register 3. This is still low level in terms of accessing hardware. Key points: Huge range of portable and mobile devices have ARM processors. ARM processors also used for embedded applications in cars, homes, hospitals, etc.

5 Machine code versus assembly language
MOV R0, #2 SUB R1, R3, #10 ADD R0, R0, R1 MUL R3, R4, R5 For reference: This code was assembled with "armasm --debug --cpu=6” MOV  r0,#2 SUB   r1,r3,#0xa ADD   r0,r0,r1 MUL   r3,r4,r5

6 Programming in assembly language
It is easier to program in assembly language than machine code. But: Still error-prone. Difficult to debug. Hard to learn.

7 High level programming languages
As computer science developed and hardware became more available, there was a need to write programs faster. High level programming languages were developed to do this. The first ones were more suited to specific applications, e.g. FORTRAN – scientific COBOL – commercial Java is an example of a modern high level programming language.

8 Characteristics of high level programming languages
More ‘English-like’ Less error-prone Easier to debug Quicker to write Can work on different machines (transportable)

9 Assembling an algorithm
Java Assembly language start Total = 0 MOV R0, # // Count For (int count=0; count<10; count++) MOV R1, # // Increment value loop System.out.println(count) ADD R0, R0, R // Count=Count + inc. CMP R1, #A // Check loop cond. BNE loop // Branch if not finished BL print // Call println() For reference: This is one of several ways the assembler could have implemented the algorithm. Alternatives would be compare with 5 and use the Equal To or Less Than condition, or to count down towards zero. Pupils don’t need to know this, but counting down to zero would usually be the most efficient approach. By using the ‘SUBS’ instruction to decrement the loop counter, the processor would check for a zero result as part of the operation, removing the need for the CMP instruction and thus saving one instruction execution per iteration of the loop. A prime objective of assembly language programming is to improve the speed of execution by eliminating unnecessary instructions. The inputs to a subroutine get passed in registers R0 to R3, and the return value (if any) is stored in R0 at the end of the subroutine.

10 Why bother coding in assembly language?
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. it’s fun! Key points: Majority of code produced to run a smartphone won’t be written in assembly language, but the ‘mission critical’ bits will be. A compiler can never produce as efficient code as a programmer writing in assembly language who really understands how the processor works.


Download ppt "Machine code Recall that all a computer recognises is binary code."

Similar presentations


Ads by Google