🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

ASM variables

Started by
18 comments, last by Calin 4 years, 1 month ago

thanks for helping me unleash the dragon

My project`s facebook page is “DreamLand Page”

Advertisement

So basically the variables are the same to those of higher level languages, the only difference is that it`s raw variables, no cushoning

My project`s facebook page is “DreamLand Page”

It is the same. It is always a register under the hood. Compilers sometimes produce assembler code in plain text and then use an assembler to covert it to machine code. It is the same under the hood.

A variable is what you want it to be. Example is the treating of chars as numbers in order to test if the letter is a number.

You can do the same trick of putting two variables in one single variable in C++. You can explicitly tell C++ to do it using the bitwise operators. Not sure if you can get a speedup from it.

For a game i see no reason to use ASM over C# or JavaScript.

Maybe you are working on something different but you keep it in secret. You tell us that you are making a game, but actually you make something different. Something secret.

NikiTo said:
there is always a register under the hood

got it.
maybe someone is asking himself where I`m headed with this, I don`t want to write an OS, but the possibility of making use of interrupts sounds intriguing.

what I don`t have a very good grasp of is the how the execution of commands succession works, I understand the code `pockets` concept (i.e code enclosed in brackets in C), what I don`t understand is how when you have for example a succession of 3 instructions/commands can you, out of thin air ,insert a new command and detour the execution. I understand that there are pointers to data (variables) and also pointers to commands/functions, but how can you break and resume execution of a command chain at run time

My project`s facebook page is “DreamLand Page”

Calin said:
maybe someone is asking himself where I`m headed with this,

I do wonder what are you doing for real.

Calin said:
but the possibility of making use of interrupts sounds intriguing.

Do you really need interrupts?

Initially i thought you want to make an OS that lives completely inside the GPU. All the things you asked, made me think that.

edited my reply above

My project`s facebook page is “DreamLand Page”

If you have a 4 cores CPU, one of these cores will be core0.
It controls the rest when booting the computer.
For all the cores and all the code you have only one interruption handling code at one single place only once. There can be variations, but still it is more or less, the same.

I say all of this because there is always a central boss.

That boss can interrupt everybody else. In order the code to not notice the STOP, everything is saved to RAM. (Actually only what is being to be used by the boss code is saved)

code:

step = 50;
bullet.x += step*unitVector.x;
Bullet.y += step*unitVector.y;

the compilers will produce this under the hood(or vectorized version, but this example is for simplicity):

step = 50;
temp = step*unitVector.x;
bullet.x += temp;
temp = step*unitVector.y;
bullet.y += temp;

now consider this:

step = 50;
temp = step*unitVector.x;
bullet.x += temp;
<<<<<< interrupt comes from the boss(could be the OS or the hardware)
temp = step*unitVector.y;
bullet.y += temp;

This is what happens:

step = 50;
temp = step*unitVector.x;
bullet.x += temp;
<<<<<< interrupt comes from the boss(could be the OS or the hardware)

save “step” to RAM.
save "unitVector.x" to RAM.
save "bullet.x" to RAM.

execute the code of the interrupt, changing the frequency of the CPU for example.
CPUFrequency = CPU.getFrequency();
If (CPUFrequency > 5mhz) {
CPUFrequency -= 5mhz;
CPU.setFrequency(CPUFrequency);
}

when the CPU is ordered to cool down restore it all

take “step” from RAM
take “unitVector.x" from RAM
take “bullet.x” from RAM

Now you can keep with the old code as if nothing happened at all

temp = step*unitVector.y;
bullet.y += temp;


This way you can even have interrupts interrupting interrupts interrupting interrupts. It is simple but effective.

The hardware has its own life and ideas. It has its own CPU to say it in a way. It can interrupt your CPU any time.

Only what is inside the CPU will be saved to RAM and then restored. The rest is already laying in RAM, no need to restore. It is more complicated than my example, but to give you an idea.

Resuming it - the OS will save a copy to RAM of everything it will override. Then, when finished, the OS will restore all that taking it from RAM back to the CPU. Your program will not even notice it. Except when the time is important. Your program will notice that time gone forward.

And there is a boss, somebody, a piece of silicon somewhere that has its own life independently of your code and can interrupt your CPU.

More technically -
https://wiki.osdev.org/Interrupts#From_the_CPU.27s_perspective

You don't need to worry about interrupts. The OS will do it all for you.

Calin said:
(i.e code enclosed in brackets in C)

In ASM it is a little bit different than that. You don't use brackets. It is more like a flow/stream of instructions.

And i feel bad for talking about OS here in this forum, because this site is about games, not ASM, not OS either.

Thanks NikiTo
with multi-core processors interrupts is easier to comprehend i.e a chief core can step in at any time. But how does that work with single core? In older OS pressing ctrl alt del would bring no matter what the blue menu the very next second( Unlike modern computers where ctrl alt del menu pops up depending on the mood of the computer at that time)

How much code/commands get saved where the interrupt takes place ?

What I want to do is so crazy I don`t even dare speak about it, for now I need to get a good grasp of assembler, I promise I will either put it to work or speak about what my plan was ( if I fail to achieve). It has to do with data `mining` but with focus not on gathering but rather interpretation

My project`s facebook page is “DreamLand Page”

Calin said:
But how does that work with single core?

Some controller somewhere on the motherboard will have its own live and will tell the CPU to stop. I use very broad terms as "something" or "boss", because things vary from one system to another.
The CPU obeys other bosses in the system.

Calin said:
How much code/commands get saved where the interrupt takes place ?

Only the ones that the CPU will override. Not much for Interrupts coming from the motherboard. Hardware interrupts are super fast. Don't worry about them.
I am not sure about savings between different programs. I guess everything possible is saved to RAM and restored. EVERYTHING!!!! Super slow, i guess. I can not tell how windows works. I never even tried to peek into how windows does its stuff. Ask some hacker who uses ASM. They know where every single bit goes on a Windows OS. I know nothing about it. I only can guess that for security reasons, everything must be zeroed between processes.

Calin said:
I promise I will either put it to work or speak about what my plan was ( if I fail to achieve).

I do the same. I keep it all in secret. But when i see i failed and will not work on it any longer, i share it with everybody.


I worked with ASM on the baremetal.
Sometimes i am not able to answer to your questions, because i just don't know the answer. It is faster for me to create my own OS kernel than try to study or reverse engineer the kernel of Windows. And Windows changes too fast. So every time i have to study a new kernel. No point in doing it. I am not a hacker.


Right now i am being bottlenecked on the GPU side. Because not always it is possible to parallelize the IFs. So far IFs were not a problem for me. Lots of IFs, but i parallelized them until now. But my algo starts to become too GPU unfriendly. Some day I will start coding for the AVX on the CPU side. Then i will be able to answer to most of your questions. But this could happen few months from now. Not soon at all.

(Notice, i will try to use C++ first to operate the AVX. If it fails, only then i will program completely in ASM. So IF i start using pure ASM and it will be not soon, i will able to answer to all of your questions.
I am sincerely telling you that you very very rarely need to use ASM. I will explain it to you this way - The troops of your enemy are attacking the borders of your country. The troops are only 1000 in number. Definitively Tzar Bomb is the most powerful weapon of all. Tzar Bomb is ASM. But do you really need Tzar Bomb for 1000 enemy troops? A single raid of Grad Missile System will suffice. This is what i mean - you PRACTICALLY rarely need to use ASM)

Some controller

So basically Jurassic of multi-core

My project`s facebook page is “DreamLand Page”

This topic is closed to new replies.

Advertisement