nasm 어셈블리 파일에서 C 입출력 함수를 호출하는 방법이 있습니까?linux nasm 어셈블리에서 C IO 함수 호출
2
A
답변
4
다음 코드는 Sample nasm programs에서 그대로 복사 :
printf1.asm 기본 호출의 printf :
The nasm source code is printf1.asm
The result of the assembly is printf1.lst
The equivalent "C" program is printf1.c
Running the program produces output printf1.out
This program demonstrates basic use of "C" library function printf.
The equivalent "C" code is shown as comments in the assembly language.
; printf1.asm print an integer from storage and from a register
; Assemble: nasm -f elf -l printf.lst printf1.asm
; Link: gcc -o printf1 printf1.o
; Run: printf1
; Output: a=5, eax=7
; Equivalent C code
; /* printf1.c print an int and an expression */
; #include <stdio.h>
; int main()
; {
; int a=5;
; printf("a=%d, eax=%d\n", a, a+2);
; return 0;
; }
; Declare some external functions
;
extern printf ; the C function, to be called
SECTION .data ; Data section, initialized variables
a: dd 5 ; int a=5;
fmt: db "a=%d, eax=%d", 10, 0 ; The printf format, "\n",'0'
SECTION .text ; Code section.
global main ; the standard gcc entry point
main: ; the program label for the entry point
push ebp ; set up stack frame
mov ebp,esp
mov eax, [a] ; put a from store into register
add eax, 2 ; a+2
push eax ; value of a+2
push dword [a] ; value of variable a
push dword fmt ; address of ctrl string
call printf ; Call C function
add esp, 12 ; pop stack 3 push times 4 bytes
mov esp, ebp ; takedown stack frame
pop ebp ; same as "leave" op
mov eax,0 ; normal, no error, return value
ret ; return
관련 문제
- 1. nasm x86-64에서 c 함수 호출
- 2. linux nasm assembly dwtoa
- 3. gcc 인라인 어셈블리에서 함수 호출
- 4. Linux 커널의 entry_32.S에서 C 함수 호출
- 5. Hello world windows 어셈블리에서 nasm 사용
- 6. 곱셈을하지 않고 NASM 어셈블리에서 숫자의 제곱
- 7. YASM 또는 NASM 어셈블리에서 백 스페이스 수행
- 8. Io 언어 포함 : C에서 Io 메소드 호출
- 9. NASM 어셈블리에서 BIOS int 13h를 사용하여 디스크에서 커널을로드하는 방법은 무엇입니까?
- 10. 호출 사용자 정의 C 함수
- 11. Ada IO Multiplexing on Linux
- 12. C/C++ 함수 호출
- 13. readint NASM 리눅스 어셈블리
- 14. DTrace 스크립트에서 C 함수 호출
- 15. NASM 가스 : 호출 equ'd 문자
- 16. nasm 64 비트 Linux 컴퓨터에서 인쇄
- 17. linux nasm 커맨드 라인 args as integers
- 18. linux nasm assembly 무엇을합니까? (register) :(register) mean?
- 19. linux nasm assembly 터미널의 클리어 화면
- 20. linux nasm AX에서 최대 값으로 AL을 이동
- 21. 어셈블리에서 함수 가상 호출 주소를 어떻게 찾을 수 있습니까?
- 22. linux c/C++ preg_replace 유형의 함수?
- 23. 하스켈 함수 정의 IO
- 24. JNA에서 C 함수 호출
- 25. C++ 호출 DLL 함수
- 26. C++ 함수 포인터 호출
- 27. C# 함수 호출?
- 28. C 함수 호출
- 29. C++ 함수 호출 식별자
- 30. C - 함수 호출
http://www.csee.umbc.edu/portal/help/nasm/ sample.shtml # printf1 ("go print printf to nasm") – NPE