Pathway Introduction: Information Technology

Pathway Introduction: Information Technology

Function Memory Memory Memory: Text Segment : Code Data Segment : Global variables / constants Stack Segment : Temporary storage Memory Up Close Variables with global duration in .data: Static Storage Static c++ vars: Allocated at start of program Assembly static storage for "function":

Static Storage Static Pros: Simple Static Storage Static Pros: Simple Static Cons: Allocated if we need or not Allocated for entire run of the program Only one copy of memory for function Non-reenterant Stack Frame Linkage Local Variables Alternative:

Stack based temporary storage as needed for functions Local Variables Stack Frame / Activation Record: memory for one function call Detail View Stack Frame Context for function Parameters Local variables Book keeping Stored registers & Return address Start of previous frame

-0x0 -0x4 -0x8 -0xC foo's frame return address num a Local Variables Components located relative to bottom of frame -0x0 +0xCfoo's numframe -0x4 address

+0x8return a -0x8 +0x4num return address -0xC +0x0 afoo's frame Local Variables Stack Pointer can move during function not a fixed reference -0x0 foo's frame +0xC -0x4 num return address +0x8 a

-0x8 return num address +0x4 -0xC foo's a frame +0x0 Local Variables Frame Pointer Fixed reference point to bottom of current stack frame +0xC foo's numframe -0x0 +0x8 return a -0x4

address +0x4 num return address -0x8 +0x0 afoo's frame -0xC What Goes In Registers we may mess up r4+ FP LR (if needed) Parameters Local variables Updated Call Convention Caller

Save r0-r3 if you care about them Put arguments in r0-r3, BL Prolog Save r4+ if you will use Push callers fp Push your lr Set frame pointer Move sp to make space on stack for locals/params Store params from registers to frame

Updated Call Convention Epilog Put return values in r0-r3 Reset stack pointer to remove locals Pop all saved registers Including fp and possibly lr Return (MOV PC, LR) Regain Control Get return values from r0 Pop any r0-r3 registers you saved Sample Sample Function: Has two local variables Each is 4 bytes

Prolog 0x1020 ??? 0x1024 ??? 0x1028 ??? 0x102C ??? 0x1030 ??? sp 0x1034 Existing Stack Frame Setup: Prolog 0x1020 ???

0x1024 ??? 0x1028 ??? sp 0x102C old fp 0x1030 my lr 0x1034 Existing Stack Frame Setup: Push callers fp, your lr Prolog 0x1020 ??? 0x1024 ???

0x1028 ??? sp 0x102C old fp 0x1030 my lr 0x1034 Existing Stack Frame Setup: Push callers fp, your lr Push r4+ if you will use This function doesn't Prolog 0x1020 ??? 0x1024 ???

0x1028 ??? sp 0x102C old fp fp 0x1030 my lr 0x1034 Existing Stack Frame Setup: Push callers fp, your lr Push r4+ if you will use Set fp to start of this frame Stack Frame Prolog 0x1020

??? sp 0x1024 ??? 0x1028 ??? 0x102C old fp fp 0x1030 my lr 0x1034 Existing Stack Frame Setup: Push callers fp, your lr

Push r4+ if you will use Set fp to start of this frame Allocate params/locals This needs 8 bytes Prolog 0x1020 ??? sp 0x1024 ??? 0x1028 num 0x102C old fp fp 0x1030 my lr 0x1034 Existing Stack

Frame Setup: Push callers fp, your lr Push r4+ if you will use Set fp to start of this frame Allocate params/locals Copy params to stack frame Prolog 0x1020 ??? sp 0x1024 ???

0x1028 num 0x102C old fp fp 0x1030 my lr 0x1034 Existing Stack Params / Locals accessed as fp + offset Ordering set by compiler Using the Frame 0x1020 ??? sp 0x1024 a 0x1028

num 0x102C old fp fp 0x1030 my lr 0x1034 Existing Stack Every variable read/write must take place on stack Registers only temporary Using the Frame 0x1020 ??? sp 0x1024 a 0x1028 num

0x102C old fp fp 0x1030 my lr 0x1034 Existing Stack Get value Do math Store result Using the Frame 0x1020 ??? sp 0x1024 a 0x1028 num 0x102C

old fp fp 0x1030 my lr 0x1034 Existing Stack Get value Do math Store result Using the Frame 0x1020 ??? sp 0x1024 a 0x1028 num 0x102C old fp

fp 0x1030 my lr 0x1034 Existing Stack Get value Do math Store result Using the Frame 0x1020 ??? sp 0x1024 a 0x1028 num 0x102C old fp fp 0x1030

