problems with memory
problems with memory
I have a problem: I wrote a procedure which enters big-real mode. it works (i have checked it) it also enables a20 gate through KBC (the program checs for A20-ON bit set in the IO register.. and i seems to be SET) well, here's the code snippet:
-----------------------------------
???call enable_32
(1)???lea esi,[image_buff]
???mov edi,0x000b8000
???mov ecx,512
???cld
a32???rep movsb
(2)???lea esi,[image_buff]
???mov edi,0x00200000
???mov ecx,512
a32???rep movsb
-------------------------------------
well, snippet (1) works. and snippet (2) doesn't work
oh, one and useful note, I have Compaq DeskPro (based on P1) and could it be the reason of that?
-----------------------------------
???call enable_32
(1)???lea esi,[image_buff]
???mov edi,0x000b8000
???mov ecx,512
???cld
a32???rep movsb
(2)???lea esi,[image_buff]
???mov edi,0x00200000
???mov ecx,512
a32???rep movsb
-------------------------------------
well, snippet (1) works. and snippet (2) doesn't work
oh, one and useful note, I have Compaq DeskPro (based on P1) and could it be the reason of that?
Re:problems with memory
it has 24MBytes of RAM. I have tested the code on 486 machine and it did the same there too so there must be something wrong in the xode ??? :-\
Re:problems with memory
ok, here's the code:
Code: Select all
[BITS 16]
[ORG 0x100]
call enable_32
call enable_a20
lea esi,[image_buff]
mov edi,0x00100000
mov ecx,512
cld
a32 rep movsb
cmp byte [es:0x00100000],'a'
je E3
mov ah,0x09
lea dx,[M0]
int 0x21
ret
M0 db 'problems with memory :(',13,10,'$'
E3: sti
mov ah,0x09
lea dx,[E3.M0]
int 0x21
ret
M0 db 'ok',13,10,'$'
image_buff times 512 db 'a'
%include '..\include\loader.inc'
Re:problems with memory
this is the modified code. changes were made to test the A20 state:
it showed "problems with memory" for different values (not random values ofcourse) it showed, that the x86-specific memory-wrapping is still enabled. ??? ::)
Code: Select all
[BITS 16]
[ORG 0x100]
call enable_32
call enable_a20
mov eax,dword[es:0x00207000]
cmp eax,dword[es:0x00307000]
jne E3
mov ah,0x09
lea dx,[M0]
int 0x21
ret
M0 db 'problems with memory :(',13,10,'$'
E3: mov ah,0x09
lea dx,[E3.M0]
int 0x21
ret
.M0 db 'ok',13,10,'$'
%include '..\include\loader.inc'
Re:problems with memory
Hi,
Just curious, but which assembler?
For NASM, in 16 bit mode it will silently truncate 32 bit memory references unless there's a 32 bit register in the effective address. For example:
Will become:
To fix this, you need to put the "dword" keyword inside the square brackets - for e.g.:
Alternatively, if there's a 32 bit register this isn't needed - for e.g. you could do:
In this case NASM knows it's a 32 bit address because you've used EDI instead of just DI. The same sort of thing applies to more complex effective addresses. For example, this works:
If the "dword" keyword is outside of the brackets, then it's telling NASM to use 32 bit data values (not 32 bit addresses). For example, all of these instructions will generate the exact same code (in 16 bit mode):
The "dword" keyword is only needed outside of the brackets when NASM can't figure out the size of the data. Normally it isn't needed because the source or destination is a register, and NASM can work out the size of the data from the size of the register used. For example, NASM will complain about these lines because it can't figure out what size the data is:
Instead you'd need to change these to something like:
Anyway, compare your source code with the output from a disassembler to see if it looks the same....
Cheers,
Brendan
Just curious, but which assembler?
For NASM, in 16 bit mode it will silently truncate 32 bit memory references unless there's a 32 bit register in the effective address. For example:
Code: Select all
mov eax,dword[es:0x00207000]
cmp eax,dword[es:0x00307000]
Code: Select all
mov eax,dword[es:0x7000]
cmp eax,dword[es:0x7000]
Code: Select all
mov eax,dword [dword es:0x00207000]
cmp eax,dword [dword es:0x00307000]
Code: Select all
mov edi,0x00207000
mov eax,dword [es:edi]
Code: Select all
mov edi,0
mov eax,dword [es:edi+0x00207000]
Code: Select all
mov eax,dword [es:0x00207000]
mov eax,dword [es:0x7000]
mov eax,[es:0x00207000]
mov eax,[es:0x7000]
mov eax,dword [word es:0x00207000]
mov eax,dword [word es:0x7000]
mov eax,[word es:0x00207000]
mov eax,[word es:0x7000]
Code: Select all
mov [0x1234],0
movzx eax,[0x1234]
Code: Select all
mov dword [0x1234],0
mov word [0x1234],0
mov byte [0x1234],0
movzx eax,byte [0x1234]
movzx eax,word [0x1234]
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re:problems with memory
that's ok guys i've fixed the problem. Brendan, your comment is right, 10x. I replaced
mov [es:0x000b8000],'1234' with
mov [es:DWORD 0x000b8000],'1234'
and it helped. there were also some errors in the flat-real mode procedure. I've fixed them too. so the code just works fine ;D
mov [es:0x000b8000],'1234' with
mov [es:DWORD 0x000b8000],'1234'
and it helped. there were also some errors in the flat-real mode procedure. I've fixed them too. so the code just works fine ;D