十进制到二进制转换 nasm - 如何在 NASM 程序集中划分和存储字符串中的余数?

问题描述 投票:0回答:0

我是 nasm assembly 的新手,所以如果这是一个真正的菜鸟问题,我深表歉意。这是我到目前为止所得到的。

%include    'functions.asm'

section .data
    ip_prompt   db  "Enter a decimal number to be converted to binary: ", 0h
    binary_res  db  32 dup('0')

section .bss
    dec_input resb 32    

section .text
    global _start
    
_start:
    mov     eax, ip_prompt
    call    str_print

    mov     eax, SYS_READ
    mov     ebx, STDIN
    mov     ecx, dec_input
    mov     edx, 32
    int     80h

    mov     eax, dec_input
    call    str_print

    mov ecx, 0
    mov eax, dec_input
    mov ebx, 2
    xor edx, edx

convert_to_bin:
    div     ebx
    mov     [binary_res + ecx], edx
    inc     ecx
    cmp     eax, 0
    jne     convert_to_bin

    mov     eax, binary_res
    call    str_print_endl

    call    quit

我正在尝试通过将dec_input分成2直到达到0来实现连续除法的方法。但是运行程序后,它会输出Segmentation fault(core dumped)。

assembly nasm
© www.soinside.com 2019 - 2024. All rights reserved.