在vc中嵌入如下的汇编代码:
__asm
{
data segment
buf db 100 dup(?)
data ends
stack segment stack'stack'
db 100 dup(?)
stack ends
code segment
assume cs:code,ds:data,es:data,ss:stack
start: mov ax,0000h
mov ds,ax
mov dx,ax
mov al,99h
shl al,1
shl al,1
mov ah,4ch
int 21h
start endp
code ends
end start
}
编译器提示如下错误:
E:\dingjie\1\1Dlg.cpp(380) : error C2400: inline assembler syntax error in 'opcode'; found 'segment'
E:\dingjie\1\1Dlg.cpp(381) : error C2400: inline assembler syntax error in 'opcode'; found 'db'
E:\dingjie\1\1Dlg.cpp(382) : error C2400: inline assembler syntax error in 'opcode'; found 'ends'
E:\dingjie\1\1Dlg.cpp(383) : error C2400: inline assembler syntax error in 'opcode'; found 'segment'
E:\dingjie\1\1Dlg.cpp(383) : error C2015: too many characters in constant
E:\dingjie\1\1Dlg.cpp(384) : error C2400: inline assembler syntax error in 'opcode'; found 'constant'
E:\dingjie\1\1Dlg.cpp(385) : error C2400: inline assembler syntax error in 'opcode'; found 'ends'
E:\dingjie\1\1Dlg.cpp(386) : error C2400: inline assembler syntax error in 'opcode'; found 'segment'
E:\dingjie\1\1Dlg.cpp(387) : warning C4405: 'cs' : identifier is reserved word
E:\dingjie\1\1Dlg.cpp(387) : error C2400: inline assembler syntax error in 'opcode'; found 'cs'
E:\dingjie\1\1Dlg.cpp(396) : error C2400: inline assembler syntax error in 'opcode'; found 'endp'
E:\dingjie\1\1Dlg.cpp(397) : error C2400: inline assembler syntax error in 'opcode'; found 'ends'
E:\dingjie\1\1Dlg.cpp(398) : error C2400: inline assembler syntax error in 'opcode'; found 'start'
E:\dingjie\1\1Dlg.cpp(418) : warning C4138: '*/' found outside of comment
E:\dingjie\1\1Dlg.cpp(418) : error C2059: syntax error : '/'
E:\dingjie\1\1Dlg.cpp(420) : error C2143: syntax error : missing ';' before '}'
E:\dingjie\1\1Dlg.cpp(420) : error C2143: syntax error : missing ';' before '}'
E:\dingjie\1\1Dlg.cpp(420) : error C2143: syntax error : missing ';' before '}'
Error executing cl.exe.1.exe - 16 error(s), 2 warning(s)
请问如何解决?
__asm
{
data segment
buf db 100 dup(?)
data ends
stack segment stack'stack'
db 100 dup(?)
stack ends
code segment
assume cs:code,ds:data,es:data,ss:stack
start: mov ax,0000h
mov ds,ax
mov dx,ax
mov al,99h
shl al,1
shl al,1
mov ah,4ch
int 21h
start endp
code ends
end start
}
编译器提示如下错误:
E:\dingjie\1\1Dlg.cpp(380) : error C2400: inline assembler syntax error in 'opcode'; found 'segment'
E:\dingjie\1\1Dlg.cpp(381) : error C2400: inline assembler syntax error in 'opcode'; found 'db'
E:\dingjie\1\1Dlg.cpp(382) : error C2400: inline assembler syntax error in 'opcode'; found 'ends'
E:\dingjie\1\1Dlg.cpp(383) : error C2400: inline assembler syntax error in 'opcode'; found 'segment'
E:\dingjie\1\1Dlg.cpp(383) : error C2015: too many characters in constant
E:\dingjie\1\1Dlg.cpp(384) : error C2400: inline assembler syntax error in 'opcode'; found 'constant'
E:\dingjie\1\1Dlg.cpp(385) : error C2400: inline assembler syntax error in 'opcode'; found 'ends'
E:\dingjie\1\1Dlg.cpp(386) : error C2400: inline assembler syntax error in 'opcode'; found 'segment'
E:\dingjie\1\1Dlg.cpp(387) : warning C4405: 'cs' : identifier is reserved word
E:\dingjie\1\1Dlg.cpp(387) : error C2400: inline assembler syntax error in 'opcode'; found 'cs'
E:\dingjie\1\1Dlg.cpp(396) : error C2400: inline assembler syntax error in 'opcode'; found 'endp'
E:\dingjie\1\1Dlg.cpp(397) : error C2400: inline assembler syntax error in 'opcode'; found 'ends'
E:\dingjie\1\1Dlg.cpp(398) : error C2400: inline assembler syntax error in 'opcode'; found 'start'
E:\dingjie\1\1Dlg.cpp(418) : warning C4138: '*/' found outside of comment
E:\dingjie\1\1Dlg.cpp(418) : error C2059: syntax error : '/'
E:\dingjie\1\1Dlg.cpp(420) : error C2143: syntax error : missing ';' before '}'
E:\dingjie\1\1Dlg.cpp(420) : error C2143: syntax error : missing ';' before '}'
E:\dingjie\1\1Dlg.cpp(420) : error C2143: syntax error : missing ';' before '}'
Error executing cl.exe.1.exe - 16 error(s), 2 warning(s)
请问如何解决?
VC 是可以嵌入汇编,可是你嵌入的是一个完整的汇编程序,这有些不合理吧.
试想,如果可以嵌入完整的汇编程序,那 VC 岂不是可以叫 VA(Visual Asm)了:) 你把那些定义段的伪代码去掉,然后将变量定义放在 __asm{} 前面(嵌入代
码可以访问到这些变量的).然后再编译,应该没问题了:)
you need write asm seperately and call it by prepare a thunk.even if by this way,commonly you can not call 16 bit code from 32 bit code in ring3.
_asm
{
加入实现应用的汇编代码。
}
就行了。