» »

[C++ & asm] Microsoft visual studio 2008 in asm

[C++ & asm] Microsoft visual studio 2008 in asm

goranv ::

Imam problem pri prevanju, na internetu sem nasel razlicne primere v asm kodi in ce jo prekopiram v ta visual studio 2008 to kodo noce prevajat, ali je mogoce treba v tem programu nekatere stvari drugace napisati. Primer kode navadnega programa ki prebere dve stevili in ju nato izpise:


#include "stdafx.h"
#include "windows.h"
#include "stdio.h"
#include "conio.h"
#include "iostream"

using namespace std;



int _tmain(int argc, _TCHAR* argv[])
{
__asm
{
%include "asm_io.inc"
segment .data
prompt1 db "Enter a number: ", 0 ; don’t forget null terminator
prompt2 db "Enter another number: ", 0
outmsg1 db "You entered ", 0
outmsg2 db " and ", 0
outmsg3 db ", the sum of these is ", 0
segment .bss
input1 resd 1
input2 resd 1
segment .text
global _asm_main
_asm_main:
enter 0, 0
pusha

mov eax, prompt1
call print_string

call read_int
mov [ainput1, eax

mov eax, prompt2
call print_string

call read_int
mov [input2], eax

mov eax, input1
add eax, input2
mov ebx, eax

dump_regs1
dump_mem 2, outmsg1

mov eax, outmsg1
call print_string ; print out first message
mov eax, [input1]
call print_int ; print out input1
mov eax, outmsg2
call print_string ; print out second message
mov eax, [input2]
call print_int ; print out input2
mov eax, outmsg3

call print_string ; print out third message
mov eax, ebx
call print_int ; print out sum (ebx)
call print_nl

popa
mov eax, 0
leave
ret
}

_getche();
return 0;
}


Izpise napak:


1>e:\__c++\project_mvs2008\test1dos\test1dos\test1dos.cpp(18) : error C2400: inline assembler syntax error in 'opcode'; found 'MOD'
1>e:\__c++\project_mvs2008\test1dos\test1dos\test1dos.cpp(19) : error C2400: inline assembler syntax error in 'opcode'; found '.'
1>e:\__c++\project_mvs2008\test1dos\test1dos\test1dos.cpp(20) : error C2400: inline assembler syntax error in 'opcode'; found 'db'
1>e:\__c++\project_mvs2008\test1dos\test1dos\test1dos.cpp(21) : error C2400: inline assembler syntax error in 'opcode'; found 'db'
1>e:\__c++\project_mvs2008\test1dos\test1dos\test1dos.cpp(22) : error C2400: inline assembler syntax error in 'opcode'; found 'db'
1>e:\__c++\project_mvs2008\test1dos\test1dos\test1dos.cpp(23) : error C2400: inline assembler syntax error in 'opcode'; found 'db'
1>e:\__c++\project_mvs2008\test1dos\test1dos\test1dos.cpp(24) : error C2400: inline assembler syntax error in 'opcode'; found 'db'
1>e:\__c++\project_mvs2008\test1dos\test1dos\test1dos.cpp(25) : error C2400: inline assembler syntax error in 'opcode'; found 'bss'
1>e:\__c++\project_mvs2008\test1dos\test1dos\test1dos.cpp(26) : error C2400: inline assembler syntax error in 'opcode'; found 'resd'
1>e:\__c++\project_mvs2008\test1dos\test1dos\test1dos.cpp(27) : error C2400: inline assembler syntax error in 'opcode'; found 'resd'
1>e:\__c++\project_mvs2008\test1dos\test1dos\test1dos.cpp(28) : error C2400: inline assembler syntax error in 'opcode'; found 'text'
1>e:\__c++\project_mvs2008\test1dos\test1dos\test1dos.cpp(29) : error C2400: inline assembler syntax error in 'opcode'; found '_asm_main'
1>e:\__c++\project_mvs2008\test1dos\test1dos\test1dos.cpp(38) : error C2400: inline assembler syntax error in 'first operand'; found ','
1>e:\__c++\project_mvs2008\test1dos\test1dos\test1dos.cpp(51) : error C2400: inline assembler syntax error in 'opcode'; found 'newline'
1>e:\__c++\project_mvs2008\test1dos\test1dos\test1dos.cpp(51) : error C2400: inline assembler syntax error in 'opcode'; found 'constant'


LP

Gundolf ::

Jah Visual ma verjetno neka svoja pravila glede deklariranja asm kode. Sama koda mu je verjetno že všeč, a deklaracije spremenljivk/konstant, kot je: prompt1 db "Enter a number: ", 0 ; don’t forget null terminator pač sem ne sodijo. Take stvari moraš verjetno definirati na standardni C način. Tudi tole: %include "asm_io.inc" sigurno ne sodi v tole kodo, ker je direktiva za assembler in ne assemblerska koda. In tako dalje. Dvomim, da ti bo ratalo tole kodo pripraviti do tega da dela znotraj Visuala, če nimaš konkretnega znanja assemblerja. Tale koda je najverjetneje pisana za masm in lahko jo prevedeš tam ter nato linkaš v kak svoj C++ projekt.

goranv ::

Nasel sem resitev,asm kodo sem skopiral v datoteko .asm in jo vkljucil v projekt.

Zdaj pa nastane drug problem, pri masm32 manjkajo datoteke .inc, .lib.

Kje bi se dalo dobiti:

stdio.inc
stdio.lib
msvcrt.inc
msvcrt.lib
conio.inc
conio.lib


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

[C++]Kako narediti screenshot?

Oddelek: Programiranje
121510 (1081) *ziga*
»

[C++] Preverjanje ce je program dos ali win32

Oddelek: Programiranje
211402 (1058) BigWhale
»

Igra LOTUS...

Oddelek: Igre
51634 (1392) DonMatejo
»

Need for speed 1!

Oddelek: Igre
101205 (995) pingec
»

Programiranje (strani: 1 2 )

Oddelek: Programiranje
846515 (5113) Thomas

Več podobnih tem