DOC PREVIEW
CMU CS 15213 - Arithmetic & Control

This preview shows page 1-2-3-22-23-24-45-46-47 out of 47 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 47 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Carnegie Mellon Carnegie Mello Machine Level Programming II Arithmetic Control 15 213 Introduction to Computer Systems 5th Lecture Sep 7 2010 Instructors Randy Bryant and Dave O Hallaron 1 Carnegie Mello Today Complete addressing mode address computation leal Arithmetic operations Control Condition codes Conditional branches While loops 2 Carnegie Mello Complete Memory Addressing Modes Most General Form D Rb Ri S Mem Reg Rb S Reg Ri D D Rb Ri Constant displacement 1 2 or 4 bytes Base register Any of 8 integer registers Index register Any except for esp Unlikely you d use ebp either S Scale 1 2 4 or 8 why these numbers Special Cases Rb Ri Mem Reg Rb Reg Ri D Rb Ri Mem Reg Rb Reg Ri D Rb Ri S Mem Reg Rb S Reg Ri 3 Carnegie Mello Address Computation Examples edx 0xf000 ecx 0x0100 Expression Address Computation Address 0x8 edx 0xf000 0x8 0xf008 edx ecx 0xf000 0x100 0xf100 edx ecx 4 0xf000 4 0x100 0xf400 0x80 edx 2 2 0xf000 0x80 0x1e080 4 Carnegie Mello Address Computation Instruction leal Src Dest Src is address mode expression Set Dest to address denoted by expression Uses Computing addresses without a memory reference E g translation of p x i Computing arithmetic expressions of the form x k y k 1 2 4 or 8 Example int int mul12 int mul12 int x x return return x 12 x 12 Converted to ASM by compiler leal leal sall sall eax eax 2 eax eax 2 eax eax 2 2 eax eax t t x x 2 x x 2 return return t 2 t 2 5 Carnegie Mello Today Complete addressing mode address computation leal Arithmetic operations Control Condition codes Conditional branches While loops 6 Carnegie Mello Some Arithmetic Operations Two Operand Instructions FormatComputation addl Src Dest Dest Dest Src subl Src Dest Dest Dest Src imull Src Dest Dest Dest Src sall Src Dest Dest Dest Src sarl Src Dest Dest Dest Src shrl Src Dest Dest Dest Src xorl Src Dest Dest Dest Src andl Src Dest Dest Dest Src orl Src Dest Dest Dest Src Also called shll Arithmetic Logical Watch out for argument order No distinction between signed and unsigned int why 7 Carnegie Mello Some Arithmetic Operations One Operand Instructions incl decl negl notl Dest Dest Dest Dest Dest Dest Dest Dest Dest 1 Dest 1 Dest Dest See book for more instructions 8 Carnegie Mello Arithmetic Expression Example arith pushl ebp esp ebp int int arith int arith int x x int int y y int int z z movl movl 8 ebp ecx int int t1 t1 x y x y movl 12 ebp edx int int t2 t2 z t1 z t1 leal edx edx 2 eax int int t3 t3 x 4 x 4 sall 4 eax int int t4 t4 y y 48 48 leal 4 ecx eax eax int int t5 t5 t3 t3 t4 t4 addl ecx edx int int rval rval t2 t2 t5 t5 addl 16 ebp edx return return rval rval imull edx eax popl ret Set Up Body ebp Finish 9 Carnegie Mello Understanding arith int int arith int arith int x x int int y y int int z z int int t1 t1 x y x y int int t2 t2 z t1 z t1 int int t3 t3 x 4 x 4 int int t4 t4 y y 48 48 int int t5 t5 t3 t3 t4 t4 int int rval rval t2 t2 t5 t5 return return rval rval movl movl leal sall leal addl addl imull 8 ebp ecx 12 ebp edx edx edx 2 eax 4 eax 4 ecx eax eax ecx edx 16 ebp edx edx eax Offset 16 z 12 y 8 x 4 Rtn Addr 0 Old ebp ebp 10 Carnegie Mello Understanding arith int int arith int arith int x x int int y y int int z z int int t1 t1 x y x y int int t2 t2 z t1 z t1 int int t3 t3 x 4 x 4 int int t4 t4 y y 48 48 int int t5 t5 t3 t3 t4 t4 int int rval rval t2 t2 t5 t5 return return rval rval movl movl leal sall leal addl addl imull 8 ebp ecx 12 ebp edx edx edx 2 eax 4 eax 4 ecx eax eax ecx edx 16 ebp edx edx eax Offset ecx edx eax eax eax edx edx eax Stack 16 z 12 y 8 x 4 Rtn Addr 0 Old ebp x y y 3 16 t4 t4 x 4 t5 x y t1 z t2 t2 t5 rval ebp 11 Carnegie Mello Observations about arith Instructions in different order int int arith int arith int x x int int y y int int z z int int t1 t1 x y x y int int t2 t2 z t1 z t1 int int t3 t3 x 4 x 4 int int t4 t4 y y 48 48 int int t5 t5 t3 t3 t4 t4 int int rval rval t2 t2 t5 t5 return return rval rval movl movl leal sall leal addl addl imull 8 ebp ecx 12 ebp edx edx edx 2 eax 4 eax 4 ecx eax eax ecx edx 16 ebp edx edx eax ecx edx eax eax eax edx edx eax from C code Some expressions require multiple instructions Some instructions cover multiple expressions Get exact same code when compile x y z x 4 48 y x y y 3 16 t4 t4 x 4 t5 x y t1 z t2 t2 t5 rval 12 Carnegie Mello Another Example logical pushl ebp movl esp ebp int int logical int logical int x x int int y y int int t1 t1 x y x y int int t2 t2 t1 t1 17 17 int int mask mask 1 13 1 13 7 7 int int rval rval t2 t2 mask mask return return rval rval movl xorl sarl andl 12 ebp eax 8 ebp eax 17 eax 8185 eax movl xorl sarl andl 12 ebp eax 8 ebp eax 17 eax 8185 eax popl ebp ret eax eax eax eax Set Up Body Finish y x y t1 t1 17 t2 t2 mask rval 13 Carnegie Mello Another Example logical pushl ebp movl esp ebp int int logical int logical int x x int int y y int int t1 t1 x y x y int int t2 t2 t1 t1 17 17 int int mask mask 1 13 1 13 7 7 int int rval rval t2 t2 mask mask return return rval rval movl xorl sarl andl 12 ebp eax 8 ebp eax 17 eax 8185 eax movl xorl sarl andl 12 ebp eax 8 ebp eax 17 eax 8185 eax popl ebp ret eax eax eax eax Set Up Body Finish y x y t1 t1 17 t2 t2 mask rval 14 Carnegie Mello Another Example logical pushl ebp movl esp ebp int int logical int logical int x x int int y y int int t1 t1 x y x y int int …


