私はアセンブリ言語のクラスに通っていますが、教える方法はサンプル コードを渡して自分で学ぶだけですが、まだ苦労しています。I/O の理解を深めるためにこのサンプル プログラムを書きたかったのですが、何度もクラッシュしてしまいます。
ここに私の.asmがあります
extern printf
extern scanf
segment .data
prompt db "Enter a number: ",0
stringdata db "%s",0
inputdata db "%Lf",0
segment .bss
x: resq 1
segment .text
global ints
ints:
;=========== Back up the base pointer =============================================================
push rbp ;Save a copy of the stack base pointer
;=========== Save registers ======================================================================
push rdi
push rsi
;===============prompt user for a number====
mov rax, 0
mov rdi, stringdata
mov rsi, prompt
call printf
finit
;==================grab input from keyboard
mov rax,0
mov rdi, inputdata
push qword 0
push qword 0
mov rsi, rsp
call scanf
fld tword [rsp] ;store into st0
fld st0 ;place another copy into the stack
fmul st0 ;multiply st0 and st1
fstp qword [x] ;store st0 into x
mov rax, 0
mov rdi, inputdata
push qword 0
push qword 0
mov rsi, x
call printf
;============ Restore all registers =================================================================================================
pop rsi ;Restore the original value to rsi
pop rdi ;Restore the original value to rdi
pop rbp ;Restore the base pointer
mov qword rax, 0 ;Return 0 to the caller. 0 indicates successful termination.
ret ;ret pops the stack taking away 8 bytes; all addresses contain 8 bytes
Heres Cファイルですが、それほど多くはありません..
#include <stdio.h>
#include <stdint.h>
extern unsigned long int ints();
int main()
{
unsigned long int result = -999;
result = ints();
return result;
}