nasm 32字除法总是给1作为答案

时间:2016-10-18 17:54:39

标签: linux assembly x86 nasm

我一直试图划分单词大小的变量,结果商总是1,余数总是除数除数。什么可能出错?提前谢谢。

section .data

section .bss
    num1a resw 1
    num1b resw 1
    num2a resw 1
    num2b resw 1

section .text
    global _start
_start:
    ;get inputs

    mov eax, 3
    mov ebx, 0
    mov ecx, num1a
    mov edx, 1
    int 80h

    mov eax, 3
    mov ebx, 0
    mov ecx, num1b
    mov edx, 2
    int 80h

    mov eax, 3
    mov ebx, 0
    mov ecx, num2a
    mov edx, 1
    int 80h

    mov eax, 3
    mov ebx, 0
    mov ecx, num2b
    mov edx, 2
    int 80h

    ;convert
    sub word[num1a], 30h
    sub word[num1b], 30h
    sub word[num2a], 30h
    sub word[num2b], 30h

    mov ax, 0
    mov bx, 0
    mov ax, [num1a]
    mov bx, 10
    mul bx

    add ax, [num1b]
    mov word[num1a], ax

    mov ax, 0
    mov bx, 0
    mov ax, [num2a]
    mov bx, 10
    mul bx

    add ax, [num2b]
    mov word[num2a], ax
    ;divide
    mov ax, 0
    mov dx, 0
    mov ax, [num1a]
    div word[num2a]

    mov word[num1a], ax
    mov word[num2a], dx

    mov ax, 0
    mov dx, 0
    mov ax, [num1a]
    mov bx, 10
    div bx
    mov word[num1a], ax
    mov word[num2a], dx

    ;convert
    add word[num1a], 30h
    add word[num2a], 30h
    ;print
    mov eax, 4
    mov ebx, 1
    mov ecx, num1a
    mov edx, 1
    int 80h

    mov eax, 4
    mov ebx, 1
    mov ecx, num2a
    mov edx, 1
    int 80h

    exit:
    mov eax, 1
    mov ebx, 0
    int 80h

0 个答案:

没有答案