Hi! Nice to meet you again! This time I'd like to explain the low level
basics. It is widely used in many programming language. I should remember
you that every thing I mention here is for the Intel PCs. No matter what
the type is. I must say sorry to Mac or other computer users. It is because
their machine language is different from that in Intel PCs. However, later
I would also explain the Mac or other computer assembly. Just give me an
input.
Of course you need to learn the concept of low level programming. :-) The concept here is a bit theoretical. However, it is severely needed to program in low level way. I talk the concepts in general here so that I can also link them into my C / C++ and assembly lessons. So, I think that I need to separate the concepts out of here. But, I provide a link in this chapter so that you can follow that, too.
After you have a firm grip at the concepts, you can go back here for the implementation. Of course, the low level basics about memory concepts, registers and interrupts is all the same as long as it is in PC. So, programming low level in C is quite the same as in Pascal. However, the implementation is different, i.e. the commands available in each language. Then, after knowing the concepts, you can apply the concepts into other programming language. All you need is just syntax reference.
So, I hope that's clear and let's go!
Click above link.
Implementing low level things in Borland Pascal is not difficult. The first thing to implement here is registers. Here's how. First, you need to include uses dos clause. Then you define a variable as registers. After that you can modify the "virtual" register. Why do I say virtual? It's because when you modify the contents of registers variable, you don't directly modify the machine register contents. Instead, it holds the will-be-modified registers so that later we can use it as the complement of other instruction, such as intr.
Defining a variable as register is easy:
var reg : registers;
Yeah! That's the way. To access the register is similar to accessing records. Suppose you want to fill in AX with the value of 13 hex, here's how:
reg.ax:=$13;
Simple and easy right? Now, how to use interrupts? Use intr! The two parameters it takes are the interrupt number and the registers variable. Here's how to invoke the interrupt 10 hex (later I'll abbreviate hex into h only):
intr($10,reg);
Neat and easy, right? Now what? How to use it then? The real-life problem is like this. Sometimes you encounters the reading of interrupts. It says roughly like this:
"Invoke the 10h interrupt service 0h with AL is equal to 13h."
Wow! What was that? The interrupt number is 10h. Service number is usually the number you would fill in AH, except they has some notes. Then you fill AL with 13h. Here's how to do it. First, yeah... of course you need the uses dos clause and then define the reg variable as registers. Follow this steps:
reg.AH:=$0; reg.AL:=$13; intr($10,reg);
Bingo! The task is now completed! Because AX is equal to AH merged with AL, people prefer filling AX rather than filling AH and AL separately. So the first two lines above can be written as: reg.AX:=$0013; Simple and easy.
Sometimes the interrupt returns value in register. You can access that approximately the same way. Look at this example:
reg.AX:=0; intr($16,reg); if reg.AL=0 then writeln('Extended keyboard code') else writeln('Normal code');
This is an example of getting keyboard key then detect it whether the key is normal or extended. The key is checking AH after interrupt call. Neat and easy right?
Now, you should be able to dechiper the interrupt reading thingy!
That's all folks! Low level programming is not so hard, isn't it? Shall we go to the quiz or the next lesson?
Back to main page
Back to Pascal Tutorial Lesson 2 contents
To the quiz
To Chapter 11 about I/O Ports.
My page of programming link
Contact me here
By: Roby Joehanes, © 1997, 2000