Author Topic: PUSH & POP question  (Read 642 times)

sinsi

  • Member
  • *****
  • Posts: 1062
Re: PUSH & POP question
« Reply #15 on: May 01, 2018, 07:20:32 PM »
LEA uses a 32-bit signed offset from RIP, OFFSET uses the 64-bit address. Benefits of LEA are smaller code (see jj's example) and no relocation needed (helps with position-independent code).
I can walk on water but stagger on beer.

LordAdef

  • Member
  • ****
  • Posts: 588
Re: PUSH & POP question
« Reply #16 on: May 02, 2018, 07:56:09 AM »
Every time I see you guys talking about masm 64 I get the shivers... It will take some time before I dig into 64 I guess

Why the hell did they make x64 with so many caveats?


daydreamer

  • Member
  • ***
  • Posts: 492
Re: PUSH & POP question
« Reply #17 on: May 03, 2018, 05:40:05 AM »
Its unfortunate that ML64 has gone the way of NASM in not using OFFSET which is a specific technical term for a distance from a location which is used to locate either data or code within an assembler binary. In 32 bit MASM (ML.EXE) it is the preferred technique for addresses. LEA will do it but you are determining the address dynamically where OFFSET puts the value in at assembly time as an immediate.
Isnt there a way to make OFFSET macro in ml64 ?
Quote from Flashdance
Nick  :  When you give up your dream, you die.
*wears a flameproof asbestos suit*

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5634
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: PUSH & POP question
« Reply #18 on: May 03, 2018, 02:13:09 PM »
Answer is simple.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm32\include64\masm64rt.inc

    .data
      testme dq 12345678

    .code

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

entry_point proc

    LOCAL var   :QWORD

    ; mov var, OFFSET testme  ; offset.asm(16) : error A2084:constant value too large

    lea rax, testme
    mov var, rax

    conout "Howdy, your new console template here.",lf,lf
    waitkey
    .exit

entry_point endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5634
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: PUSH & POP question
« Reply #19 on: May 03, 2018, 02:17:02 PM »
Alex,

I would not worry about Win64, if you saw the miseries of shifting from 16 bit segment:offset to Win32 flat memory model, this is no big deal to go to 64 bit. Its different but it does make sense.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5634
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: PUSH & POP question
« Reply #20 on: May 03, 2018, 02:28:27 PM »
In 32 bit, OFFSET works fine.

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    include \masm32\include\masm32rt.inc
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

comment * -----------------------------------------------------
                        Build this  template with
                       "CONSOLE ASSEMBLE AND LINK"
        ----------------------------------------------------- *

    .data
      item dd 12345678

    .code

    start:
   
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    call main
    inkey
    exit

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

 main proc

    mov eax, OFFSET item

    print str$([eax]),13,10

    ret

 main endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end start
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

jj2007

  • Member
  • *****
  • Posts: 8599
  • Assembler is fun ;-)
    • MasmBasic
Re: PUSH & POP question
« Reply #21 on: May 03, 2018, 05:56:51 PM »
In 32 bit, OFFSET works fine.
...
    mov eax, OFFSET item

That works in 64-bit, too. Rarely useful but it works, even with ML64.

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5634
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: PUSH & POP question
« Reply #22 on: May 03, 2018, 06:43:10 PM »
The distinction is simple, ML64 treats OFFSET like a memory operand so while you can load it into a register you cannot load it into another memory operand. An OFFSET is an immediate, not a memory operand. LEA does the job but its 2 steps, not an immediate into either a memory operand or a register.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin: