Presentation is loading. Please wait.

Presentation is loading. Please wait.

Microprocessors and microcontrollers

Similar presentations


Presentation on theme: "Microprocessors and microcontrollers"— Presentation transcript:

1 Microprocessors and microcontrollers
Digital technics review and programming last modified: Feb 25.

2 II.2. Instruction set (processor)
Instruction set: the set of instructions a processor knows in hardware Machine code: a program containing instructions from the instruction set, in binary or hexadecimal format. It can generally be natively run by the processor (without the need for other software).

3 Instruction set, programming
Assembly: lowest level programming language, processor dependent. It is made by assigning easy to remember words (mnemonics) to machine code instructions; make easier data and number formatting; make labels and constants available; make some simple functions

4 Instruction set, programming
Software originally written in other programming languages have to be converted to machine code using a compiler (in older times, by hand). For very high level languages it can involve several middle steps. Question: in what language and machine are compilers written?

5 Programming languages

6 Low level languages Nearest to hardware,
thus easiest to compile to machine code, best for optimizing hardware resource usage. Generally assembly languages are in this category.

7 Assembly Practically a readable version of machine code
Takes lot of time and effort to realize complex functions (of course code parts can be reused) Hard to overview, find bugs – needs lots of comment Can directly access hardware, can utilize all special functions of hardware and special cpu/gpu instructions Code can be made small in size, small in memory footprint, fast to run, optimized for hardware

8 Assembly More suited for small programs, for low-end hardware, for microcontrollers and embedded systems with special needs Eg. military or space uses – small memory, low speed, have to be very reliable Compilers (esp.in older times) often in asm Some of op.system’s special functions in asm But possible to write whole graphical modern op system in asm (see eg. Menuet OS)

9 Medium level languages
eg. C (though often put in other categories) developed before microprocessors, developed for programming Unix operating system integral part of Unix and Linux systems often used to write opsystems and compilers „mother” of many modern prog.languages less special data types; pointers used for strings and arrays; can use pointers of pointers and chaines lists etc. can change data type of an existing variable (without conversion) allows to give value inside a condition (eg. if(a=b) and if(a==b) both are allowed!)

10 Higher level languages
In high level languages simple instructions can realize complex jobs closer to human languages and logic easier, more special data types easier, faster to develop and debug, easier to overview though sometimes finding a bug needs looking at the asm/machine code, if the bug is hardware-dependent

11 Higher level languages
High level languages: Fortran, Algol, Cobol, Basic, Pascal, Python, Perl, PHP, Ruby, C#, Java,... Easy to learn, to program, to overview Modern version often give help to create graphical user interface (GUI) (Visual Basic, Visual C, etc) Compiled code potentially larger and/or slower than if using C or asm Often need „runtime engine” and larger hardware req. (eg. dotnet,java) Less chance for syntax errors or algorithm errors, but harder to find errors related to compiler, opsys or hw.

12 Special high level languages
Windowed system development Visual Basic / C / whatever program's visual elements (windows, buttons etc.) are placed in a graphical UI; traditional program code is written for each element

13 Visual C#

14 Special high level languages
Dataflow programming LabView, VEE, Simulink program's visual elements created in GUI, the corresponding code is also created in a GUI in the form of a flowchart Labwindows CVI form of Labview, in which you can put traditional "typed" code

15 Labview

16 Special high level languages
Mathematical, logical MatLab, Maple, Mathematica R, S (statistics) Coq (theorem proving), SML (?),Haskell (?)

17 Coq

18 Special high level languages
Scripting languages for small, quick tasks often built into op system (esp.Unix/Linux) or built into / support markup language (PHP, Javascript, Flash, Java) often started as simple script languages, but in the end, can do more than that (most of the above languages) Markup and supporting languages (often not „real” programming, more like data formats) HTML / CSS

