‫Hello and welcome in this lecture, we are going to implement our own in and out functions.
‫So obviously in the intel processor, as you know, we have in and out instructions, right.
‫But we sort of want to be able to use them in see.
‫And to do that, we're going to have to create a function in assembly that can be called from from C.
‫So that's what we're going to be doing today.
‫So if we create a new directory in your source directory and we're just going to call it IO and then
‫we're going to create a new file called IO Page, and we're just going to go F and I o h define Io,
‫H and F and just decide here we're going to go unsigned.
‫Char nsb unsign shot part, so this will be one bite from the give part right here.
‫We're going to go unsigned, short, NSW reworked unsigned shorts parts here.
‫We're going to go void outby unsigned, short parts, unsigned char vowel.
‫So this is the value that we want to output to the part.
‫Right.
‫And now we're going to go void out w unsigned, short part, unsigned, short vowel.
‫So you can see, you know, this is outputting one bite to the part.
‫This is out, but in two bites to the poor and the same for these.
‫OK, so we're now going to have to write some assembly instructions for these function prototypes here,
‫right.
‫So we can create a new Falconio called Iodized HSM.
‫OK, now this is going to be in the RSM section.
‫So when we explained all that previous in this course, so do S.A.M. and we're going to go global endersby,
‫OK, and now we're going to go in space.
‫And now if we go to Google and we type Intel in instructions and there is an inspired instruction,
‫by the way, but it shouldn't conflict, we should still be able to assemble.
‫So should be OK.
‫But we will be using the end instructions anyway so we can see here we have enabled X input by from
‫iReport index into.
‫OK, and then we have in a D X input word so we can use these two instructions to do what we need to
‫do here.
‫Right.
‫So well first going to create our stack frame and we don't really need to, but it's good practice.
‫Right.
‫So push SBP Pop SBP Rete for Return Move SBB E.S.P.
‫There we go.
‫So if we go back to here, we can see input work from iReports, not input byte from Eyeopener Index
‫into out.
‫So we need to move the part into the D X register.
‫OK, so to do that we just go move eddys x and we'll go for Eppy plus A and that should put the parts
‫in the register and although it's a shot it should still work.
‫OK, because we are only caring about the lower eight bits here.
‫Right.
‫And it should be fine.
‫So we're going to go back to Firefox's here.
‫So when we go in Aldy X now it should put one bite into the P&L register for us.
‫So before we go any further, just above here, we're going to explore the X register, so it's zero.
‫OK, and then we're going to go in al d x.
‫So there we go, that should be OK, because if you know how C. and assembly work together, the register
‫is always the return value.
‫So here we Zodiac's, so it becomes with itself.
‫So it becomes zero.
‫And then obviously the lower the lower eight bits of X will then be set to the byte loaded from the
‫port provided to us.
‫Right.
‫So then Al will contain our return value.
‫And since since Al is part of the X register, when we return from this function assembly function,
‫what we will actually be returning the result.
‫So that's all fine.
‫OK, so before we go any further, we're going to add that to the Makefile just to check it assembles.
‫Fine.
‫Before we move any further on.
‫So we're going to copy this ITSM that over here and we're just going to paste to the bottom here and
‫we're going to go build Io, Io Dadaism that our source Io Io that Diesem and I copy and paste this.
‫And.
‫OK, so it should look like that and don't forget, we need to put this in our files to include at the
‫top here as well.
‫So that I knows which file to link with, right?
‫OK, so we stick with the code convention here, the naming convention, I mean, just because in case
‫we create an IOC file at some point, you need to prepare yourself for these things.
‫So that is all fine.
‫And if we now go to the terminal and we make clean and then we build, we can see unable to open up
‫a file.
‫That is because we didn't create the directory in the build.
‫So go to the build directory.
‫We're going to create a directory called IO.
‫OK, and now if you run that again, there we go.
‫Works fine.
‫So just remember to do that.
‫Remember to create that folder so we can see that Sambo's absolutely fine.
‫And if we just go back to iodized ASEM, we're now going to do in S.W. so we go plushy BP movie BP VSP
‫Ekso execs move IDEX Eppy plus eight in acoustics and knows how to use a rather than al.
‫Now Poppy VPE rats and there's our in W so if we now export that global NSW, ok, now we go to iodized
‫Hajj, we now need to implement outby NSW.
‫Now they take two arguments here porten values.
‫So we need to take that into account.
‫So let's now start implementing outby so we go out be paci VPI movie, PSP Move EBP plus eight and that
‫will be plus 12 actually move IDEX EBP plus eight.
‫OK, and then we're going to go out desex and that should output one bite to that pop for us Pop.
‫OK, now we're going to do the same for our W pushy BP movie BP E.S.P movie EBP plus 12 move IDEX EBP
‫plus eight out the X X PBP return.
‫OK, now we need to scroll up.
‫We're going to explore both of those global outby and don't spot global wrong global outby global out
‫w OK, so that should work absolutely fine.
‫We're going to go to Canada at See and we're going to scroll up and we're just going to go include Io,
‫Io da Hajj and we're now going to actually try that.
‫So we're going to go outby zero X sixty six F F and now we're actually going to try that out.
‫So we just make clean bill that I say it's sidibé and gdb add symbol file dot dot backslash build kernel
‫fold.
‫Oh, so you one, one, two, three, four, five, and by the way, you can set up GDB remembers these
‫commands if you would rather do that.
‫I'm repeating myself here because I'm trying to get you to memorize them because there will become a
‫time, way where gdb might not remember the command you typed.
‫Right.
‫So we're going to target remote kumu system exi six sixty four and if you want to know how to do that,
‫just do a Google search.
‫It's very easy to reconfigure this terminal to remember that those commands for you.
‫So we're going to dash to stop and dash gdb sd io dash s.
‫So now we're going to go break Colonel Dot see eighty continue layout hsm step by step.
‫Now that now we're in here, we're going to step through this, we're going to print X and we see two
‫five five good print idex and we see as you 060 sixty decimal nice X so now we now step.
‫I can see that outputted that successfully to that part and if we now return.
‫We are now finished.
‫So I know that was a bit of a mouthful for such a simple operation, but I did have to briefly go over
‫a few things with you.
‫So we've now implemented outby out West NSW NS B so we can now do those instructions from C, congratulations.