Assembly code

First, I have some code :
1
2
3
4
5
6
7
8
9
10
int main()
{
//printf("Number : %d", 10);
__asm
{
push "Number : %d";
push 10;
call printf;
}
}

But I get several crazy compling errors.
Can anyone explain "what is wrong in my code"? And how to fix it?
Last edited on
I'd say that the push on line 6 looks really fishy. What is pushing a string literal supposed to mean?
Maybe try posting the errors...
Actually I don't know much how to call a function by assembly... :)
Last edited on
I tried to call the function by assembly code but no luck :(

Here is my latest code :
1
2
3
4
5
6
7
8
9
10
int main()
{
char *str = "Number : %d";
unsigned int len = strlen(str);

for(unsigned int i = 0;i < len;i++)
__asm push str[i]
__asm push 10
__asm call printf
}
Last edited on
Does anyone know the crash assembly error? (I am now very confused hmm...)
First of all, what compiler are you using?
I am? Using VS2005 (Visual Studio 2005). It's really old, right? :)
But I think the program crash is not the error compiler itself...
Last edited on
I'm honestly shocked that this actually is the calling convention for printf().
Anyway, you're pushing the parameters in reverse order. Also this bit:
__asm push str[i]
Makes no sense.

1
2
3
4
5
6
const char *format="Number : %d";
__asm{
	push 10;
	push format;
	call printf;
}
helios wrote:
I'm honestly shocked that this actually is the calling convention for printf().
Indeed, I didn't think anyone uses stacks these days.

I just checked my development boxes:
 
Platform(compiler)   format (char*)   the number (int)
x86_64(GCC)                 %rsi           %edx
x86_64(Intel, Clang)        %rdi           %esi
IBM(GCC, XLC)               %r4            %r3
Solaris(Sun)                %o0            %o1
CPU registers as expected.

Jackson Marie wrote:
I am? Using VS2005 (Visual Studio 2005). It's really old, right?

Assembly languages are different on every platform, and the syntax for inserting them into C++ programs is different on every compiler. It's not that VS2005 is old, it's that you need to read its documentation or find someone who uses inline assembly in Visual Studio specifically,
Last edited on
Thanks you very much helios and Cubbi!!
I want to get into assembly, thres amazing raspberry Pi guides...im gonna mess with everything that plugs into computers, change error codes yooh name it
I hope you know some great computer architecture^ assembly requires you to know the instruction set architecture as well as the system architecture.
@DeXecipher, is that a comment about Pi? If not, I'll have to say you're wrong. To write most programs in assembly you don't need more knowledge about computer architecture that in any other language. Note, operating systems and etc. are not included in "most programs".
Of course, that does not apply if you were talking about writing good code...
@hamsterman You cant write assembly without knowing the word size for the architecture and the size of a byte and the type of addressing and modes that the architecture uses. Depending on the assembly language you cant even effectively program if you dont know what a register is or a stack is. Tutorials only take you so far.

Edit: Instead of great in depth architecture i really mean the basics, what an interrupt is, what a register is and how to access main memory for reading and writing data (interrupts).
Last edited on
I guess with assembly there is a narrow line between the language architecture and the system architecture.
Topic archived. No new replies allowed.