View Full Document

CMU CS 15213 - Arithmetic & Control

Documents in this Course
lecture

lecture

14 pages

lecture

lecture

46 pages

Caches

Caches

9 pages

lecture

lecture

39 pages

Lecture

Lecture

36 pages

Lecture

Lecture

45 pages

Lecture

Lecture

56 pages

lecture

lecture

11 pages

lecture

lecture

9 pages

Lecture

Lecture

36 pages

Lecture

Lecture

37 pages

Exam

Exam

16 pages

Lecture

Lecture

10 pages

Lecture

Lecture

43 pages

Lecture

Lecture

8 pages

Lecture

Lecture

8 pages

Lecture

Lecture

36 pages

Lecture

Lecture

43 pages

Lecture

Lecture

12 pages

Lecture

Lecture

37 pages

Lecture

Lecture

6 pages

Lecture

Lecture

40 pages

coding

coding

2 pages

Exam

Exam

17 pages

Exam

Exam

14 pages

Lecture

Lecture

29 pages

Lecture

Lecture

34 pages

Exam

Exam

11 pages

Lecture

Lecture

9 pages

Lecture

Lecture

37 pages

Lecture

Lecture

36 pages

lecture

lecture

46 pages

Lecture

Lecture

33 pages

Lecture

Lecture

57 pages

Lecture

Lecture

32 pages

Lecture

Lecture

46 pages

Lecture

Lecture

40 pages

Lecture

Lecture

11 pages

Lecture

Lecture

6 pages

Lecture

Lecture

43 pages

Lecture

Lecture

12 pages

Lecture

Lecture

18 pages

Exam

Exam

10 pages

Lecture

Lecture

45 pages

Lecture

Lecture

37 pages

Exam

Exam

24 pages

class09

class09

21 pages

class22

class22

37 pages

class20

class20

30 pages

class27

class27

33 pages

class25

class25

21 pages

class04

class04

31 pages

Lecture

Lecture

59 pages

class01a

class01a

14 pages

class12

class12

45 pages

class29

class29

33 pages

Lecture

Lecture

39 pages

Lecture

Lecture

6 pages

class03

class03

34 pages

lecture

lecture

42 pages

Lecture

Lecture

40 pages

Lecture

Lecture

47 pages

Exam

Exam

19 pages

R06-B

R06-B

25 pages

class17

class17

37 pages

class25

class25

31 pages

Lecture

Lecture

15 pages

final-f06

final-f06

17 pages

Lecture

Lecture

9 pages

lecture

lecture

9 pages

Exam

Exam

15 pages

Lecture

Lecture

22 pages

class11

class11

45 pages

lecture

lecture

50 pages

Linking

Linking

37 pages

Lecture

