<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Operating_Systems_2019F_Lecture_9</id>
	<title>Operating Systems 2019F Lecture 9 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Operating_Systems_2019F_Lecture_9"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2019F_Lecture_9&amp;action=history"/>
	<updated>2026-05-18T21:41:56Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2019F_Lecture_9&amp;diff=22485&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Video==  Video from the lecture given on October 2, 2019 [https://homeostasis.scs.carleton.ca/~soma/os-2019f/lectures/comp3000-2019f-lec09-20191002.m4v is now available].  =...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2019F_Lecture_9&amp;diff=22485&amp;oldid=prev"/>
		<updated>2019-10-03T17:29:15Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Video==  Video from the lecture given on October 2, 2019 [https://homeostasis.scs.carleton.ca/~soma/os-2019f/lectures/comp3000-2019f-lec09-20191002.m4v is now available].  =...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
Video from the lecture given on October 2, 2019 [https://homeostasis.scs.carleton.ca/~soma/os-2019f/lectures/comp3000-2019f-lec09-20191002.m4v is now available].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 9&lt;br /&gt;
---------&lt;br /&gt;
&lt;br /&gt;
Trying to explain assembly code!&lt;br /&gt;
&lt;br /&gt;
Key concepts&lt;br /&gt;
* saving and loading of registers from stack&lt;br /&gt;
* call/ret&lt;br /&gt;
* passing arguments&lt;br /&gt;
* using base pointer register for local variables&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When you enter a function, you save any registers that you will clobber&lt;br /&gt;
 - they are saved by pushing them on the stack&lt;br /&gt;
 - they must be popped when the function exits&lt;br /&gt;
 - register save/restore (like any instruction) can be optimized away&lt;br /&gt;
&lt;br /&gt;
Registers are marked by a %&lt;br /&gt;
Constant values are marked by a $&lt;br /&gt;
&lt;br /&gt;
The stack pointer contains the current &amp;quot;top&amp;quot; of the stack (note that the stack grows down in memory).&lt;br /&gt;
&lt;br /&gt;
The base pointer contains the value of the stack pointer as it was&lt;br /&gt;
at the start of the function.&lt;br /&gt;
&lt;br /&gt;
We use the base pointer to access parameters that are passed to a function and to access local variables.&lt;br /&gt;
&lt;br /&gt;
To allocate local variables, we just decrement the stack pointer (to make space).  We can get rid of them by restoring the stack pointer from the base pointer (on function exit).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Key steps to make a function call&lt;br /&gt;
* push arguments onto stack or store in registers&lt;br /&gt;
* call function (save current instruction on stack, jump to function)&lt;br /&gt;
&lt;br /&gt;
Key steps on entry to a function&lt;br /&gt;
* save base pointer&lt;br /&gt;
* copy stack pointer to base pointer register&lt;br /&gt;
* decrement stack pointer to make room for local variables&lt;br /&gt;
&lt;br /&gt;
Key steps on exiting a function&lt;br /&gt;
* copy base pointer register to stack pointer register&lt;br /&gt;
* do ret (pop instruction pointer from stack, jump to it)&lt;br /&gt;
&lt;br /&gt;
After function call finishes&lt;br /&gt;
* take arguments off stack, get return value&lt;br /&gt;
&lt;br /&gt;
What happens when a signal is delivered to a process?&lt;br /&gt;
* the currently running instruction is saved to the stack&lt;br /&gt;
* kernel replaces instruction pointer value with signal handler location&lt;br /&gt;
  (after putting proper arguments on stack)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int something(char *s)&lt;br /&gt;
{&lt;br /&gt;
        printf(&amp;quot;You said: %s\n&amp;quot;, s);&lt;br /&gt;
&lt;br /&gt;
        return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[], char *envp[])&lt;br /&gt;
{&lt;br /&gt;
        printf(&amp;quot;Entering main.\n&amp;quot;);&lt;br /&gt;
        if (argc &amp;gt; 1) {&lt;br /&gt;
                something(argv[1]);&lt;br /&gt;
        } else {&lt;br /&gt;
                printf(&amp;quot;No argument given.\n&amp;quot;);&lt;br /&gt;
        }      &lt;br /&gt;
        printf(&amp;quot;Exiting main.\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
        return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>