The Stack & Procedures CSE410, Winter 2017, Lecture notes of Artificial Intelligence

The document covers topics related to the stack and procedures in computer science, including calling conventions, register saving conventions, and recursion. It also includes examples of data flow and return values. Additionally, the document briefly mentions homework and lab deadlines, a midterm exam, and a review session. The document could be useful as study notes or lecture notes for a computer science course on the stack and procedures, possibly at Carnegie Mellon University or a similar institution. The typology of the document is 'lecture notes'.

Typology: Lecture notes

2021/2022

Uploaded on 05/11/2023

captainamerica
captainamerica šŸ‡ŗšŸ‡ø

4.4

(13)

250 documents

1 / 34

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSE410, Winter 2017L12: The Stack & Procedures
TheStack&Procedures
CSE410Winter2017
Instructor: TeachingAssistants:
JustinHsia KathrynChan,KevinBi,RyanWong,WaylonHuang,Xinyu Sui
AIDecisivelyDefeatsHumanPokerPlayers
Libratus lived up to its ā€œbalanced but forcefulā€ Latin name by becoming the first AI to
beat professional poker players at heads-up, no-limit Texas Hold'em. Developed by
Carnegie Mellon University, the AI won the ā€œBrains Vs. Artificial Intelligenceā€
tournament against four poker pros by $1,766,250 in chips over 120,000 hands (games).
Researchers can now say that the victory margin was large enough
to count as a statistically significant win (99.7 percent certainty).
Libratus focuses on improving its own play, [described] as safer
and more reliable compared to the riskier approach of trying to
exploit opponent mistakes.
•http://spectrum.ieee.org/automaton/robotics/
artificial‐intelligence/ai‐learns‐from‐mistakes‐to‐defeat‐human‐poker‐players
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22

Partial preview of the text

Download The Stack & Procedures CSE410, Winter 2017 and more Lecture notes Artificial Intelligence in PDF only on Docsity!

CSE410, Winter 2017

L12: The Stack & Procedures

The Stack & Procedures CSE 410 Winter 2017 Instructor:

Teaching Assistants:

Justin Hsia

Kathryn Chan, Kevin Bi, Ryan Wong, Waylon Huang, Xinyu Sui

AI Decisively Defeats Human Poker Players Libratus lived up to its ā€œbalanced but forcefulā€ Latin name by becoming the first AI tobeat professional poker players at heads-up, no-limit Texas Hold'em. Developed byCarnegie Mellon University, the AI won the ā€œBrains Vs. Artificial Intelligenceā€tournament against four poker pros by $1,766,250 in chips over 120,000 hands (games).Researchers can now say that the victory margin was large enoughto count as a statistically significant win (99.7 percent certainty).Libratus focuses on improving its own play, [described] as saferand more reliable compared to the riskier approach of trying toexploit opponent mistakes. •^

http://spectrum.ieee.org/automaton/robotics/artificial‐intelligence/ai‐learns‐from‐mistakes‐to‐defeat‐human‐poker‐players

CSE410, Winter 2017

L12: The Stack & Procedures

Administrivia^ 

Homework 3 released today, due next Thu (2/9)



Lab 2 deadline pushed to Monday (2/13)^ ļ‚§

Definitely want to start before the Midterm



Midterm

(2/10) in lecture

Reference sheet + 1

handwritten

cheat sheet

Find a study group! Look at past exams!

Aiming for average of 75%



Midterm review session

(2/7) in BAG 261 from

5‐7:30pm

CSE410, Winter 2017

L12: The Stack & Procedures

Procedure Data Flow^ Registers

(NOT in Memory)

Stack

(Memory)



First 6 arguments



Return value

%rdi%rsi%rdx%rcx%r8%r

Arg

- • • Arg

Arg

n

- • •

HighAddresses

LowAddresses 0x00…

Di

ane’s

Si

lk

D

ress

C

osts

Only allocate stackspace when needed

%rax

CSE410, Winter 2017

L12: The Stack & Procedures

x86‐64 Return Values^ 

By convention, values returned by procedures areplaced in

%rax

Choice of

%rax

is arbitrary

1) Caller must make sure to save the contents of

%rax

before calling a callee that returns a value^ ļ‚§

Part of register‐saving convention

2) Callee places return value into

%rax

Any type that can fit in 8 bytes – integer, float, pointer, etc.

For return values greater than 8 bytes, best to return a pointer

to them

3) Upon return, caller finds the return value in

%rax

CSE410, Winter 2017

L12: The Stack & Procedures

Procedures^ 

Stack Structure



Calling Conventions^ ļ‚§

Passing control

Passing data

Managing local data



Register Saving Conventions



Illustration of Recursion

CSE410, Winter 2017

L12: The Stack & Procedures

Stack‐Based Languages^ 

Languages that support recursion^ ļ‚§

e.g.

C, Java, most modern languages

Code must be

re‐entrant

-^

Multiple simultaneous instantiations of single procedure

Need some place to store

state

of each instantiation

-^

Arguments, local variables, return pointer



Stack allocated in

frames

State for a single procedure instantiation



Stack discipline^ ļ‚§

State for a given procedure needed for a limited time^ •

Starting from when it is called to when it returns

Callee always returns before caller does

CSE410, Winter 2017

L12: The Stack & Procedures

1) Call to

yoo

%rbp%rsp

Stack

yoo

yoo(…){

  • • who();• • }

yoo who amI amI amI

amI

CSE410, Winter 2017

L12: The Stack & Procedures

yoo(…){

  • • who();• • }

2) Call to

who

who(…){

  • amI();• amI();• }

Stack

yoo who

%rbp%rsp

yoo who amI amI amI

amI

CSE410, Winter 2017

L12: The Stack & Procedures

yoo(…){

  • • who();• • }

who(…){

  • amI();• amI();• }

amI(…){

if(){

amI() }

4) Recursive call to

amI

amI(…){

if(){

amI() }

Stack

yoo who amI

1

amI

2

%rbp%rsp

yoo who amI amI amI

amI

CSE410, Winter 2017

L12: The Stack & Procedures

yoo(…){

  • • who();• • }

who(…){

  • amI();• amI();• }

amI(…){

if(){

amI() }

amI(…){

if(){

amI() }

(another)

Recursive call to

amI

amI(…){

if(){

amI() }

Stack

yoo who amI

1

amI

2

amI

3

%rbp%rsp

yoo who amI amI amI

amI

CSE410, Winter 2017

L12: The Stack & Procedures

yoo(…){

  • • who();• • }

who(…){

  • amI();• amI();• }

amI(…){

if(){

amI() }

7) Return from recursive call to

amI

yoo who amI amI amI

amI

Stack

yoo who amI

1

%rbp%rsp

CSE410, Winter 2017

L12: The Stack & Procedures

yoo(…){

  • • who();• • }

who(…){

  • amI();• amI();• }

8) Return from call to

amI

yoo who amI amI amI

amI

Stack

yoo who

%rbp%rsp

CSE410, Winter 2017

L12: The Stack & Procedures

yoo(…){

  • • who();• • }

who(…){

  • amI();• amI();• }

10) Return from

(second)

call to

amI

yoo who amI amI amI

amI

Stack

%rbp%rsp

yoo who

CSE410, Winter 2017

L12: The Stack & Procedures

11) Return from call to

who

yoo(…){

  • • who();• • }

yoo who amI amI amI

amI

Stack

%rbp%rsp

yoo