Learning x86 with NASM - Calling Standard C Functions

preview_player
Показать описание
In this video, you will learn how to call standard C functions from x86. This video demonstrates calling printf and exit.

#x86 #nasm
Рекомендации по теме
Комментарии
Автор

Will you continue this course??

This course was very helpful.

smallSphere
Автор

Anyone got the warning about using executable stack. "/usr/bin/ld: warning: call1.o: missing .note.GNU-stack section implies executable stack". Why does the code use executable stack ?

mrfli
Автор

I'm having troubles compiling in gcc, can you help?
I'm actually using a ec2 with 1vcpu x86 intel and i'm getting errors as the gcc try to call some files(I guess), there's no error code for me to send, but there's a line "collect2: error: ld returned 1 exit status"

szcjufo
Автор

Sheesh that was a pain in the neck. Anyone following along in amd64, note that the calling convention is completely different, and stack alignment gets important. Working code:

extern printf
extern exit
section .data
gura DB "gura", 0
ame DB "ame loves %s", 10, 0

section .text
global main

main:
MOV rsi, gura
MOV rdi, ame
AND rsp, -16 ; align the stack
CALL printf

MOV rdi, 5
; AND rsp, -16 ; not needed this time because we exit immediately after
CALL exit

The register order for amd64 is RDI, RSI, RDX, RCX, R8, R9, then stack. Irrelevant here, but the return value "comes back in EAX/RAX" whatever that means.

Asdayasman
Автор

Hi, I wrote a code to calculate faculty of a number and print out. But I am getting segmentation fault (core dumped) error when I try to run the code. Can somebody help me? Why I am getting this error?
extern printf

section .data
n dq 10
ergebnis dq 0
output_str db "Fakultat von n = %u", 10, "ergebnis: %u", 10, 0


section .text
global main


main:
mov rcx, qword[n]
mov rax, 1
cmp rcx, 0
je ende

l1:
mul rcx
loop l1

ende:
mov qword[ergebnis], rax
push qword output_str
push qword[n]
push qword[ergebnis]
call printf
mov rax, 1
mov rbx, 1
INT 80h

mehmeteminfincan