Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.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
Assembly 输出中的NASM混合字符串_Assembly_64 Bit_Nasm - Fatal编程技术网

Assembly 输出中的NASM混合字符串

Assembly 输出中的NASM混合字符串,assembly,64-bit,nasm,Assembly,64 Bit,Nasm,我试图从我在这里获取的教程中生成一个简单的“使用提示创建文件”代码。但每次我输入东西时,终端中的输出字符串都会混合并剪切在一起。将要创建的文件也是混合的 代码如下: section .data Msg1: db 'Masukkan nama Anda ',0xa Msg1ln equ $-Msg1 Name: db ' ', 0xa ; space characters msg_done: db 'File telah dibuat ', 0xa ;msg

我试图从我在这里获取的教程中生成一个简单的“使用提示创建文件”代码。但每次我输入东西时,终端中的输出字符串都会混合并剪切在一起。将要创建的文件也是混合的

代码如下:

    section .data
Msg1: db 'Masukkan nama Anda ',0xa
Msg1ln equ $-Msg1

Name: db ' ', 0xa               ; space characters

msg_done: db 'File telah dibuat ', 0xa
;msg_doneln equ $-msg_done


section .text
   global _start         

_start:                  

   ; Output  'Masukkan nama Anda '
mov eax, 4              ; write…
mov ebx, 1              ; to the standard output (screen/console)…
mov ecx, Msg1           ; the information at memory address prompt
mov edx, Msg1ln         ; 19 bytes (characters) of that information
int 0x80                ; invoke an interrupt

; Accept input and store the user’s name
mov eax, 3              ; read…
mov ebx, 1              ; from the standard input (keyboard/console)…
mov ecx, Name               ; storing at memory location name…
mov edx, 23                 ; 23 bytes (characters) is ok for my name
int 0x80

   ;create the file
   mov  eax, 8
   mov  ebx, Name
   mov  ecx, 0777        ;read, write and execute by all
   int  0x80             ;call kernel

   mov [fd_out], eax

    ;write the message indicating end of file write
   mov eax, 4
   mov ebx, 1
   mov ecx, msg_done
   mov edx, 18
   int  0x80

   mov  [fd_in], eax


   mov  eax,1             ;system call number (sys_exit)
   int  0x80              ;call kernel

section .bss
fd_out resb 1
fd_in  resb 1
如果我输入“Jack”,终端是这样的

应该怎样

Masukkan nama Anda
Jack 
File telah dibuat
Jack
文件名是

Jack e telah dibuat
应该怎样

Masukkan nama Anda
Jack 
File telah dibuat
Jack
对不起,我是大会的新成员。 现在我仍在尝试编辑eax、ebx的内容。如果我知道一些事情,我会发帖的。 非常感谢

更新 看起来我在64位汇编中使用了32位代码。所以我修改了大部分语法(但问题不是这个)。最终的代码成功了(感谢底部的那个家伙)


考虑到你的内存布局是这样的

..., ' ', 0xA, 'F', 'i', 'l', 'e', ' ', 't', 'e', ... 
其中
Name
指向第一个
'
msg_done
指向
'F'

一旦您在
Name
指定的地址存储了读取的23个字节,那么
msg_done
所在的位置也会被该数据覆盖,因为
Name
“只有”2个字节

为了纠正您的问题,您可以使用此选项,假设您的最大长度将保持在23个字符-它基本上表示“在该位置定义23个初始化为
,也可以通过
Name
访问该位置。”


您仅在
Name
处为单个字符分配了足够的空间。你需要更多。这只解决了剩下的问题!但是,我不明白你的最后一句话。它仍然将msg_done写入输出文件(文件名合并),感谢您指出,答案的这一部分对于您的代码是不正确的。我把它拿走了。在
名称
后面添加的空终止符永远不会被覆盖,解决了这个问题。
Name: times 23 db ' '