Presentation is loading. Please wait.

Presentation is loading. Please wait.

Assignment 7 Sample Problems. Boolean Expressions and Machine Language Write a Boolean Expression and Machine Language code corresponding to Expression.

Similar presentations


Presentation on theme: "Assignment 7 Sample Problems. Boolean Expressions and Machine Language Write a Boolean Expression and Machine Language code corresponding to Expression."— Presentation transcript:

1 Assignment 7 Sample Problems

2 Boolean Expressions and Machine Language Write a Boolean Expression and Machine Language code corresponding to Expression tree A OR c AND B

3 Solution Boolean Expression Reading from top: boolean expression = ( Left-tree expression) AND (Right tree expression) AND Left TreeRight Tree

4 What's Left Tree and Right Tree Reading from Top, Left Tree A OR C AND Right Tree B

5 Solution (Continued) Left-tree expression = A or B Right-tree expression = C From slide 3, boolean-expression= (Left-tree expression) and (Right-tree expression) boolean-expression = (A or B) and C

6 Assembly Code acc= A acc=acc OR B acc=acc AND C

7 Boolean Expressions and Machine Language Write a Boolean Expression and Machine Language code corresponding to Expression tree A NOT B OR

8 Solution Boolean Expression Reading from top: boolean expression = ( Left-tree expression) OR (Right tree expression) OR Left TreeRight Tree

9 What's Left Tree and Right Tree Left Tree A NOT B OR Right Tree

10 Solution (Continued) Left-tree expression = NOT A Right-tree expression = NOT B From slide 8, boolean-expression= (Left-tree expression) OR (Right-tree expression) boolean-expression = NOT A or NOT B

11 Assembly Code acc=NOT A E= acc (There are two operations OR and NOT left, so,store acc temporarily) acc=NOT B acc=acc or E Note: Cannot write, acc=not A E = acc or not B (This is wrong!. OR and NOT are two operations).

12 Boolean Expressions and Machine Language A B NOT AND A B NOT OR Write a Boolean Expression and Machine Language code corresponding to Expression tree

13 Solution Boolean Expression Reading from top: boolean expression = ( Left-tree expression) OR (Right tree expression) OR Left TreeRight Tree

14 What's Left tree, Right Tree? A B NOT AND A B NOT OR Left Tree Right Tree

15 Left-Tree Expression A B NOT AND Another Left- Tree Another Right-Tree Reading from Top of Left Tree: left-tree expression = (Another Left-tree) AND (Another Right-tree) = A and (NOT B)

16 Right-Tree Expression Yet-Another Left-Tree Yet-Another Right-Tree Reading from Top of Right Tree: right-tree expression = (Yet-Another Left-tree) AND (Yet-Another Right- tree) = (NOT A) and B AND A B NOT

17 Combining Left Tree and Right Tree From Slide 13 boolean expression = (Left-tree expression) OR (Right-tree expression) From Slide 15, 16 Left-tree expression = A and NOT B Right-tree expression = NOT A and B Writing everything down together Boolean Expression = (A and NOT B) OR (NOT A and B)

18 Machine Language Code acc=NOT B acc=acc AND A E=acc acc=NOT A acc=acc AND B acc=acc OR E (Note: See that the operations at top of tree come at last)

19 Scratch (Am I in order)

20 Solution Checks if the list L is in ascending order. If it is, say Yes!, Otherwise say No!

21 Scratch (I have 100?)

22 Solution Checks if the List contains 100. If it has 100, says “Yes” and stops. If 100 is not in list, says “No” and stops

23 Scratch(Me and the last one)

24 Solution ● Check if any number in the list is same as the last number. If it is, then say Yes!. Say No! Otherwise.

25 Scratch(Me and the last one)

26 Solution ● Check if any number in the list is same as the last number. If it is, then say Yes!. Say No! Otherwise.

27 Scratch Lists Predict what List has at the end of Execution

28 Solution (Step 1)

29 Solution (Step 2)

30 Solution (Step 3)

31 Solution (Step 4)

32 Solution (Step 5)

33 Solution (Step 6) Now we are Done!

34 More Lists What is in List at the end of execution

35 Solution Hint: delete last deletes the last element in the list.

36 Solution Hint: delete-last deletes the last element in the list.


Download ppt "Assignment 7 Sample Problems. Boolean Expressions and Machine Language Write a Boolean Expression and Machine Language code corresponding to Expression."

Similar presentations


Ads by Google