链接2个程序集文件似乎会导致文本双重打印?

问题描述

我编写了一个简单的程序集外部过程,如果输入ESI->buffer address,则在EDI->number to printEDI=0 print till null character中进行输入,并将其打印到控制台。如果将其源代码复制到主程序中,它将非常完美。但是,如果它在单独的文件中并使用

链接在一起,则会导致重复打印
ld main.o write.o -o main

并组装为

nasm -f elf64 -o write.o write.asm

写过程:

section .text
global write
write:       ; Save registers state 
    push rdx    
    push rbx
    push rcx
    
    cmp edi,0                ; test if edi = 0
    je loop_setup             ; if true calculate string length
    mov edx,edi              ; If edi != 0 store number of bytes in edx
    
sys_write: 
       mov eax,4             ; specify sys_write
       mov ebx,1             ; specify file descriptor 1
       mov ecx,esi           ; Pass Buffer address
                              ; edx already contain number of bytes to write
       int 80h                ; make sys_call   
        ; Restore back all registers modifed except eax(contain return code)
       pop rcx
       pop rbx
       pop rdx   
       ret              ; Return back to the caller
          
loop_setup: mov edx,0              ; set write counter to zero 
loop_part:   
        mov al,byte[esi+edx]       ; store byte into al adjusted by counter
        inc edx                     ; increment counter by one byte 
        cmp byte al,0              ; check if character is "/0"
        jne loop_part               ; loop back until find null character
        jmp sys_write               ; go to sys_write if found

主程序为

section .data
    name: db "test",0
section .text
global _start
_start:
    mov esi,name
    mov edi,0
    call write

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)