Archived

This topic is now archived and is closed to further replies.

Bruno

Assembly in VC 6 ++

Recommended Posts

Hi I''m tryng to make a little assembler function inside VC, and i keep getting a stupid compilation error. The error is: D:\diske\test.cpp(463) : error C2415: improper operand type being the line 463 the last assembler line. If i delete that line, then the compiler will go to the previous line, and so on, until i have no assembler code.. lol With _asm before each line, the result is the same., do i have to setup visual c, somewhere, so that i can compile asm inline code? thanks My code, is the following: void drawH(int ymin,int ymax,int y) { int i=ymin; __asm { um: mov ax,1 mov sbuffer[y],1 cmp i,ymax jne um } } thanks Bruno

Share this post


Link to post
Share on other sites
If it''s anything like Borland, it should be like this:

void drawH(int ymin,int ymax,int y)
{
int i=ymin;
__asm {
um:
mov ax,1
mov sbuffer[y],1
cmp i,ymax
jne um
}

Notice the squigily bracket just after __asm

Share this post


Link to post
Share on other sites
It''s been a long time ago since I''ve done assembly, but I think this will compile:

    
void drawH(int ymin, int ymax, int y)
{
int i=ymin;

__asm
{
um:
mov ax, 1
mov WORD PTR [sbuffer+y], 1
cmp i, ymax
jne um
}
}



btw. Just a question, why are you filling sbuffer with one byte at a time?

Share this post


Link to post
Share on other sites
Hi
thanks for the replys.
I have just started assembler., i''m filling one byte at a time, because i still don''t know a fast way to do it

I still can''t compile, i tried everything you guys said, my compiler simply refuses any assembler command.. , any ideias ???

Share this post


Link to post
Share on other sites
This works :D. I think it''s an endless loop though . I don''t know much asm at all. I learned just enough to understand adresses and values for pointers.

    __asm
{
um:
mov ax, 1
add ax, 2
jmp um
}

Share this post


Link to post
Share on other sites
Hmm.. don''t the labels have to be outside the brackets?

like:

void drawH(int ymin,int ymax,int y)
{
int i=ymin;
um:
__asm
{
mov ax,1
mov sbuffer[y],1
cmp i,ymax
jne um
}

Share this post


Link to post
Share on other sites
Kinda along the same lines, is it possible to switch to Mode 13 or Mode X using the VC++ console app? If I run a program where I switch to Mode 13 and back that I complied with Borland 3.1 I have no problem. But if I run the same program compiled under VC++ it gives me the blue screen of death.

    
#include <stdio.h>

void main()
{
_asm {
mov ax,ax;
mov ax,0x13;
int 0x10;
}
}

Share this post


Link to post
Share on other sites
Can any of you guys sent me, a little piece of code that compiles in your VC, just to check if it compiles in mine ?
I think i''m missing something here., my VC continues to refuse any assembly commands..

thanks

my email is brunomtc@hotmail.com

Bruno

Share this post


Link to post
Share on other sites
Use an assembler like masm/masm32/tasm/tasm32.
Then link the obj file created by the assembler to the
obj file created by the MSVC compiler, then the MSVC
linker to spit out an exe.

Inline assembly is 10x slower than the suggestion above!
You will have a difficult time trying to link the two objects
together and i''m a bit rusty so I don''t wanna make it harder
than it is. One note, tasm and borland uses OFF,
MSVC and masm uses COFF to create the obj file.
I think MSVC will automatically convert the OFF obj to COFF,
but i''m rusty.


Share this post


Link to post
Share on other sites
quote:
Original post by Bruno

void drawH(int ymin,int ymax,int y)
{
int i=ymin;
__asm
{
um:
mov ax,1
mov sbuffer[ i ][y],1
cmp i,ymax
jne um
}
}




1. mov ax,1
Why??? You don''t use it...

2. mov sbuffer[ i ][y],1
3. cmp i,ymax
This instructions can have just 1 memory operand.

What do you want exactly?
Just write it in C, and we''ll translate it to inline ASM.

Share this post


Link to post
Share on other sites
Hmm.. First of all: Masm is free. Even the latest versions

Second... You can''t change to mode 13h in a console app. Your application needs ring 0 priviliges (same rights as VMM), which you need a device driver in order to do. (in win9x you could do it by hijacking an interrupt, but that''s not recommended, as it is a bug and not a feature... In fact, viruses like CIH take advantage of this to give itself ring 0 rights.)

Third... What the cuckoo is your code doing? To me it seems like it gets stuck in an infinite loop... If it''d work, that is.

Try this... I think this is what you''re trying to do... But your code makes no sense, really, so I could be totally off.

    
void drawH(int ymin,int ymax)
{

__asm
{
mov ecx, ymin
mov eax, sbuffer
um:
mov WORD PTR [eax+ecx*2],1
cmp ecx,ymax
inc ecx
jle um
}

}

Share this post


Link to post
Share on other sites
quote:
Original post by gi-centerprintf
Inline assembly is 10x slower than the suggestion above!



What do you mean by that? Execution speed remains the same. An asm instruction is an asm instruction is an asm instruction... Or were you thinking of something else?

quote:

You will have a difficult time trying to link the two objects
together and i''m a bit rusty so I don''t wanna make it harder
than it is. One note, tasm and borland uses OFF,
MSVC and masm uses COFF to create the obj file.


Not trying to be picky or anything, but i think it''s OMF, as in O bject M odule F ormat :D



Share this post


Link to post
Share on other sites
quote:

Inline assembly is 10x slower than the suggestion above!



I too wondered about this. This effectively means that C++ implementations for some reason *change* the asm code to different asm code that is less efficient. I hate it when grossly misinformed people say things when they haven''t researched it one little bit!



-=[ Lucas ]=-

Share this post


Link to post
Share on other sites