my lr 0x1034 Existing Stack Get value Do math Store result Using the Frame 0x1020 ??? sp 0x1024 a 0x1028 num 0x102C old fp fp 0x1030 my lr

0x1034 Existing Stack Get value Do math Store result Using the Frame 0x1020 ??? sp 0x1024 a 0x1028 num 0x102C old fp fp 0x1030 my lr 0x1034 Existing Stack

Get value Do math Store result Epilog 0x1020 ??? sp 0x1024 a 0x1028 num 0x102C old fp fp 0x1030 my lr 0x1034 Existing Stack

Cleanup Put return in r0+ Epilog 0x1020 ??? 0x1024 a 0x1028 num sp 0x102C old fp fp 0x1030 my lr 0x1034 Existing Stack Cleanup

Put return in r0+ Remove locals/params By moving stack pointer Epilog 0x1020 ??? 0x1024 a 0x1028 num 0x102C old fp 0x1030 my lr sp 0x1034 Existing Stack

Cleanup Put return in r0+ Remove locals/params Restore old fp and our lr Wipes out our fp Epilog 0x1020 ??? 0x1024 a 0x1028 num 0x102C old fp 0x1030 my lr

sp 0x1034 Existing Stack Cleanup Put return in r0+ Remove locals/params Restore old fp and our lr Return Function as Caller & Callee Functions call each other Lifecycle: Prolog Set up stack frame Do work Call others? Set up call Regain control

Do Work Epilog Clean up stack frame Return Call Stack closeEnough calls abs: closeEnough 0x1010 ??? 0x1014 ??? 0x1018 ??? 0x101C ??? 0x1020

??? 0x1024 ??? 0x1028 ??? 0x102C ??? 0x1030 ??? sp 0x1034 Existing Stack closeEnough is called closeEnough 0x1010 ??? 0x1014 ???

0x1018 ??? sp 0x101C diffMagnitude 0x1020 diff 0x1024 y 0x1028 x 0x102C old fp fp 0x1030 closeEnough lr 0x1034 Existing Stack Builds frame, stores params closeEnough 0x1010

??? 0x1014 ??? 0x1018 ??? sp 0x101C diffMagnitude 0x1020 diff 0x1024 y 0x1028 x 0x102C old fp fp 0x1030 closeEnough lr 0x1034 Existing Stack Does work

closeEnough 0x1010 ??? 0x1014 ??? 0x1018 ??? sp 0x101C diffMagnitude 0x1020 diff 0x1024 y 0x1028 x 0x102C old fp fp 0x1030 closeEnough lr

0x1034 Existing Stack Calls abs abs 0x1010 sp 0x1014 0x1018 0x101C 0x1020 0x1024 0x1028 0x102C fp 0x1030 0x1034 ??? old fp(0x1030)

abs lr diffMagnitude diff y closeEnough x old fp closeEnough lr Existing Stack abs stores old fp with current lr abs 0x1010 sp 0x1014 fp 0x1018 0x101C 0x1020

0x1024 0x1028 0x102C 0x1030 0x1034 ??? old fp(0x1030) abs abs lr diffMagnitude diff y closeEnough x old fp closeEnough lr Existing Stack

Now safe to update fp abs sp 0x1010 0x1014 fp 0x1018 0x101C 0x1020 0x1024 0x1028 0x102C 0x1030 0x1034 x old fp(0x1030) abs abs lr diffMagnitude

diff y closeEnough x old fp closeEnough lr Existing Stack abs makes space for x and loads param into it abs sp 0x1010 0x1014 fp 0x1018 0x101C 0x1020 0x1024 0x1028

0x102C 0x1030 0x1034 x old fp(0x1030) abs abs lr diffMagnitude diff y closeEnough x old fp closeEnough lr Existing Stack after work is done, put x in r0

abs 0x1010 sp 0x1014 fp 0x1018 0x101C 0x1020 0x1024 0x1028 0x102C 0x1030 0x1034 x old fp(0x1030) abs abs lr diffMagnitude diff y

closeEnough x old fp closeEnough lr Existing Stack pop locals/params abs 0x1010 0x1014 0x1018 sp 0x101C 0x1020 0x1024 0x1028 0x102C fp 0x1030

0x1034 x old fp(0x1030) abs lr diffMagnitude diff y closeEnough x old fp closeEnough lr Existing Stack popping fp retores pointer in old frame Notes All variables allocated up front:

Even if all can't be used!!! 0x1014 ??? sp 0x1018 a 0x101C b 0x1020 c 0x1024 b 0x1028 x 0x102C my lr fp 0x1030 old fp 0x1034 Existing Stack

