MSVC CHOKES on this ASM putpixel routine! 
Author Message
 MSVC CHOKES on this ASM putpixel routine!

This is a putpixel function....Lookup_Table is 200 unsigned integers
containing the offsets of row 1, row 2, etc.  (To eliminate multiplication
of any kind)

My compiler choked on even the Lookup_table part...nevermind trying to port
it to write to a 64K BUFFER instead of the screen, which I don't want to
do!

BUFFER_SEG=_FP_SEG(buffer);            // Get the buffer's segment address
When I say mov es, BUFFER_SEG, it also chokes.   (It calls it an "illegal
symbol")

It seems that Microsoft's documentation contradicts this problem.  

Can anyone help me on this?  I have Microsoft Visual C++ 1.52.  The
documentation says it can use any variables and structs withing the _asm's
curly braces.  I don't know about the [] though, that might be too much.  I
found this source code on the net, and I'd assume he'd have tested it
before posting it.  What's wrong here?

        _asm {
mov es, A000h
        mov al, val
        mov bx, y
        shl bx, 1
        mov bx, Lookup_Table[bx]      
        add bx, x
        mov es:[bx], al
        }

--
Matt McDevitt
MAKTOS (at) ix.netcom.com
Maktos Productions Homepage
http://www.*-*-*.com/

Spammers and Commercial e-mailers beware:

"By US Code Title 47, Sec.227(a)(2)(B), a computer/modem/printer
meets the definition of a telephone fax machine.
By Sec.227(b)(1)(C), it is unlawful to send any unsolicited
adverti{*filter*}t to such equipment.
By Sec.227(b)(3)(C), a violation of the aforementioned Section is
punishable by action to recover actual monetary loss, or $500,
whichever is greater, for each violation."



Sun, 03 Oct 1999 03:00:00 GMT  
 MSVC CHOKES on this ASM putpixel routine!

On Wed, 16 Apr 1997 22:52:33 -0500, "Matt McDevitt"

Quote:

>BUFFER_SEG=_FP_SEG(buffer);            // Get the buffer's segment address
>When I say mov es, BUFFER_SEG, it also chokes.   (It calls it an "illegal
>symbol")

The problem is, that you cannot load a segment register with immediate
data as in mov es, 0A000h.
Use
        mov ax, 0A000h
        mov es, ax
instead.

--



Mon, 04 Oct 1999 03:00:00 GMT  
 MSVC CHOKES on this ASM putpixel routine!

Quote:

> This is a putpixel function....Lookup_Table is 200 unsigned integers
> containing the offsets of row 1, row 2, etc.  (To eliminate multiplication
> of any kind)
[snip]
> Can anyone help me on this?  I have Microsoft Visual C++ 1.52.  The
> documentation says it can use any variables and structs withing the _asm's
> curly braces.  I don't know about the [] though, that might be too much.  I
> found this source code on the net, and I'd assume he'd have tested it
> before posting it.  What's wrong here?

>         _asm {
> mov es, A000h

Two errors:

a) The hex constants need to start with a numeric digit, i.e. 0A000h

b) You cannot move an immediate value into a segment register!
   Use MOV AX,0A000h / MOV ES,AX instead.

Quote:
>         mov al, val
>         mov bx, y
>         shl bx, 1
>         mov bx, Lookup_Table[bx]

Try
        MOV BX, WORD PTR Lookup_Table[bx]
instead!

Due to cache misses this might be slower than a shift & add combination.

Quote:
>         add bx, x

Terje

--

Using self-discipline, see http://www.eiffel.com/discipline
"almost all programming can be viewed as an exercise in caching"



Mon, 04 Oct 1999 03:00:00 GMT  
 MSVC CHOKES on this ASM putpixel routine!

Quote:

> This is a putpixel function....Lookup_Table is 200 unsigned integers
>    _asm {
>       mov es, A000h
>    mov al, val
>    mov bx, y
>    shl bx, 1
>    mov bx, Lookup_Table[bx]      
>    add bx, x
>    mov es:[bx], al
>    }

As pointed out in the previous response, you can't load es with an immediate
value. Also, make sure you are using 16 bit unsigned integers. It seems to
me (though I have little experience myself) that some C compilers use 32
bit values for integers, in which case you'd have to "shl bx,2" (if you use
386+ instructions otherwise do two times "shl bx,1"). Assuming you are
on an intel processor, you can then load a 16 bit value from Lookup_Table[bx].
Beware of other systems though, some use big-, some little endian, and
you might have to add 2 to bx then. Best thing is to make sure you have
16 bit integers...

Also, if you consider using regsiter di in stead of bx, you can leave out the
"es:" part in the last instruction, which probably saves one whole byte of
code in the end... I think the other instructions with di in stead of bx
would be of equal size.

