Presentation is loading. Please wait.

Presentation is loading. Please wait.

COS 151 Bootcamp – Week 4 Department of Computer Science

Similar presentations


Presentation on theme: "COS 151 Bootcamp – Week 4 Department of Computer Science"— Presentation transcript:

1 COS 151 Bootcamp – Week 4 Department of Computer Science
01 June 2019

2 CH09: Programming Languages
int i = 15; int j = 25; i = i + j; high-level Assembly machine code

3 Assembly and Machine Code
( F )16 STORE M40 <— RF

4 Convert the following binary machine code into hexadecimal
Exercise 1.1 Convert the following binary machine code into hexadecimal ( )2 ( )2 ( )2 ( )2

5 Convert the following binary machine code into hexadecimal
Exercise 1.1 — Solution Convert the following binary machine code into hexadecimal ( )2 ( )2 ( )2 ( )2 ( A D )16 ( )16 ( )16 ( E B )16

6 Exercise 1.2 ( 1 0 A D )16 ( 3 0 0 0 )16 ( 3 0 0 0 )16 ( 2 E B 0 )16
Derive the corresponding Assembly code from the table ( A D )16 ( )16 ( )16 ( E B )16

7 Exercise 1.2 — Solution ( 1 0 A D )16 ( 3 0 0 0 )16 ( 3 0 0 0 )16
Derive the corresponding Assembly code from the table ( A D )16 ( )16 ( )16 ( E B )16 LOAD R0 <— MAD ADDI R0 <— R0 + R0 ADDI R0 <— R0 + R0 STORE MEB <— R0

8 Exercise 1.3 LOAD R0 <— MAD ADDI R0 <— R0 + R0
Let 3 be the value stored in MAD. Which will be the value stored in MEB when the Assembly program terminates? LOAD R0 <— MAD ADDI R0 <— R0 + R0 ADDI R0 <— R0 + R0 STORE MEB <— R0

9 The value 9 will be stored in MEB
Exercise 1.3 — Solution Let 3 be the value stored in MAD. Which will be the value stored in MEB when the Assembly program terminates? LOAD R0 <— MAD ADDI R0 <— R0 + R0 ADDI R0 <— R0 + R0 STORE MEB <— R0 The value 9 will be stored in MEB

10 Exercise 2 LOAD R2 <— MBA LOAD R7 <— MFE OR R1 <— R2 OR R7
Convert the following Assembly program first into hexadecimal, then into binary machine code LOAD R2 <— MBA LOAD R7 <— MFE OR R1 <— R2 OR R7 STORE MBA <— R1

11 Exercise 2 — Solution LOAD R2 <— MBA LOAD R7 <— MFE
Convert the following Assembly program first into hexadecimal, then into binary machine code LOAD R2 <— MBA LOAD R7 <— MFE OR R1 <— R2 OR R7 STORE MBA <— R1 ( B A )16 ( F E )16 ( )16 ( B A )16

12 Exercise 2 — Solution ( 1 2 B A )16 ( 1 7 F E )16 ( 8 1 2 7 )16
Convert the following Assembly program first into hexadecimal, then into binary machine code ( B A )16 ( F E )16 ( )16 ( B A )16 ( )2 ( )2 ( )2 ( )2

13 Section 2: High-Level Language Java

14 Variables in Java A variable has:
a data type e.g. boolean, int, string, a name e.g. b, x, s and a value e.g. true, 42, “Hello World” Declaration of variables: boolean b = true; int x = 42; String s = “Hello”; Operations on variables: b = b && true; x = 8 * 10; s = “Hello”+”World”;

15 Basic Operators

16 Exercise 3

17 Exercise 3 — Solution true -14 ab 9 8

18 Conditional Statements

19 Conditional Statements — Example

20 Exercise 4

21 Exercise 4 — Solution Output: 1 3 5 7 9 11 13 15 17 19
20 executions of the while-loop

22 Exercise 4 — Solution first two numbers along the sequence are fixed to 1 and 1 other numbers are sum of its two predecessors

23 Exercise 5

24 Exercise 5 — Solution

25 CH11: Data Structures link data NODE arrays linked lists records

26 Arrays An array has: a data type e.g. boolean, int, string,
a name e.g. b, x, s a length e.g. 3, x.length and a value e.g. {true, false, true}, {1, 2, 3}, {“Hello”, “ ”, “World”}

27 Arrays Declaration of arrays: int x[]; //declaring array
x = new int[10]; // allocating memory to array OR int[] x = new int[10]; //combining both in one Explicit initialisation of arrays: x = new int[]{ 1, 2, 3, 4, 5, 6, 7, 8 }; x[2] = 13; Accessing an element of an array: System.out.println(x[5]); positions of array x range from 0 to x.length-1

28 Arrays — Example

29 Exercise 6

30 Exercise 6 — Solution

31 Multi-Dimensional Arrays
Declaration: int[][] x = new int[3][5]; int[][][] y = new int[5][3][7]; Explicit initialisation of multi-dimensional arrays: x = new int[][] { {1, 2, 3, 4, 5}, {6, 7, 8, 9, 0}, {3, 2, 1, 0, 7} }; Accessing an element of a multi-dimensional array: System.out.println(x[2][4]); //outputs 7 Length of multi-dimensional array: x.length = 3, x[0].length = 5

32 Multi-Dimensional Arrays — Example
Output: program subtracts elements of y from elements of x and stores results as elements of z

33 Exercise 7

34 Exercise 7 — Solution Output: 25 20 15 10 5 24 19 14 9 4 23 18 13 8 3
program mirrors content of the array along the diagonal line

35 Matrix Multiplication based on Arrays
Result: 28 10 73 28

36 Exercise 8 Modify the program part with the red dots such that A and B get correctly multiplied

37 Exercise 8 — Solution

38 Records a record is a collection of related elements
of possibly different types elements of a record are called fields example: record student with fields id, name and grade of different types record declaration, access of fields: student a; a.name = “George”; array of records: student b[400];

39 Records — Example

40 Linked Lists linked list is a data structure consisting of a series of nodes each node stores data item link to the next node link link data NODE LINKED LIST L HEAD CURRENT TAIL null pointer A B C D NULL

41 Basic Operations on Linked Lists

42 Exercise 9 — Determine Output

43 Exercise 9 — Solution Content of l: [A, X, D, H, Z]
Content of l: [A, X, Z, Y, B] Content of l: [A, U, G, Z, Y, B]

44 COS 151 End of Bootcamp – Week 4 Department of Computer Science
01 June 2019


Download ppt "COS 151 Bootcamp – Week 4 Department of Computer Science"

Similar presentations


Ads by Google