19 Portability of source code
Portable code can be compiled (without modification or with little modification) on other hardware or op system this needs an existing compiler for that hardware (needs not to be compiled on target HW (cross compilation) different HW might not need exactly the same SW... (Win8 on PC and tablet ??)

20

21 Readability „Read-only programming language” (easy to read, hard to write) „Write only programming language” (easy to write, hard to read) And then this... ide ábrát a conway gameről

22 Programming languages
interpreted compiled to machine code to bytecode mixed (intermediate) runtime compiled

23 Operating system Technically not necessary – programs can be run without it – but it is not convenient to do so Opsys allow us to: provide user interface (UI) to load stored programs easily (it needs not be graphical (GUI) – even a command line is a huge help vs the original computers) provides application programming interface (API) – makes programming easier and portable

24 Operating system provides a layer btw HW and user SW
when changing HW, only Driver software changed, but end-user SW sees the same API API can be a library of a programming language or a function call the opsys provides BIOS is „first part” of opsys (but is independent), it also provides some simple function calls opsys can allow for multitasking – it has to keep track of running processes and allocate their cpu time; also helps allocating multi-processor jobs

25 Instruction set example
Intel 8085A 8 bit data bus, 16 bit address bus few MHz clock its instruction set was the basis for the 8086 and then x86 series processors it is also similar to many current 8b microcontrollers

26 8085 Instruction types arithmetics: add, subtract, increment
logics: and, or, xor, complement (negate) bitwise: rotate (as in a shift register) data moving: move, exchange, push,pop branch: jump, call, return conditional: jump on condition (jz,jnz,jc, etc) IO: in, out

27 8085 addressing modes example
mov r1,r2 1 byte, 1 machine cycle, r2r1 mov r,M 1 byte, 2 m.cycle, (HL)r HL register pair contains memory address mov M,r 1 byte, 2 m.cycle, r(HL) mvi r, data 2 byte (code+data), 2 m.cycles, datar mvi M,data 2 byte (code+data), 3 m.cycle, data(HL) lxi rp,data 3 byte (code+2byte data), 3 m.cycle, datarp (register pair)

28 8085 addressing modes example
lda addr 3 byte (code+2byte address), 4 m.cycle, (addr)A memory cell’s content into accumulator (A) sta addr 3 byte, 4 m.cycle, A(addr) lhdl addr 3 byte, 5 m.cycle, (addr)HL memory word (2B) at address addr into HL register pair shld addr 3 byte, 5 m.cycle, HL(addr) ldax rp 1 byte, 2m.cycle, (rp)A memory cell addressed by BC or DE into A stax rp 1 byte, 2 m.cycle, A(rp) xchg 1 byte, 1 m.cycle, HL<=>DE exchange contents of register pairs

29 Data formats

30 Number systems Most computers store and process numbers in a binary form Users mostly see decimal form, programmers use decimal, hexadecimal (base 16), or less frequently octal and binary forms

31 Number systems Some notation examples: Decimal: Hexadecimal: Binary
D’223’ , 223D, 223D, Hexadecimal: H’2F’, h2F, 2Fh, 0x2F, 2F16 Binary B’ ’, b ,

32 Number systems Decimal to binary conversion:
Divide by two, repeat with int(result), read the remainders from bottom up (NB last remainder / first digit is always 1) Binary to decimal conversion: Sum up the powers of two where the binary digit is 1

33 Number systems Hexadecimal (base 16):
0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F digits One digit can be translated to 4 bits, so an 8bit number (byte) will always be two hexa digits: 3Ah= b

34 Integer numbers Unsigned integer (uint) Signed integer (int)
possible storing formats: sign bit two’s complement – this one is most popular offset binary, excess-K range in abs.value is halved

35 Sign bit format first bit is sign 01010011b=83d 11010011b=-83d
range: there are two zeros ( , ) problem when counting harder to add numbers

36 Two’s complement Take binary number, invert and add 1
easier to do addition simply add like unsigned int try adding a number with its 2’s c. ! comparison problem: negative numbers appear larger than positive range in 8 bit: first bit 1: negative, 0: zero or positive only one zero, good for counting

37 Offset binary add 2^(n-1) to binary number
first part of range negative, middle is zero, upper part positive practically same as two’s compl. but first bit inverted easier comparison

38 Numbers larger than data bus width
Eg. 8b system and I want to use 16b long numbers Of course it is possible, just takes more time Eg. addition: first add least significant bytes (LSB), result is LSB of end result, generates Carry flag bit add next two bytes, add carry bit to it (special add with carry instructions may be available) and so on

39 Fractional numbers Fixed point Floating point Traditional fraction

40 Fixed point practically store as an integer (eg. when there are no floating point capabilities) n bit: total number of digits m: original number f: number of two’s fractional digits

41 Floating point s: sign b: base (2) c: significant digits
q: exponent (2’s complement or offset)

42 IEEE745 (floating point standard)
first significant digit is always 1 -> no need to store, thus eg. out of 24b we need to store 23 (remaining bit can be sign) special values: +0 , -0, +inf , -inf , NaN, subnormal NaN (not a number): exp all 1, rest not 0 inf (infinite): exp all 1, rest 0

43 IEEE745 (floating point) Single precision: 32b (24+8)
approx decimal digit precision exponent format: add 127-et, thus (offset binary) max: (2−2−23) × 2127 ≈ × 1038 Double precision: 64b (53+11) approx. 16 decimal digits precision

44 Storing multi-byte numbers
word: a number (or piece of data) made up of multiple bytes generally two types of storage/transmission method: little endian LSB (least significant byte) first, it is stored at lowest address easier hardware for addition (starts with LSB) big endian MSB (most significant byte) stored at lowest address

45 Storing multi-byte numbers
Little endian: Intel-AMD x86, x86-64 series Big endian: Motorola descendants AVR32 IBM System/360, z/Architecture Internet Protocol (IP, TCP, UDP) Bi-endian (configurable): ARM 3-tól, PowerPC, Alpha, MIPS, Itanium etc. May find this problem in communications (eg. connect PC to a data acquisition device) image source:

46 Arrays, strings Array: realization of a matrix
Various support in hw. and sw. String: a variable containing several characters; a character chain, a 1D array (vector) containing characters

47 Arrays Hardware support:
scalar processors: access one element at a time; access by pointers pointer hw. support: certain machine code instructions can use certain cpu registers to access RAM (register contains memory address, register is the pointer); pointer can also be in RAM vector processor: SIMD: single instruction, multiple data; one instruction processes an array

48 Characters Alphanumerical characters are stored by using a table to turn them into numbers; eg. BCDIC,ASCII,Unicode,

49 ASCII American Standard Code for Information Interchange
originally 7b coding, 8.bit could be parity if needed thus 128 characters available 95 printable char. (lowercase, uppercase alphabet, numbers, punctuation) 32 control char. (for teletypes,printers) (incl. new line, carriage return, end of line, end of file, tab, del, space, etc.) lowercase and uppercase differ in one bit only (easier conversion) numbers contain the number in binary (last four bits)

50 ASCII

51 ASCII Extensions the 8.bit is used, thus another 128 characters
(too) many versions exist ("code pages") include accented characters, non-latin alphabets, graphical characters eg. Code page 437 (IBM PC); ISO 8859-x software can change between the code pages try not to use these in file names or as serial communication control characters

52 Unicode Made to be able to express most of the world's writing systems. Currently contains 136,690 characters, 139 scripts (alphabets) (even emojis) Includes modifier characters (eg. n~ => ñ), also joining characters for ligatures etc. Codes often referred in form U+20AC (4 bytes hexadecimal)

53 Unicode encodings UTF-8 variable width encoding: 1 to 4 bytes
Today the dominant encoding on WWW First 128 characters same as ASCII 2 byte form includes Latin-based, Greek, Cyrillic, Arabic, Hebrew, Armenian etc. 4 byte form includes all characters (only 21 bits used)

54 Unicode encodings UTF-16 UTF-32 variable length, 2bytes or 2x2bytes
used by eg. Windows 2000 and above UTF-32 fixed length, 4 bytes (21 bits are used for code points)

55 Arrays Software support:
possible solution: a pointer shows the base address, ie. the first element of the array, we can give an offset to this eg. int *array is a pointer to memory address xyz, which contains first element of array; in array[i] i means the offset array[0] thus points to base address+0, ie. first element; array[5] points thus to sixth element therefore in many languages (eg. C and similar), arrays start with 0 index

56 Arrays multi-dimensional arrays:
if the language supports only 1D array: create a vector (1D array) the elements of which are also pointers, all pointing to vectors themselves, thus a 2D array is made addressing will be eg. array[i][j]

57 Other

58 Parallel execution legend:
„Parallel portion”: how many percent of code can be parallelized Not everything can be! Vertical axis: how many times faster the execution could be in ideal case


Download ppt "Microprocessors and microcontrollers"

Similar presentations


Ads by Google