Regards, Maarten 'Elmer' Egmond,
second year physics student at the Eindhoven University of Technology
www: http://www.*-*-*.com/ ~ep                         email: ep (at) dds.nl
----------Be a friend to the Earth, and it will be a friend to you----------
Today's tagline: Children: the most common {*filter*}ly transmitted disease.



Mon, 04 Oct 1999 03:00:00 GMT  
 MSVC CHOKES on this ASM putpixel routine!

I modified it a bit for the es:ax thing......

        _asm {
        mov ax, 0a000h
        mov es, ax
        mov al, val
        mov bx, y
        shl bx, 1
        mov bx, WORD PTR Table[bx]       <-----line 142
        add bx, x
        mov es:[bx], al
        }

And it gives me this:

c:\msvc\files\mpgraph.cpp(142) : error C2420: 'Table' : illegal symbol in
operand 2
But it seems it won't accept SCREEN_SEG or anything other than a  HARD
CODED value for what I initially move into AX (the first line), plus
anything with [] throws it for a
loop.  How else can I do this?
Matt McDevitt


Quote:
>This is a putpixel function....Lookup_Table is 200 unsigned integers
>containing the offsets of row 1, row 2, etc.  (To eliminate multiplication
>of any kind)

>My compiler choked on even the Lookup_table part...nevermind trying to
port
>it to write to a 64K BUFFER instead of the screen, which I don't want to
>do!

>BUFFER_SEG=_FP_SEG(buffer);            // Get the buffer's segment
address
>When I say mov es, BUFFER_SEG, it also chokes.   (It calls it an "illegal
>symbol")

>It seems that Microsoft's documentation contradicts this problem.

>Can anyone help me on this?  I have Microsoft Visual C++ 1.52.  The
>documentation says it can use any variables and structs withing the
_asm's
>curly braces.  I don't know about the [] though, that might be too much.
I
>found this source code on the net, and I'd assume he'd have tested it
>before posting it.  What's wrong here?

> _asm {
>mov es, A000h
> mov al, val
> mov bx, y
> shl bx, 1
> mov bx, Lookup_Table[bx]    
> add bx, x
> mov es:[bx], al
> }

>--
>Matt McDevitt
>MAKTOS (at) ix.netcom.com
>Maktos Productions Homepage
> http://www.*-*-*.com/

>Spammers and Commercial e-mailers beware:

>"By US Code Title 47, Sec.227(a)(2)(B), a computer/modem/printer
>meets the definition of a telephone fax machine.
>By Sec.227(b)(1)(C), it is unlawful to send any unsolicited
>adverti{*filter*}t to such equipment.
>By Sec.227(b)(3)(C), a violation of the aforementioned Section is
>punishable by action to recover actual monetary loss, or $500,
>whichever is greater, for each violation."



Mon, 04 Oct 1999 03:00:00 GMT  
 MSVC CHOKES on this ASM putpixel routine!


Quote:

>I modified it a bit for the es:ax thing......

>    _asm {
>    mov ax, 0a000h
>    mov es, ax
>    mov al, val
>    mov bx, y
>    shl bx, 1
>    mov bx, WORD PTR Table[bx]       <-----line 142
>    add bx, x
>    mov es:[bx], al
>    }

  Since you're using Visual C++ (for Win32, right?), video
  memory doesn't reside at 0a000h.  Visual C++ programs
  work in protected mode so I recommend you s{*filter*}that
  putpixel routine (which looks like it was designed for
  16-bit realmode code).

--



Tue, 05 Oct 1999 03:00:00 GMT  
 MSVC CHOKES on this ASM putpixel routine!

I think, for one, you can't load ES with a base address like you've done
with that code.  Try something like

                push  0a000h
                pop   es
or
                mov   ax,0a000h
                mov   es,ax

Isn't this for real mode as well?  
You would need to set up SI as well, as a pointer into the lookup table
array.  I don't think this code does that... (Might be wrong, sorry if I
am)  *8)

Stay Gravy!

On that fateful day of Wed, 16 Apr 1997, Matt McDevitt proclaimed:

Quote:

> This is a putpixel function....Lookup_Table is 200 unsigned integers
> containing the offsets of row 1, row 2, etc.  (To eliminate multiplication
> of any kind)

> My compiler choked on even the Lookup_table part...nevermind trying to port
> it to write to a 64K BUFFER instead of the screen, which I don't want to
> do!

