Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux nasm x86初学者使用C调用-printf scanf_Linux_X86_Printf_Nasm_Scanf - Fatal编程技术网

Linux nasm x86初学者使用C调用-printf scanf

Linux nasm x86初学者使用C调用-printf scanf,linux,x86,printf,nasm,scanf,Linux,X86,Printf,Nasm,Scanf,此代码从用户处获取一个名称和一个数字,并向其中添加一个数字(5150)。我不明白为什么我会出现分割错误。我在提示输入数字后得到错误。代码如下: SECTION .data askName: db "Enter your name: ",0 askNum: db "Enter an unsigned number no more than four digits: ",0 fResultP1: db "Thank you ",0 fResultP

此代码从用户处获取一个名称和一个数字,并向其中添加一个数字(5150)。我不明白为什么我会出现分割错误。我在提示输入数字后得到错误。代码如下:

SECTION .data

    askName:   db "Enter your name: ",0
    askNum:    db "Enter an unsigned number no more than four digits: ",0
    fResultP1:  db "Thank you ",0   
    fResultP2:  db ".",0
    fResultP3:  db "After adding 5150 to your number, the answer is now: ", 0
    formats:    db "%s", 0
    formatd:    db "%d", 0
    formatdlf:  db "%d",10, 0       ; with line feed

SECTION .bss

    name:   resb    20
    number: resb   4
    ;answer: resb    5       

SECTION .text

    extern printf
    extern scanf

            global main                    

main:
    ;;;;;;; set up stack frame
            push EBP        ; base pointer
            mov EBP, ESP    ; put stack pntr in EBP
            pushad          ; pushes all registers on stack

    ;;;;;;; ask user name 
            push askName    ; push question 
            call printf     ; print question
            add  ESP, 4     ; clean the stack (pop stack)

    ;;;;;;; get name input
            push name
            push formats    ; %s (string)               
            call scanf
            add ESP, 8      ; clean the stack (pop stack)

    ;;;;;;; ask user number
            push askNum     ; push question
            call printf     
            add ESP, 4      ; pop stack

    ;;;;;;; get number input
            push number
            push formatd    ; %d (decimal)
            call scanf
            add ESP, 8      ; pop stack 2X4= 8

    ;;;;;;; print closing sent
            push fResultP1  ; "Thank you "
            call printf
            add ESP, 4      ; pop stack

            push dword [name]
            call printf
            add ESP, 4      ; pop

            push fResultP2  ; "."
            call printf
            add ESP, 4

            push fResultP3  ; "After adding..."
            call printf
            add ESP, 4      ; pop

            mov EAX, dword [number]
            add EAX, 5150   
            push EAX        ; push on the added number
            push formatdlf  ; has line feed
            call printf
            add ESP, 8      ; pop

    ;;;;;;; destroy stack frame ;;;;;;;;;;;;;;;;;
           popad          
          mov ESP, EBP
           pop EBP

           ret 

push-dword[name]
更改为
push-dword-name
(或
push-name
)。不需要方括号
name
是名称字符串的地址。

打印名称时,
push name
不应该是
push name
?我在OP的代码中没有看到任何
mov EAX,dword[name]
指令。谢谢你的帮助。也必须改变这个数字:resd 1