Notes Arrays / struct / objects on stack allocated as block: 0x1014 ??? sp 0x1018 nums[0] 0x101C nums[1] 0x1020 nums[2] 0x1024 nums[3] 0x1028 arg 0x102C my lr

fp 0x1030 old fp 0x1034 Existing Stack Real World Compilers may each build frames differently Compilers may omit steps if optimizing Skip saving link register if do not call other functions Skip saving frame pointer Skip loading/storing from stack Extra/large parameters placed on stack by caller Recursion Recursive procedure Calls itself factorial(4)

Step 0: executes factorial(4) Step 9: return 24 return 4 * factorial(3) Step 1: executes factorial(3) Step 8: return 6 return 3 * factorial(2) Step 2: executes factorial(2) Step 7: return 2 return 2 * factorial(1) Step 6: return 1 Step 3: executes factorial(1)

return 1 * factorial(0) Step 4: executes factorial(0) Step 5: return 1 return 1 Recursion Each call has own stack frame: 0x1000 ??? sp 0x1004 nextValue 0x1008 n 0x100C old fp fp 0x1010 my lr

0x1014 nextValue 0x1018 n 0x101C old fp 0x1020 my lr 0x1024 nextValue 0x1028 n 0x102C old fp 0x1030 my lr 0x1034 Existing Stack fact(2)

factorial(4) Step 0: executes factorial(4) Step 9: return 24 return 4 * factorial(3) Step 1: executes factorial(3) Step 8: return 6 fact(3) return 3 * factorial(2) Step 2: executes factorial(2) Step 7: return 2 return 2 * factorial(1)

Step 6: return 1 fact(4) Step 3: executes factorial(1) return 1 * factorial(0) Step 4: executes factorial(0) Step 5: return 1 return 1

Recently Viewed Presentations

  • OHRMD's Organizational Learning presents: - dhr.state.ga.us

    OHRMD's Organizational Learning presents: - dhr.state.ga.us

    If you are at the OHRMD Computer Training webpage, click on the link that reads "GA DHR Learning Portal (Self Registration)" If you are NOT at our webpage… lms.dhr.state.ga.us Open the Internet browser if not already open. Then click in...
  • EOR-Knowledge Base (KB) Screening/Design Tool

    EOR-Knowledge Base (KB) Screening/Design Tool

    FSI. Slightly relaxed approach. Conservative approach. It is all about confidence building after meeting the workflow checklist items? Decision. ... - Provide GIS interface with locations of EOR projects worldwide with details on the map including adding new ones on...
  • Race to The Top: Early Learning Challenge Grant

    Race to The Top: Early Learning Challenge Grant

    Coaching & Mentoring Inclusion Project Provide coaching & mentoring to programs serving children (3-5 years of age) who have an IEP/IFSP Project 3 Expand the language program, VIOLETS, to 150 classrooms in MD EXCELS Develop a Guide to Early Childhood...
  • Traditional Origin Accounts

    Traditional Origin Accounts

    Pushed and separated the two for another 18,000 years. Sky, Earth, and Pangu all grew. Assisted by four animals: Dragon, Turtle, Phoenix, and Qilin. The death of Pangu completes the Earth. Pangu died after 18,000 years of hard labor.
  • Animal Organ Systems - BruceAg

    Animal Organ Systems - BruceAg

    Monogastric - 1 stomach - can't digest cellulose (fiber) - pigs and humans Ruminant - 4 stomachs - polygastric - digest cellulose, produce own B vitamins and proteins - cows and sheep Pseudo-ruminant - have 1 stomach, but have enlarged...
  • 2015 Legislative Update for Law Enforcement 02/11/2020 1

    2015 Legislative Update for Law Enforcement 02/11/2020 1

    Conflicts of Interest Act (con't.) HB2070/SB1424. Requires the CA to initiate civil proceedings against persons who knowingly provide a gift after applying for or receiving a grant or loan under the Commonwealth's Development Opportunity Fund.
  • Approaching question 2 - scott.k12.ky.us

    Approaching question 2 - scott.k12.ky.us

    THE PROMPT LIMITS THE RESPONSE TO ONE PASSAGE - a hint at tone? In the following passage from Cormac McCarthy's novel The Crossing (1994), the narrator describes a dramatic experience.. In the following passage from . The Spectator (March 4,...
  • Point of Care Research

    Point of Care Research

    Early introduction of Point of Care Research to regulatory/oversight thought leaders to plan the way forward. Consider implementation requirements - from single site with highly engaged research personnel using in-person informed consent to national rollout. Conduct focus groups of providers...