Lecture

64 pages

Integers

Integers

40 pages

Exam

Exam

11 pages

Lecture

Lecture

37 pages

Lecture

Lecture

44 pages

Lecture

Lecture

37 pages

Lecture

Lecture

9 pages

Lecture

Lecture

37 pages

Lecture

Lecture

45 pages

Final

Final

25 pages

lecture

lecture

9 pages

Lecture

Lecture

30 pages

Lecture

Lecture

16 pages

Final

Final

17 pages

Lecture

Lecture

8 pages

Exam

Exam

11 pages

Lecture

Lecture

47 pages

Lecture

Lecture

9 pages

lecture

lecture

39 pages

Exam

Exam

11 pages

lecture

lecture

41 pages

lecture

lecture

37 pages

Lecture

Lecture

59 pages

Lecture

Lecture

45 pages

Exam 1

Exam 1

18 pages

Lecture

Lecture

41 pages

Lecture

Lecture

32 pages

Lecture

Lecture

30 pages

Lecture

Lecture

9 pages

Lecture

Lecture

9 pages

Lecture

Lecture

15 pages

Lecture

Lecture

11 pages

Lecture

Lecture

9 pages

Lecture

Lecture

34 pages

Lecture

Lecture

40 pages

Lecture

Lecture

4 pages

Lecture

Lecture

46 pages

Lecture

Lecture

8 pages

Lecture

Lecture

65 pages

Lecture

Lecture

38 pages

Lecture

Lecture

35 pages

Lecture

Lecture

8 pages

Lecture

Lecture

34 pages

Lecture

Lecture

8 pages

Exam

Exam

13 pages

Lecture

Lecture

43 pages

Lecture

Lecture

9 pages

Lecture

Lecture

12 pages

Lecture

Lecture

9 pages

Lecture

Lecture

34 pages

Lecture

Lecture

43 pages

Lecture

Lecture

7 pages

Lecture

Lecture

45 pages

Lecture

Lecture

24 pages

Lecture

Lecture

47 pages

Lecture

Lecture

12 pages

Lecture

Lecture

20 pages

Lecture

Lecture

9 pages

Exam

Exam

11 pages

Lecture

Lecture

52 pages

Lecture

Lecture

20 pages

Exam

Exam

11 pages

Lecture

Lecture

35 pages

Lecture

Lecture

47 pages

Lecture

Lecture

18 pages

Lecture

Lecture

30 pages

Lecture

Lecture

59 pages

Lecture

Lecture

37 pages

Lecture

Lecture

22 pages

Lecture

Lecture

35 pages

Exam

Exam

23 pages

Lecture

Lecture

9 pages

Lecture

Lecture

22 pages

class12

class12

32 pages

Lecture

Lecture

8 pages

Lecture

Lecture

39 pages

Lecture

Lecture

44 pages

Lecture

Lecture

38 pages

Lecture

Lecture

69 pages

Lecture

Lecture

41 pages

Lecture

Lecture

12 pages

Lecture

Lecture

52 pages

Lecture

Lecture

59 pages

Lecture

Lecture

39 pages

Lecture

Lecture

83 pages

Lecture

Lecture

59 pages

class01b

class01b

17 pages

Exam

Exam

21 pages

class07

class07

47 pages

Lecture

Lecture

11 pages

Odyssey

Odyssey

18 pages

multicore

multicore

66 pages

Lecture

Lecture

6 pages

lecture

lecture

41 pages

lecture

lecture

55 pages

lecture

lecture

52 pages

lecture

lecture

33 pages

lecture

lecture

46 pages

lecture

lecture

55 pages

lecture

lecture

17 pages

lecture

lecture

49 pages

Exam

Exam

17 pages

lecture

lecture

56 pages

Exam 2

Exam 2

16 pages

Exam 2

Exam 2

16 pages

Notes

Notes

37 pages

Lecture

Lecture

40 pages

Lecture

Lecture

36 pages

Lecture

Lecture

43 pages

Lecture

Lecture

25 pages

Exam

Exam

13 pages

Lecture

Lecture

32 pages

Lecture

Lecture

12 pages

Lecture

Lecture

58 pages

Lecture

Lecture

29 pages

Lecture

Lecture

59 pages

Lecture

Lecture

41 pages

Lecture

Lecture

50 pages

Exam

Exam

17 pages

Lecture

Lecture

29 pages

Lecture

Lecture

44 pages

Lecture

Lecture

41 pages

Lecture

Lecture

52 pages

Lecture

Lecture

40 pages

Lecture

Lecture

33 pages

lecture

lecture

10 pages

Lecture

Lecture

27 pages

Lecture

Lecture

29 pages

Lecture

Lecture

39 pages

Lecture

Lecture

9 pages

Lecture

Lecture

29 pages

Lecture

Lecture

8 pages

