Step by step with inline assembler

Just starting out? Need help? Post your questions and find answers here.
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Step by step with inline assembler

Post by luis »

I was trying for the first time some inline assembler with PB, using the "!" followed by the ASM instructions.

I started the program with debug on and I was expecting to navigate inside the procedure containing the ASM one line at a time, instead the debugger skipped all the "!" prefixed code in just one big step.

Is there a way to accomplish this ?

Would be nice to at least verify if/when a jump is executed or not...

Thank you.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

The debugger would interfere with the asm. Why don't you set a variable to a new value if the jump is taken and examine the value afterwards.
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Post by luis »

Trond wrote:The debugger would interfere with the asm. Why don't you set a variable to a new value if the jump is taken and examine the value afterwards.
I seem to recall in visual studio you could debug asm routines too ?
Am I wrong ?
I remember debugging a C source with some inline asm and stepping into the asm... but maybe it wasn't executing the asm single step and only showing the disassembled code ... I really can't remember.

About the variable, I was hoping to not have to write some extra code who need to be removed afterwards. Not to mention one have to pay great attention the "debug code" doesn't interfere with the true code (flag, registers, etc.).
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6161
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

Dunno, but you tried ASM with the ! prefix, have you tried without?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6161
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

I just tried, and I seem to be able to step through the following:

Code: Select all

Global c.l
Global b.l
;
Procedure x()
  Protected b.l
  a.l
  MOV a.l,2
  MOV b.l,2
  MOV c.l,2
  Debug a
EndProcedure
;
x()
Debug c
Debug b
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Post by luis »

blueznl wrote:I just tried, and I seem to be able to step through the following:
You are right, seem to work.

I have not tried this mode 'cause I was more interested in use asm exactly as in fasm... and because quite frankly I don't understand very well how to use it this way. Code must be written differently, directives seem incompatibile, don't know where find some help about it...

But if can single step with this, I'll try to experiment with it.

Thank you.


For example, how can translate this simple code

Code: Select all

  Procedure Test(*Pointer)
     ! MOV EAX, dword [p.p_Pointer]  ; store in EAX the pointer 
     ! INC dword [EAX]               ; increment the 32 bit variable at the address pointed in EAX
  EndProcedure


Define a.l  = 10

Test(@a)

Debug a ; it will be 11

to make it compatible with inline assembly ?
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8433
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Code: Select all

Procedure Test(*Pointer) 
  EnableASM
    MOV EAX, dword [p.p_Pointer]  ; store in EAX the pointer 
    INC dword [EAX]               ; increment the 32 bit variable at the address pointed in EAX 
  DisableASM
EndProcedure 


Define a.l  = 10 

Test(@a) 

Debug a ; it will be 11 
BERESHEIT
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Post by luis »

LOL! TOO DIFFICULT!

OMG, I'm a little embarassed :oops:

I tried enabling inline asm but globally in the compiler options... I had a strange error on the test() call and I thought there was some problem in the use of "directives" (not the right word) like dword or something.

Now I can see enabling and disabling it only when needed cure the problem.

And the problem was due to the fact TEST is an asm instruction... damn! Nice naming choice!

Now I'll do some more experiments using explicits enable/disable pairs.

Thank you all.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6161
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

Dunno' if this is of some use to you...

http://www.xs4all.nl/~bluez/datatalk/pure10.htm#top
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Post by luis »

blueznl wrote:Dunno' if this is of some use to you...

http://www.xs4all.nl/~bluez/datatalk/pure10.htm#top
Thank you.

Ant thank you for maintaining your helpful site :)
Thorium
Addict
Addict
Posts: 1271
Joined: Sat Aug 15, 2009 6:59 pm

Post by Thorium »

You can also use a assembler level debugger like OllyDbg: http://www.ollydbg.de/
Very powerfull debugger, i use it often.

Edit:
Just one tipp on how to find your code with a assembler level debugger. Just add a "!int 3" to the start of your assemblercode. That interrupt is a debugger breakpoint. So just run the program with the debugger and it will pause if execution reach this instruction.

Code: Select all


  Procedure Test(*Pointer)
     ! INT 3 ; OllyDbg will break here
     ! MOV EAX, dword [p.p_Pointer]  ; store in EAX the pointer
     ! INC dword [EAX]               ; increment the 32 bit variable at the address pointed in EAX
  EndProcedure


Define a.l  = 10

Test(@a)

Debug a ; it will be 11
Post Reply