hey guys! assembly language and i need your help! :)
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
because ... uhh ... "ESI does not identify the structure it belongs to."
Consider this: if you did not know (because you had not been told) that ESI pointed to an Employee structure, how would you compute the proper offset to use for "Years?"
(Let's assume that there are twenty different structure definitions in this program, all of which define a field named "Years.")
The answer is: "you couldn't." Unless the programmer tells you what ESI is pointing to at any particular time, you (the assembler...) cannot solve the problem.
Because the fools who designed the language you're trying to use didn't understand why there was a difference between high level languages and assembly languages.
High level languages can support complicated scoping, such as multiple structs defined within the same scope containing the same named field. Such scoping is totally unnatural for ASM, and results in verbose unreadable code that defeats any purpose of writing ASM. If you want to write in a high level language, write in a high level language.
because ... uhh ... "ESI does not identify the structure it belongs to."
Consider this: if you did not know (because you had not been told) that ESI pointed to an Employee structure, how would you compute the proper offset to use for "Years?"
(Let's assume that there are twenty different structure definitions in this program, all of which define a field named "Years.")
The answer is: "you couldn't." Unless the programmer tells you what ESI is pointing to at any particular time, you (the assembler...) cannot solve the problem.
but this instruction
Code:
mov esi,OFFSET worker
and this one
Code:
.data
worker Employee <>
tells that worker is a structure variable,and it passes the address of worker structure.so i should know "Years" is belongs to "worker" structure.
tells that worker is a structure variable,and it passes the address of worker structure.so i should know "Years" is belongs to "worker" structure.
But there is no declaration of the data type of esi. I don't know if this stupid kludge of a language has a way to declare (rather than cast) the data type of a register. It is so far from what asm should be, that I don't want to know.
In that C++ code, the compiler could do flow analysis to know what kind of thing esi points to. But it isn't supposed to do that to resolve syntax/semantic issues, only for optimization. So the above code won't work.
In ASM, the assembler isn't supposed to do that flow analysis at all. So seeing mov esi,OFFSET worker doesn't make the assembler take that info about esi to any other line of your code. That info stays on that line only.
In ASM, the assembler isn't supposed to do that flow analysis at all. So seeing mov esi,OFFSET worker doesn't make the assembler take that info about esi to any other line of your code. That info stays on that line only.
but what does this instruction really do? nothing?
Code:
mov esi,OFFSET worker
and what is the value of esi in this instruction?
Code:
mov ax,(Employee PTR [esi]).Years
Last edited by topheraholic; 06-13-2011 at 08:18 PM.
but what does this instruction really do? nothing?
Code:
mov esi,OFFSET worker
At least one of your other posts (not in this thread) implies you know some C. Do you know what this line of C does?
Code:
void* esi = &worker;
The asm instruction you asked about puts the address of worker into the register esi. It does not do anything with type information. The register esi holds only the address. It has no extra bits to know the data type of the thing it points to.
Even in C, a pointer holds just an address. At run time, the pointer holds no type information. Type checking in C is all done at compile time. If you wrote
Code:
Employee* esi = &worker;
in C, the compiler would know esi was an Employee* (because you declared it as such, not because you initialized it to point to worker) so later use of esi can take advantage of that compile time type knowledge.
Your actual instruction
Code:
mov esi,OFFSET worker
doesn't create any compile time type knowledge. At run time, esi gets just the address of worker, not any info about the type. At compile time, even less is remembered. The assembler generates the machine language instruction for that ASM instruction, but carries no knowledge of it forward to affect later instructions.
A human sees that instruction and knows what kind of thing esi points to and can apply that knowledge to help understand the next use of esi in the program. The computer does not use that kind of knowledge/understanding, neither at run time nor at assembly time.
Quote:
Originally Posted by topheraholic
but esi points to the address of worker!so work.years could be works as well!but why it is not?
(only guessing at what you mean, so I might be answering the wrong question):
The assembler does know the type of worker, so it should be able to understand something like worker.Years
I don't know the exact syntax for that. I haven't used asm in quite a while and I never made significant use of the stupid features of Microsoft ASM that make it more like a high level language. So I'm pretty sure you could do something like
Code:
mov ax, worker.Years
and not need to involve esi at all. But I'm not sure of exact syntax.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.