1

我参加了一个汇编语言课程,但教学方法只是将示例代码交给我们自学,但我仍然很挣扎。我想编写这个示例程序只是为了更好地了解 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

这是C文件,虽然不多..

#include <stdio.h>
#include <stdint.h>


extern unsigned long int ints();

int main()
{
        unsigned long int result = -999;
        result = ints();

        return result;

}
4

0 回答 0