> BUFFER_SEG=_FP_SEG(buffer);            // Get the buffer's segment address
> When I say mov es, BUFFER_SEG, it also chokes.   (It calls it an "illegal
> symbol")

> It seems that Microsoft's documentation contradicts this problem.  

> Can anyone help me on this?  I have Microsoft Visual C++ 1.52.  The
> documentation says it can use any variables and structs withing the _asm's
> curly braces.  I don't know about the [] though, that might be too much.  I
> found this source code on the net, and I'd assume he'd have tested it
> before posting it.  What's wrong here?

>    _asm {
> mov es, A000h
>    mov al, val
>    mov bx, y
>    shl bx, 1
>    mov bx, Lookup_Table[bx]      
>    add bx, x
>    mov es:[bx], al
>    }

> --

     O   O
-oooO--(_)---Oooo-------------------------------------------------------
     .MiK.                Any sufficiently complicated technology      
TIAS (c) Labs. 1997           is no diferrent from Magick
------------------------------------------------------------------------    
 .oooO   Oooo.            Brisbane, Gold and Sunshine Coasts
 ( Y )   ( Y )    Aah!  No Spam!  No.... Spam!!!  AAArrrrgggghhh!!...
--\ (-----) /-----------------------------------------------------------
   \_)   (_/    


Tue, 05 Oct 1999 03:00:00 GMT  
 MSVC CHOKES on this ASM putpixel routine!

It is realmode...it's Visual C++ 1.52 for DOS and Win 3.1....it came with
Visual C++ 4.0 (win95) which I'm not into yet.

Quote:


>>I modified it a bit for the es:ax thing......

>> _asm {
>> mov ax, 0a000h
>> mov es, ax
>> mov al, val
>> mov bx, y
>> shl bx, 1
>> mov bx, WORD PTR Table[bx]       <-----line 142
>> add bx, x
>> mov es:[bx], al
>> }

>  Since you're using Visual C++ (for Win32, right?), video
>  memory doesn't reside at 0a000h.  Visual C++ programs
>  work in protected mode so I recommend you s{*filter*}that
>  putpixel routine (which looks like it was designed for
>  16-bit realmode code).

>--

...



Wed, 06 Oct 1999 03:00:00 GMT  
 MSVC CHOKES on this ASM putpixel routine!



Quote:
> I modified it a bit for the es:ax thing......

>    _asm {
>    mov ax, 0a000h
>    mov es, ax
>    mov al, val
>    mov bx, y
>    shl bx, 1
>    mov bx, WORD PTR Table[bx]       <-----line 142
>    add bx, x
>    mov es:[bx], al
>    }

It's still not clear what your problem is, but it doesn't look like
the assembler is the problem.  The following compiles cleanly with my
copy of VC 1.52c:

int Table[200];
unsigned screen_seg = 0xA000;  

void init(void) {

    int I, offset;

        for (I=0, offset= 0; I<200; I++, offset += 320)
                Table[I] = offset;

Quote:
}              

void putpixel(int x, int y, char val) {

        _asm {
                mov ax, screen_seg
                mov es, ax
                mov al, val
                mov bx, y
                shl bx, 1
                mov bx, WORD PTR Table[bx]
                add bx, x
                mov es:[bx], al
        }

Quote:
}      

--
    Later,
    Jerry.


Wed, 06 Oct 1999 03:00:00 GMT  
 MSVC CHOKES on this ASM putpixel routine!

Quote:



> >I modified it a bit for the es:ax thing......

> >       _asm {
> >       mov ax, 0a000h
> >       mov es, ax
> >       mov al, val
> >       mov bx, y
> >       shl bx, 1
> >       mov bx, WORD PTR Table[bx]       <-----line 142
> >       add bx, x
> >       mov es:[bx], al
> >       }

sorry ... i missed the original message ...
but should'nt es be 0a0000h  (FOUR zeros) ... in p-mode it definitly
should ...

ciao
anti



Tue, 02 Nov 1999 03:00:00 GMT  
 MSVC CHOKES on this ASM putpixel routine!


Quote:


>> >       mov ax, 0a000h
>> >       mov es, ax

>sorry ... i missed the original message ...
>but should'nt es be 0a0000h  (FOUR zeros) ... in p-mode it definitly
>should ...

  No way.  In real mode, the segment register value gets shifted left 4 bits in
forming the resolved address.  In protected mode, it's an index into a
descriptor table, and so probably has some other value.  But the register
itself is never more than 16 bits long, so trying to shove 0A0000 into it will
set ES to ZERO.

Dave



Fri, 05 Nov 1999 03:00:00 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. MSVC CHOKES on this ASM putpixel routine!

2. porting inline Watcom asm to MSVC inline asm

3. PutPixel Routine

4. need a FAST putpixel routine

5. FAST PUTPIXEL ROUTINE IN VESA?

6. Cycle-exact Pentium timing routine for MSVC 4.2

7. MSVC's ASM is really messed up

8. MSVC 4.2 re-arranges inline asm

9. Interrupt Service Routine in asm help wanted

10. Calling asm routines from modula2

11. newbie question: calling asm routines from c

12. Interrupt Service Routine in asm help wanted

 

 
Powered by phpBB® Forum Software