Lecture

Lecture

43 pages

Lecture

Lecture

43 pages

Lecture

Lecture

75 pages

Lecture

Lecture

55 pages

Exam

Exam

12 pages

Lecture

Lecture

43 pages

Lecture

Lecture

35 pages

lecture

lecture

36 pages

Exam

Exam

33 pages

lecture

lecture

56 pages

lecture

lecture

64 pages

lecture

lecture

8 pages

Exam

Exam

14 pages

Lecture

Lecture

43 pages

Lecture

Lecture

36 pages

lecture

lecture

56 pages

lecture

lecture

75 pages

lecture

lecture

36 pages

Lecture

Lecture

50 pages

Lecture

Lecture

45 pages

Lecture

Lecture

13 pages

Exam

Exam

23 pages

Lecture

Lecture

10 pages

Lecture

Lecture

48 pages

Lecture

Lecture

83 pages

lecture

lecture

57 pages

Lecture

Lecture

33 pages

Lecture

Lecture

39 pages

Lecture

Lecture

33 pages

lecture

lecture

54 pages

Lecture

Lecture

30 pages

Exam

Exam

13 pages

Lecture

Lecture

36 pages

Lecture

Lecture

40 pages

Exam

Exam

17 pages

Lecture

Lecture

9 pages

Exam

Exam

15 pages

Lecture

Lecture

44 pages

Lecture

Lecture

34 pages

Lecture

Lecture

24 pages

Lecture

Lecture

29 pages

class12

class12

43 pages

lecture

lecture

43 pages

class22

class22

22 pages

R06-B

R06-B

25 pages

class01b

class01b

19 pages

lecture

lecture

29 pages

lab1

lab1

8 pages

Caches

Caches

36 pages

lecture

lecture

55 pages

Lecture,

Lecture,

37 pages

Integers

Integers

40 pages

Linking

Linking

38 pages

lecture

lecture

45 pages

Lecture

Lecture

61 pages

Linking

Linking

33 pages

lecture

lecture

40 pages

lecture

lecture

40 pages

Lecture

Lecture

32 pages

lecture

lecture

48 pages

lecture

lecture

44 pages

Exam

Exam

11 pages

Lecture

Lecture

31 pages

Lecture

Lecture

46 pages

Lecture

Lecture

40 pages

Lecture

Lecture

40 pages

Exam

Exam

12 pages

Lecture

Lecture

42 pages

Lecture

Lecture

36 pages

Lecture

Lecture

45 pages

Lecture

Lecture

41 pages

Lecture

Lecture

13 pages

Lecture

Lecture

35 pages

Lecture

Lecture

20 pages

Final

Final

19 pages

Lecture

Lecture

33 pages

Lecture

Lecture

50 pages

Lecture

Lecture

33 pages

Lecture

Lecture

27 pages

Lecture

Lecture

6 pages

Exam

Exam

15 pages

Lecture

Lecture

24 pages

Lecture

Lecture

23 pages

Lecture

Lecture

43 pages

Lecture

Lecture

32 pages

Lecture

Lecture

52 pages

Lecture

Lecture

37 pages

Lecture

Lecture

36 pages

Lecture

Lecture

34 pages

Lecture

Lecture

40 pages

Lecture

Lecture

15 pages

lecture

lecture

21 pages

Lecture

Lecture

58 pages

Lecture

Lecture

49 pages

Lecture

Lecture

36 pages

Lecture

Lecture

11 pages

Lecture

Lecture

12 pages

Lecture

Lecture

58 pages

Lecture

Lecture

33 pages

Exam

Exam

15 pages

Lecture

Lecture

35 pages

Lecture

Lecture

10 pages

Lecture

Lecture

25 pages

Lecture

Lecture

31 pages

Lecture

Lecture

24 pages

Lecture

Lecture

34 pages

Lecture

Lecture

50 pages

lecture

lecture

35 pages

Lecture

Lecture

11 pages

Lecture

Lecture

39 pages

Lecture

Lecture

45 pages

Lecture

Lecture

41 pages

exam1-f05

exam1-f05

11 pages

Lecture

Lecture

4 pages

Lecture

Lecture

17 pages

Exam

Exam

17 pages

malloc()

malloc()

12 pages

Lecture

Lecture

57 pages

Lecture

Lecture

30 pages

Lecture

Lecture

30 pages

Lecture

Lecture

47 pages

Lecture

Lecture

33 pages

Exam

Exam

12 pages

Lecture

Lecture

43 pages

Lectures

Lectures

33 pages

Lecture

Lecture

36 pages

lecture

lecture

33 pages

Exam

Exam

14 pages

Lecture

Lecture

43 pages

Lecture

Lecture

25 pages

Load more
Download Arithmetic & Control
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Arithmetic & Control and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Arithmetic & Control and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?