NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: Wannabe Developer on February 27, 2011, 03:56:12 AM
-
Below I have a script that's supposed to place a certain colored pixel at a given position (address)...but I get the error message "error: beroset-p-637-invalid effective address" at line 28. Any help on this would be nice, many thanks!
color db 0xff0000 ; 27 - pixel color
position db 0xa000, 0000 ; 28 - pixel position
label1: mov ebp, [color + position] ; 29 - write (color, position->ebp)
%macro clearreg 1-* ; 31 - clear register
%rep %0 ; 32
push %1 ; 33
%rotate 1 ; 34
%endrep ; 35
%endmacro ; 36
offset db 0x13 ; 38 - video memory offset
label2: mov 0xa000, [offset + ebp] ; 39 - write (ebp->video memory)
%macro clearvid 1-* ; 41 - clear video memory
%rep %0 ; 42
push %1 ; 43
%rotate 1 ; 44
%endrep ; 45
%endmacro ; 46
-
I think that you are off by one line in your source code counting, and I believe that this is the line in question:
label1: mov ebp, [color + position] ; 29 - write (color, position->ebp)
As a rule, don't use two potentially relocatable addresses (e.g. any label/address that can be move around by optimization) as a combined memory reference.
Within the context of your code, you are probably trying to achieve the following:
color dd 0xff0000 ; 27 - pixel color
position dd 0xa0000000 ; 28 - pixel position
label1: mov ebp, DWORD[color] ; 29 - write (color->ebp)
add ebp, DWORD[position] ; 30 - add (position->ebp)
%macro clearreg 1-* ; 32 - clear register
%rep %0 ; 33
push %1 ; 34
%rotate 1 ; 35
%endrep ; 36
%endmacro ; 37
offset dd 0x13 ; 39 - video memory offset
label2: add ebp,DWORD[offset] ; 40 add (offset->ebp)
mov DWORD[0xa000],ebp ; 41 - write (ebp->video memory)
%macro clearvid 1-* ; 42 - clear video memory
%rep %0 ; 43
push %1 ; 44
%rotate 1 ; 45
%endrep ; 46
%endmacro ; 47
Note that there are quite a few more mistakes in your code besides the ones I implicitly corrected via the above example.
I would suggest (re)reading the NASM Documentation in regard to memory references and the like.
-
I think that you are off by one line in your source code counting, and I believe that this is the line in question:
label1: mov ebp, [color + position] ; 29 - write (color, position->ebp)
As a rule, don't use two potentially relocatable addresses (e.g. any label/address that can be move around by optimization) as a combined memory reference.
Within the context of your code, you are probably trying to achieve the following:
color dd 0xff0000 ; 27 - pixel color
position dd 0xa0000000 ; 28 - pixel position
label1: mov ebp, DWORD[color] ; 29 - write (color->ebp)
add ebp, DWORD[position] ; 30 - add (position->ebp)
%macro clearreg 1-* ; 32 - clear register
%rep %0 ; 33
push %1 ; 34
%rotate 1 ; 35
%endrep ; 36
%endmacro ; 37
offset dd 0x13 ; 39 - video memory offset
label2: add ebp,DWORD[offset] ; 40 add (offset->ebp)
mov DWORD[0xa000],ebp ; 41 - write (ebp->video memory)
%macro clearvid 1-* ; 42 - clear video memory
%rep %0 ; 43
push %1 ; 44
%rotate 1 ; 45
%endrep ; 46
%endmacro ; 47
Note that there are quite a few more mistakes in your code besides the ones I implicitly corrected via the above example.
I would suggest (re)reading the NASM Documentation in regard to memory references and the like.
Thanks, I'll try it out!