Thread: How would these variables get pushed on to the stack?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    Quote Originally Posted by I C everything View Post
    its two different animals compile for x86 or compile for x64 using very different calling conventions
    so x64 only uses stack in exceptions
    x86 calling conventions - Wikipedia
    Yep... Try to compile the same code for i386 (or x86, as you called) and you'll get:
    Code:
      section .text
    
    _multiplyByTwo:
      fld QWORD [esp+4]
      fadd  st, st(0)
      ret
    
      section .rdata
    LC2:
      db `double your salary is %.3f\n`, 0
    
      section .text
    
      extern printf
    
      global _main
    _main:
      push  ebp
      mov   ebp, esp
      and   esp, -16
      sub   esp, 16
      call  ___main
      mov   DWORD [esp+4], -1030792151
      mov   DWORD [esp+8], 1087904981
      mov   DWORD [esp], .LC2
      call  _printf
      xor   eax, eax
      leave
      ret
    _multiplyByTwo isn't called by _main and the direct doubled value is pushed before printf. No 'local vars' are pushed!

    Let's try with ARM AArch32, shall we?
    Code:
      .cpu cortex-a53
      .arm
      .fpu vfp
    
      .section .text
    
      .extern printf
    
    multiplyByTwo:
      vadd.f64  d0, d0, d0
      bx        lr
    
      .global  main
    main:
      push  {r4, lr}
      movw  r0, #:lower16:.LC1
      movt  r0, #:upper16:.LC1
      movw  r2, #23593
      movt  r2, 49807
      movw  r3, #7381
      movt  r3, 16600
      bl    printf  
      mov   r0, #0  
      pop   {r4, pc}
    
      .section  .rodata 
    .LC1:
      .ascii  "double your salary is %.3f\012\000"
    Still... no multiplyByTwo call and still no 'local var' pushing...
    Last edited by flp1969; 12-03-2020 at 06:31 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. address of stack variables
    By telmo_d in forum C Programming
    Replies: 4
    Last Post: 04-06-2016, 03:48 PM
  2. local variables and stack
    By telmo_d in forum C Programming
    Replies: 1
    Last Post: 06-04-2015, 02:14 PM
  3. local stack variables
    By Amyaayaa in forum C++ Programming
    Replies: 25
    Last Post: 10-07-2008, 01:13 PM
  4. how to identify which button is pushed
    By gaurav07 in forum Windows Programming
    Replies: 1
    Last Post: 06-23-2005, 10:44 AM
  5. Doing stuff when certain Key combo's pushed
    By HisWord in forum Windows Programming
    Replies: 13
    Last Post: 09-30-2001, 07:39 AM

Tags for this Thread