adressing problem
-
Dienstag, 21. August 2012 18:11
i have two numbers , and want add it .
mov eax,3[90fffffh]
mov ebx,4
add eax,ebx
i have extern C structure and result in Asm said ...
The result is Asm-1862270970
I use .model flat
i ought have result Asm7
Where is my mistake ? Can We help me ?
Alle Antworten
-
Dienstag, 21. August 2012 18:18
On 8/21/2012 2:11 PM, rafal_bator wrote:
i have two numbers , and want add it .
mov eax,3[90fffffh]If you want to load 3 into eax, just write
mov eax, 3
What you have is something like "load into eax the four bytes that are in memory at offset 3 from address 0x90fffff". What is that supposed to achieve?
Igor Tandetnik
-
Dienstag, 21. August 2012 19:13Yes i want load in eax 3 from 0x90fffff . And add it to 4 .
-
Dienstag, 21. August 2012 19:42
On 8/21/2012 3:13 PM, rafal_bator wrote:
Yes i want load in eax 3 from 0x90fffff . And add it to 4 .
What exactly do you mean by "from 0x90fffff"? What is the significance of the number 0x90fffff ?
If you want to load 3 into eax, you just write "mov eax, 3". If you want to load some value X other than 3 into eax, then why do you expect that X+4 should equal 7? I'm confused.
Igor Tandetnik
-
Dienstag, 21. August 2012 20:31
how can i load "3" to eax under 0x90fffff and add "4" to ebx under 0x91ffffff ?
-
Dienstag, 21. August 2012 20:40
-
Dienstag, 21. August 2012 21:48i want load to eax cell capacity from segment number 3 and move about 0x90fffff in relation to segment begin , and load 4 to ebx , and get result .
-
Dienstag, 21. August 2012 23:04
-
Dienstag, 21. August 2012 23:22
cell -> cellule
segment -> bit slice
-
Dienstag, 21. August 2012 23:25
-
Dienstag, 21. August 2012 23:35i think about segment:offset
-
Dienstag, 21. August 2012 23:58
-
Mittwoch, 22. August 2012 00:09
Ok . Thank You .
How write number 3 into 0x90fffff ? next add it to 4 in 0x91fffff ?
-
Mittwoch, 22. August 2012 00:19
On 8/21/2012 8:09 PM, rafal_bator wrote:
How write number 3 into 0x90fffff ?
mov eax, 3
mov [90fffffh], eaxnext add it to 4 in 0x91fffff ?
I don't understand this part. Do you want to read the contents of memory at address 0x91fffff? How do you know this address contains the value 4 - and if you do somehow already know that, why do you want to read from memory?
Or are you saying you want to add 4 to 3, and then write 7 to the memory at address 0x91fffff?
Where do the numbers 0x91fffff and 0x90fffff come from? What's so special about them?
Igor Tandetnik
-
Mittwoch, 22. August 2012 00:30
ok , must i write 4 as 3 ?eg.
mov ebx,4
mov[91fffffh],ebx
?
and add as :
add [91fffffh],[90fffffh]
?
-
Mittwoch, 22. August 2012 00:39
On 8/21/2012 8:30 PM, rafal_bator wrote:
ok , must i write 4 as 3 ?eg.
mov ebx,4
mov[91fffffh],ebxYes, if you want to save the value 4 into memory at address 91fffffh
and add as :
add [91fffffh],[90fffffh]You can't add two values from memory directly - you have to load them into registers first. But since at that point you already have them in registers, just do
add eax, ebx
Igor Tandetnik
- Als Antwort markiert Damon ZhengMicrosoft Contingent Staff, Moderator Mittwoch, 5. September 2012 12:00
-
Mittwoch, 22. August 2012 00:58mov[91fffffh],eax and ebx is not allowed . I have that communicate .
-
Mittwoch, 22. August 2012 06:29I give up. What does any of this have to do with Visual C?
-
Mittwoch, 22. August 2012 10:18
I do not understand ? Can You answer on my problem ?
- Bearbeitet rafal_bator Mittwoch, 22. August 2012 10:19 it is above
-
Mittwoch, 22. August 2012 13:31
rafal_bator wrote:
mov[91fffffh],eax and ebx is not allowed . I have that communicate .
I don't understand what you are trying to say.
Igor Tandetnik
- Als Antwort markiert rafal_bator Mittwoch, 22. August 2012 13:37
- Tag als Antwort aufgehoben rafal_bator Mittwoch, 22. August 2012 18:15
-
Mittwoch, 22. August 2012 13:50this is communicate after build .
-
Mittwoch, 22. August 2012 13:54
-
Mittwoch, 22. August 2012 18:13
Maybe eax and ebx are allowed, but you do not use them correctly. For example if you write ‘_asm mov [91fffffh], eax’ in Visual Studio, you will receive an error, but when you write ‘_asm mov ds:[91fffffh], eax’, nu such compiler error.
So show the error messages that are displayed in console window, and the text of the program that you are trying to execute. And maybe rephrase the question giving more details.
-
Mittwoch, 22. August 2012 18:14
mov [90fffffh],eax
mov [91fffffh],ebx
build it
1>asm.asm(7): error A2001: immediate operand not allowed
1>asm.asm(9): error A2001: immediate operand not allowed
ok .Viorel .
How add this ?
must i define load from adress ?- Bearbeitet rafal_bator Mittwoch, 22. August 2012 18:19 add explain
- Bearbeitet rafal_bator Mittwoch, 22. August 2012 18:22 add
-
Mittwoch, 22. August 2012 18:18
how add this ?
main.cpp :
#include<iostream>
#include<conio.h>
using namespace std;
extern "C" int Asm();
int main()
{
cout<<"Asm"<<Asm()<<endl;
_getch();
return 0;
}
asm.asm:
.486
.model flat
.code
Asm proc C
mov eax,3
mov ds:[80fffffh],eax
mov eax,ds:[80fffffh]
mov ebx,4
mov es:[90fffffh],ebx
mov ebx,es:[90fffffh]
add ebx,eax
ret
Asm endp
end
Build is ok .
Debuging
i have :
Unhandled exception at 0x01232045 in project1.exe: 0xC0000005: Access violation writing location 0x080fffff.
where is my adress space , is it my mistake ?
- Bearbeitet rafal_bator Mittwoch, 22. August 2012 19:26 add
- Bearbeitet rafal_bator Mittwoch, 22. August 2012 19:28 add
-
Donnerstag, 23. August 2012 04:31
The error means that cells situated at addresses 80fffffh and 90fffffh do not belong to your program, therefore you do not have rights to access them.
Instead of numeric addresses, try variables. For example define data segment before ‘end’ statement:
.data
X dd ?
Y dd ?
Then try ‘mov X, eax’ instead of ‘mov ds:[80fffffh],eax’ and ‘mov Y, ebx’ instead of ‘mov es:[90fffffh],ebx’ and so on.
- Als Antwort markiert Damon ZhengMicrosoft Contingent Staff, Moderator Mittwoch, 5. September 2012 12:01
-
Donnerstag, 23. August 2012 10:24
i want to place datas in definite cells .
how can i reserve memory cells about definite adress for simply datas ?
what do
You think about dynamic allocation ?mov ah,49h
mov es,[ds:2ch]
int 21h
mov ax,3
mov ds,ax
mov ah,48h
mov bx,10
int 21h
is this slow down and allocated in 2ch number 3 ? how can i make next slow down and allocation for other number in this same thread ?
if i definite from 2ch , and slow down by int 21h , can i put this sime as previous ?:
- Bearbeitet rafal_bator Donnerstag, 23. August 2012 10:39 add
- Bearbeitet rafal_bator Donnerstag, 23. August 2012 10:41 add
- Bearbeitet rafal_bator Donnerstag, 23. August 2012 12:30 add
- Bearbeitet rafal_bator Donnerstag, 23. August 2012 12:41 add
- Bearbeitet rafal_bator Donnerstag, 23. August 2012 12:42 add
-
Donnerstag, 23. August 2012 13:25
rafal_bator wrote:
i want to place datas in definite cells .
Why? What's the purpose of this exercise?
how can i reserve memory cells about definite adress for simply datas ?
You can't. Again, why do you want to?
what do
You think about dynamic allocation ?
mov ah,49h
mov es,[ds:2ch]
int 21hYou seem to be reading some very old manual about programming for MS DOS, where "int 21h" was a system call. This manual is obsolete by 17 years - Windows doesn't work this way since 1995. Throw it away, forget everything you read in it.
Igor Tandetnik
-
Donnerstag, 23. August 2012 13:57
The address 90FFFFFh does not belong to your program, but you can try something like this:
.data
db 90FFFFFh+4 dup(?)
Now you should have enough space for your experiments. However a declaration like this usually slows down the compilation (http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvc/thread/dea7357d-0650-4182-a55e-8cf951aba97e). Maybe you first try some smaller addresses.
-
Donnerstag, 23. August 2012 14:47what belong to my free adress space , how count it ?
-
Donnerstag, 23. August 2012 17:19
This is a Visual C++ forum. If you need help with asm, please ask in appropriate forum.
-- pa
-
Donnerstag, 23. August 2012 20:39I took with You , Sir Pavel A . Part of Visual C++ is Masm . VC++ have Masm32 and Masm64 , it is depends of version . Masm is as _asm or Asm in You , Sir code . Before if You want to use it , Sir have to definite it .
-
Donnerstag, 23. August 2012 20:46what are different between diferent MASMs ? Masm work in cmd too .
-
Donnerstag, 23. August 2012 20:59what is instead int 21h ?
-
Donnerstag, 23. August 2012 21:22
Unhandled exception at 0x00e72044 in project1.exe: 0xC0000005: Access violation writing location 0x00000300.
What is it ?
-
Donnerstag, 23. August 2012 21:39
On 8/23/2012 5:22 PM, rafal_bator wrote:
Unhandled exception at 0x00e72044 in project1.exe: 0xC0000005: Access violation writing location 0x00000300.
What is it ?Which part of the error message is unclear? You attempt to write to a memory location at address 0x00000300, but your process doesn't have access to write to that location.
Igor Tandetnik
-
Donnerstag, 23. August 2012 21:40
On 8/23/2012 4:59 PM, rafal_bator wrote:
what is instead int 21h ?
Windows API functions:
http://msdn.microsoft.com/en-us/library/windows/desktop/hh447209.aspx
Igor Tandetnik
-
Donnerstag, 23. August 2012 22:24
Thank You
i wrote :
.486
.model flat
.code
Asm proc C
mov eax,4
mov ecx,[30]
mov ecx,eax
mov ebx,5
mov edx,[40]
mov edx,ebx
add ecx,edx
ret
Asm endp
end
my asm see number 4 , why do not add 4 to 5 ?- Bearbeitet rafal_bator Donnerstag, 23. August 2012 22:25 add
-
Donnerstag, 23. August 2012 22:34
On 8/23/2012 6:24 PM, rafal_bator wrote:
my asm see number 4 , why do not add 4 to 5 ?
A function returns a result by placing it into EAX register. In other words, whatever is in EAX after the function returns, becomes the function's return value.
Your code loads 4 into EAX in the very first line, and never touches that register afterwards. So when the function returns, EAX still holds 4, which becomes the function's return value. All the other lines don't serve any useful purpose, and can be removed without changing the outcome.
Igor Tandetnik
-
Donnerstag, 23. August 2012 22:52
to ecx , is not load adress [30] ? And eax with 4 to change into ecx as adressed [30]?
-
Donnerstag, 23. August 2012 23:00
On 8/23/2012 6:52 PM, rafal_bator wrote:
to ecx , is not load adress [30] ? And eax with 4 to change into ecx as adressed [30]?
In a mov instruction, the first argument is the destination and the second argument is the source. Thus, "mov ecx, eax" means "take value from EAX register, copy it into ECX register". EAX register remains unchanged.
Igor Tandetnik
-
Donnerstag, 23. August 2012 23:08
Thank You .
how adressed into memory eg. 4 ?
-
Donnerstag, 23. August 2012 23:18
-
Donnerstag, 23. August 2012 23:25how can i put into definite memory address eg.4 ?
-
Donnerstag, 23. August 2012 23:36
On 8/23/2012 7:25 PM, rafal_bator wrote:
how can i put into definite memory address eg.4 ?
Why do you want to? Where is this "definite" memory address coming from? There is never a good reason to access a hard-coded address. But if you insist, you can just write
mov [10000000h], 4
Replace 10000000h with the actual address you want to access.
Igor Tandetnik
-
Donnerstag, 23. August 2012 23:41
1>asm.asm(5): error A2001: immediate operand not allowed
i have it .
-
Donnerstag, 23. August 2012 23:51
-
Donnerstag, 23. August 2012 23:57this same result
-
Freitag, 24. August 2012 00:04
-
Freitag, 24. August 2012 00:20
then take value in hexadecimal 10000000h to eax , and 4 to eax ?
how is purpose it ?
when i meke mov [eax],4 i have it :
1>asm.asm(6): error A2070: invalid instruction operands
-
Freitag, 24. August 2012 00:35
On 8/23/2012 8:20 PM, rafal_bator wrote:
then take value in hexadecimal 10000000h to eax , and 4 to eax ?
No. [eax] (note square brackets) means "the memory location whose address is stored in EAX".
when i meke mov [eax],4 i have it :
1>asm.asm(6): error A2070: invalid instruction operandsLast attempt, and I give up. It's been 19 years since I last coded in assembler.
mov eax, 10000000h
mov dword ptr [eax], 4
Igor Tandetnik
-
Freitag, 24. August 2012 00:43
i have it :Unhandled exception at 0x01052045 in project1.exe: 0xC0000005: Access violation writing location 0x10000000.
-
Freitag, 24. August 2012 00:49
-
Freitag, 24. August 2012 00:55if i use it in e.g. 7h , i have this same . this is free space , windows contain self in up memory .
what is your time ?- Bearbeitet rafal_bator Freitag, 24. August 2012 00:58 add
-
Freitag, 24. August 2012 01:10
On 8/23/2012 8:55 PM, rafal_bator wrote:
if i use it in e.g. 7h , i have this same.
Of course. Why would you expect any different?
this is free space , windows contain self in up memory.
A 32-bit process can address 2GB of address space. But that doesn't mean that every process has 2GB of physical RAM available to it. You simply don't have that much RAM in your machine. Thus, most of that address space is not in fact backed by physical memory. If you try to access a virtual memory address that is not backed by physical RAM, you will get an access violation. Which is exactly what you observe in practice.
You cannot just go poking at random addresses. Before you can access memory, you must allocate it.
See if this helps clarify the picture:
http://en.wikipedia.org/wiki/Virtual_address_space
http://en.wikipedia.org/wiki/Virtual_memorywhat is your time ?
I beg your pardon?
Igor Tandetnik
-
Freitag, 24. August 2012 01:12good night , i will be for 7 hours . thank You .
-
Freitag, 24. August 2012 04:47Igor, my compliments for your patience.
-
Freitag, 24. August 2012 21:47
1.how can i check where i have free memory , and all memory structure ?
2.have i use to space of application app.exe only in Visual C++ or can i definite this space in free space on outside this aplication app.exe ?
3.how can i allocate my application app.exe ?
4. is my asm.asm inside main.cpp , or outside ?
5. is my _asm inside main.cpp ?
6. who is who ?
-
Freitag, 24. August 2012 23:30
rafal_bator wrote:
1.how can i check where i have free memory , and all memory structure ?
There is no free memory just lying around waiting to be picked up. Free memory is made available to you upon request. When you need a certain amount of memory, you allocate it, then you can use it.
2.have i use to space of application app.exe only in Visual C++ or can i definite this space in free space on outside this
aplication app.exe ?I don't understand this question. But I suspect you have deep misconceptions about how virtual memory works.
3.how can i allocate my application app.exe ?
If you are asking how you can allocate memory for use by your application, then calling HeapAlloc API function would be one possibility.
4. is my asm.asm inside main.cpp , or outside ?
I don't understand this question.
5. is my _asm inside main.cpp ?
What do you mean by "your _asm"? What do you mean by being "inside"?
6. who is who ?
I am me. I can't speak for others.
Igor Tandetnik
-
Freitag, 24. August 2012 23:37
mov eax,1h // load to eax 1
mov ebx,eax // load eax to edx ,free pointer of datas
mov esi,201h//201h , load to source pointer esi
mov edx,esi//load esi to data register edx
i build and debug
my result is : 1
but i have it :
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
what is it ?
who is who // this is mistake , sorry// i ought : what is what ?
inside -> when You have aplication start - to - finish , when You use this _asm into and Asm outside .- Bearbeitet rafal_bator Samstag, 25. August 2012 00:05 add
- Bearbeitet rafal_bator Samstag, 25. August 2012 00:15 add
-
Samstag, 25. August 2012 00:06
rafal_bator wrote:
but i have it :
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a
function declared with one calling convention with a function pointer declared with a different calling convention.
what is it ?Calling convention mismatch. Show how you declare this function in your C++ code, and show the complete assembly code, from "proc" to "endp".
Igor Tandetnik
-
Samstag, 25. August 2012 10:32
main.cpp:
#include <iostream>
#include <conio.h>
using namespace std;
extern "C" int Asm();
int main()
{
cout<<"Asm"<<Asm()<<endl;
_getch();
return 0;
}
asm.asm:
.486
.model flat
.code
Asm proc C
mov eax,1h
mov ebx,eax
mov esi,201h
mov edx,esi
ret
Asm endp
end
-
Samstag, 25. August 2012 13:46
rafal_bator wrote:
Asm proc C
mov esi,201hWith __cdecl calling convention (which is the one you are using), the function must preserve all registers except EAX, ECX, and EDX. This doesn't mean the function cannot use these registers for its own needs - but if it does, it must save the original values at the beginning, and restore them at the end, before returning.
Your code fails to preserve the value of ESI register.
Igor Tandetnik
-
Samstag, 25. August 2012 22:24
how can i use ds segment register in 32 mode ?
how can i replace this segment register in 32 bit mode ?
why cannot i use 16 bit registers , x86 architecture have this ?
- Bearbeitet rafal_bator Samstag, 25. August 2012 22:44 add
- Bearbeitet rafal_bator Samstag, 25. August 2012 23:20 add
- Bearbeitet rafal_bator Samstag, 25. August 2012 23:20 add
-
Sonntag, 26. August 2012 01:37
rafal_bator wrote:
how can i use ds segment register in 32 mode ?
You can't.
how can i replace this segment register in 32 bit mode ?
You can't.
why cannot i use 16 bit registers , x86 architecture have this ?
You can happily use AX, BX, CX and DX 16-bit registers. Probably also SI and DI, but I'm not sure.
Igor Tandetnik
-
Sonntag, 26. August 2012 10:53
Thank You .
I know , that i cannot use DS in 64 bit mode . Can i replace this by descriptor ?
-
Sonntag, 26. August 2012 13:23
-
Sonntag, 26. August 2012 14:36
Descriptor it is data structure who is use by segment motion :
Segment descriptor describe segment , and contain place in virtual space , size , safety and more ...
-
Mittwoch, 5. September 2012 12:05Moderator
Hi rafal,
Thanks for your active participation.
Apparently, you have asked a lot of question in this thread. I temporarily marked two of the replies, which in my view have answered the questions in your original post. If you disagree with them, you can unmarked them.
Thanks,
Damon Zheng [MSFT]
MSDN Community Support | Feedback to us

