‫Hello and welcome in in this lecture, we're going to improve our study live functionality by creating
‫a print function.
‫So you'll know in previous lectures we printed to the screen while in this lecture, we're going to
‫create a function that prints to the screen in see, OK, so it's not so hard and we're going to implement
‫that.
‫So the very first thing I want us to do in our study lab, create a new file called PTW at HSM and this
‫is going to contain assembly routines.
‫Add to our.
‫Now we need to write these assembly functions in a way that the C compiler approves.
‫Otherwise we could lead to binary incompatibility.
‫So that's just something to keep in mind.
‫If you follow the course, all will make sense.
‫So we're going to start with Bits 32 because we want to deal with 32 bit code here.
‫OK, now we're going to create a print label and we're going to export that print label.
‫And it's a function.
‫So we're going to call them function.
‫OK, so so that it's aware of that.
‫And now here in the print label, we're going to start by pushing the base pointer.
‫Then we're going to pop the base point and return.
‫OK, this is how see compilers create a stack frame, OK?
‫And we should create our own as well.
‫OK, so here we're going to go move EBP E.S.P.
‫So we're going to move the stack pointer into the base point of here, OK, and the C function will
‫look like this void print const char filename.
‫So that's how that is going to look.
‫So what we now need to do is push the filename the to the stack, the one that was provided to us.
‫So to do that we just go past what, EBP plus eight now Y plus eight because we pushed our base punches
‫of the stack which was four bytes, and the person who called our function, that led to the return
‫address being put on the stack, which was also four bytes.
‫So by plussing eight, it should give us the filename that they pushed to the stack.
‫OK, we're now going to go move vacs one, which is fine print.
‫I'm going to go in at zero 680, OK?
‫And that should invoke the COL to print this file name.
‫So when I'm going to copy and paste this definition that I defined here while in the assembly comment,
‫we're going to create a new file in acidy lab called Peko s top hech.
‫And guys, these things should be in the source directory.
‫Right.
‫Move them to the source directory here.
‫OK, just like that and impetuous thought, hey, we're just going to go hashtag Ifan, death defying
‫Peter S.H., hashtag INDEF and we're going to paste that in there.
‫And there's our definition.
‫Now, go back to us today.
‫Tourism and we can see everything's fine.
‫We've marked it as global.
‫It's a function.
‫This shows that the alpha type, the alpha symbol type is a function symbol type of code for the alpha
‫produced by this, which is important for dynamic linking.
‫I just want to get you into the habit of that now.
‫So, yeah, there's a prototype, there's our code, and now we should be able to use this in our study.
‫So go back to Blanchot C and we're just going to include start Hajjaj.
‫OK, and just in the Makefile a blank, we're going to go to our includes and we're going to go dashi,
‫dot, dot, backslash, well-thought-of, such as say a source, no, no S3 Leyb source and there we
‫are.
‫That's our include set.
‫So now we can resolve PTW and I was just going to go print.
‫Hello, how are you.
‫OK, we're just going to have a while one here because we haven't yet handled program X X.
‫It's OK, we haven't yet implemented our program exit, so just do an infinite loop here to stop the
‫program end.
‫And just you, a new line character there as well.
‫OK, so we need to go to the Makefile of S3 Lab and we just need to compile prostatitis.
‫So just by here, go build pictures, DOT.
‫Oh, we're going to copy and paste this.
‫Nazim, come in here and this will be Estado.
‫This so be Peatross today.
‫Some pictures Dadaism Pacho Estado.
‫And now if we now try to compile that everything should be OK, so we're going to go make clean.
‫Builder S.H..
‫And we can see that compiles that successfully when I was going to go CD bin, we're going to run Kumu.
‫You can do control cue and then we'll give you that command and look what we see.
‫Hello, how are you?
‫So that's really good.
‫Now we're writing use the programs in just the C programming language.
‫Now you can't pass percent s percent eye and stop printing things to the screen like that, like integers
‫and stuff, because we haven't yet implemented the printer function that'll come later on.
‫We'll implement print if we don't need to worry about that right now.
‫So that's just one other thing I forgot to do for the print function if we could just a to today, as
‫you'll see here, we push the filename to the stack, but we don't store the stack after we call the
‫kernel.
‫So that's that's a bug.
‫OK, so we need to go at ESP fall.
‫And as you know, when you push to the stack that uses four bytes, OK, that that changes the stack
‫pointer by four bytes.
‫So by restoring the stack pointer up by four bytes, it will be as if we never even pushed this item
‫into the stack and the stack will be restored.
‫And then when we go to pop the base point, everything should work fine.
‫So just make sure that you have ADP for just after you interrupt here to the kernel.
‫So congratulations.
‫You've now implemented the print function.
‫We'll worry about the printer and things like that later on.
‫Take care.