flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > Print out register values

Author
Thread Post new topic Reply to topic
masterducky



Joined: 12 May 2010
Posts: 10
masterducky
Hi!

I would like to print out the values in registers in inline C.
What am i doing wrong?

Code:

#include <stdio.h>

int main()
{
    _asm
    {
       mov ecx, 5
       mov eax, ecx
       push eax
       call printf
       pop ebx
    }
    return 0;
}

    
Post 14 May 2010, 16:04
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
http://www.cplusplus.com/reference/clibrary/cstdio/printf/

maybe you don't push enough parameters on the stack.

Code:
mov ecx,5
mov eax,ecx
push eax
    

:s
Code:
push dword 5
    
is enough
Post 14 May 2010, 16:12
View user's profile Send private message Visit poster's website Reply with quote
masterducky



Joined: 12 May 2010
Posts: 10
masterducky
Yes of course, how could i forget it, it needs two arguments.

By the way it compiles rather this way:

Code:
 push dword ptr 5     


Thank you Ed!
Post 14 May 2010, 16:30
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Quote:

By the way it compiles rather this way:


Code:
push dword ptr 5

That will be equivalent to "push dword [5]" which is an assured crash in Windows and probably in many others OSes that never allocate too low addresses.
Post 14 May 2010, 16:47
View user's profile Send private message Reply with quote
masterducky



Joined: 12 May 2010
Posts: 10
masterducky
Thanks for letting me know that.
Post 14 May 2010, 18:40
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin
depending on what you want ..
This works. if your using visual c++ ..

use the regs... to do the work ... then print with the standard lib outside the asm tags...

Code:
#include <stdio.h> 


int main() 
{ 

    int some_var=0;
    _asm 
    { 
       mov ecx, 5 
       mov eax, ecx 
       mov [some_var],eax
    } 

   printf("Value of some var: %i ",some_var);
    return 0; 
} 

    
Post 14 May 2010, 23:36
View user's profile Send private message Reply with quote
masterducky



Joined: 12 May 2010
Posts: 10
masterducky
Awesome, that's what i wanted to do.

Thank you Dosin!
Post 15 May 2010, 04:09
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.