Printf Assembly Language Stack pointer nasm intel -



Printf Assembly Language Stack pointer nasm intel -

setup: nasm intel 64bit ubuntu getting segmentation error when include printf line. without including compiles , runs fine. trying print 1 in code.

does calling printf print whatever @ stack pointer? dd2 @ stack pointer when printf called here?

i popped lastly 2 items have stack homecoming initial position.

all help appreciated, have great evening!

section .data dd: db 1 dd2: db "%d" extern printf section .text global main main: force dd force dd2 phone call printf pop rax ; pop rbx ; ret

the calling conventions 64 bit different used 32bit.

http://en.wikipedia.org/wiki/x86_calling_conventions

scroll downwards x86-64 tell first 6 parameters passed in registers: 1st param in rdi, 2nd param in rsi, 3rd param in rdx, 4th rcx, 5th r8, 6th r9, more , passed on stack; floating point params passed in xmm0–7

so, printf phone call should be:

mov rsi, dd mov rdi, dd2 mov rax, 0 phone call printf

since don't pass in xmm regs, set rax 0 (without it may crash)

i should note stack must 16 byte aligned, when programme starts , link c library. but, since phone call pushes 8 byte value on stack (the homecoming address) stack not aligned. @ start of functions (in case main), sub rsp, 8 , take care of it.

assembly nasm

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -