Page 1 of 1

PS2=64 - What instruction is this?

Posted: Wed Nov 17, 2021 6:04 pm
by ricardo_sdl
I looked at the assembly for a simple procedure:

Code: Select all

; Procedure.i IsOdd(n.i)
_Procedure2:
  MOV    qword [rsp+8],rcx
  PUSH   r15
  PS2=64
  XOR    rax,rax
  PUSH   rax
  SUB    rsp,40
; ProcedureReturn n & %1
  MOV    r15,qword [rsp+PS2+0]
  AND    r15,1
  MOV    rax,r15
  JMP   _EndProcedure3
; EndProcedure
_EndProcedureZero3:
  XOR    rax,rax
_EndProcedure3:
  ADD    rsp,48
  POP    r15
  RET
What is the instruction PS2=64? PS2 doesn't appear anywhere else in the assembly code. Is it something peculiar to the assembler (flatassembler)? My PureBasic version is PureBasic 5.73 LTS (Windows - x64).

Re: PS2=64 - What instruction is this?

Posted: Wed Nov 17, 2021 6:18 pm
by STARGÅTE
It is an offset for the stack and it is used in
MOV r15,qword [rsp+PS2+0]

Re: PS2=64 - What instruction is this?

Posted: Wed Nov 17, 2021 6:57 pm
by ricardo_sdl
STARGÅTE wrote: Wed Nov 17, 2021 6:18 pm It is an offset for the stack and it is used in
MOV r15,qword [rsp+PS2+0]
In the context of the assembler PS2 is a local variable for the procedure? Shouldn't it be declared in some place? Is PS2 some kind of macro available in flatassembler? Is it idiomatic for x64 assembly language?

Re: PS2=64 - What instruction is this?

Posted: Wed Nov 17, 2021 7:17 pm
by STARGÅTE
ricardo_sdl wrote: Wed Nov 17, 2021 6:57 pm
STARGÅTE wrote: Wed Nov 17, 2021 6:18 pm It is an offset for the stack and it is used in
MOV r15,qword [rsp+PS2+0]
In the context of the assembler PS2 is a local variable for the procedure? Shouldn't it be declared in some place? Is PS2 some kind of macro available in flatassembler? Is it idiomatic for x64 assembly language?
It is a global variable in ASM

Code: Select all

Define x.i

! abc = 123
! MOV [v_x], abc

Debug x
It is named as PS2 because it is used in _Procedure2. In case of another procedure, the number in the name is increasing.
The value itself depends on the number and size of arguments and protected variables in the procedure, which are stored in the stack.

Re: PS2=64 - What instruction is this?

Posted: Wed Nov 17, 2021 8:06 pm
by ricardo_sdl
Thank you STARGÅTE! I searched a little more and found this:
https://flatassembler.net/docs.php?article=manual#2.2.1

So the value of PS2 is simply stored with the assembled instructions, right?

Re: PS2=64 - What instruction is this?

Posted: Wed Nov 17, 2021 8:34 pm
by STARGÅTE
ricardo_sdl wrote: Wed Nov 17, 2021 8:06 pm So the value of PS2 is simply stored with the assembled instructions, right?
Yes, like a #constant in Pure Basic

Re: PS2=64 - What instruction is this?

Posted: Thu Nov 18, 2021 7:30 am
by juergenkulow
@ricardo_sdl
What debbuger are you using to see what is happening on the stack and in the registers?

Re: PS2=64 - What instruction is this?

Posted: Thu Nov 18, 2021 12:38 pm
by ricardo_sdl
Hi juergenkulow!
In this case I wasn't using the debugger. I looked at the asm output of the compiler with the /commented flag. A tool that used once was https://x64dbg.com/#start, you can look at the stack, memory and registers, really useful to learn assembly.