Есть ли способ вызвать функции ввода/вывода C из файла сборки nasm?
2
meltuhamy
15 Дек 2011 в 21:08
csee.umbc.edu/portal/help/nasm/sample. shtml#printf1 (лучший поисковый запрос Google по запросу «вызов printf из nasm»)
– NPE
15 Дек 2011 в 21:10
1 ответ
Следующий код дословно скопирован из примеров программ nasm:
Основной вызов 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
5
NPE
15 Дек 2011 в 21:19
После долгих поисков в гугле вот ответ для 64-битной версии: forum.nasm.us/index. php?topic=342.0 в основном не нажимает параметры.
– meltuhamy
15 Дек 2011 в 22:33
Похожие вопросы
Новые вопросы
c
C - это язык программирования общего назначения, используемый для системного программирования (ОС и встраиваемых), библиотек, игр и кроссплатформенности. Этот тег следует использовать с общими вопросами, касающимися языка C, как это определено в стандарте ISO 9899 (последняя версия 9899: 2018, если не указано иное, а также для запросов, специфичных для версии, с c89, c99, c11 и т. Д.). C отличается от C ++ и не должен сочетаться с тэгом C ++ без разумной причины.