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 如何显示存储在DX:AX中的32位DIV结果_Assembly_X86_Emu8086 - Fatal编程技术网

Assembly 如何显示存储在DX:AX中的32位DIV结果

Assembly 如何显示存储在DX:AX中的32位DIV结果,assembly,x86,emu8086,Assembly,X86,Emu8086,我写这段代码是为了在计算后显示当前值。但是程序给出了错误的输出,当它应该给出十进制10的结果时,它给出了13107的结果,我找不到原因。在此之前,我所做的基本上是从用户那里获取输入,并将这些值存储在si寄存器中 islem: MOV AX,[SI+14] MOV BX,[SI+10] MOV CX,[SI+2] SUB AX,BX SUB AX,CX MOV BX,[SI+8] MOV [SI+16],AX MOV DX,00H M

我写这段代码是为了在计算后显示当前值。但是程序给出了错误的输出,当它应该给出十进制10的结果时,它给出了13107的结果,我找不到原因。在此之前,我所做的基本上是从用户那里获取输入,并将这些值存储在si寄存器中

islem: 

  MOV AX,[SI+14]
  MOV BX,[SI+10]
  MOV CX,[SI+2]
  
  SUB AX,BX
  SUB AX,CX
  
  MOV BX,[SI+8]
  
  MOV [SI+16],AX
  
  MOV DX,00H
  MOV AX,[SI+16]
  DIV BX
  
  
  
  MOV [SI+18],OFFSET IE
  
  MOV [SI+18],AX
  MOV [SI+20],DX
  
  CALL NEWLINE
  
  mov dx, offset Ie_msg
  mov ah,9
  int 21h
  
  MOV AX,[SI+18]
  MOV DX,[SI+20]
  

  
    mov     bx,10          ;CONST
    push    bx             ;Sentinel
a: mov     cx,ax          ;Temporarily store LowDividend in CX
    mov     ax,dx          ;First divide the HighDividend
    xor     dx,dx          ;Setup for division DX:AX / BX
    div     bx             ; -> AX is HighQuotient, Remainder is re-used
    xchg    ax,cx          ;Temporarily move it to CX restoring LowDividend
    div     bx             ; -> AX is LowQuotient, Remainder DX=[0,9]
    push    dx             ;(1) Save remainder for now
    mov     dx,cx          ;Build true 32-bit quotient in DX:AX
    or      cx,ax          ;Is the true 32-bit quotient zero?
    jnz     a             ;No, use as next dividend
    pop     dx             ;(1a) First pop (Is digit for sure)
b: add     dl,"0"         ;Turn into character [0,9] -> ["0","9"]
    mov     ah,02h         ;DOS.DisplayCharacter
    int     21h            ; -> AL
    pop     dx             ;(1b) All remaining pops
    cmp     dx,bx          ;Was it the sentinel?
    jb      b             ;Not yet
  



ret
您的计算结果来自除法(
div bx
商仅保存在
AX
寄存器中
DX
寄存器包含除法的余数

只需使用
mov AX,[si+18]
加载
AX
,然后使用
xor DX,DX


此后,您可以运行我的转换代码…

他想显示一个32位数字。@prl不,他不想。计算结果为16位。他只问了关于
DX:AX
的问题,因为我之前把他和我的一个显示32位数字的答案联系了起来。先生,我按照你的建议做了,但没有得到正确的答案,即10,而是得到了6,这是只存储在商中的结果。但是我需要显示存储在dx:ax中的正确答案02:06如何更改代码以给出正确的输出?@BengisuAdsız如果
dx=2
ax=6
,正确答案如何为10?这将产生
2*65536+6
,即131078。您需要告诉我您在当前发布的程序顶部使用的输入数字。对不起,先生,我注意到我在开始时出现了一个计算错误,我更改了它,现在它给出了正确的结果,即10。谢谢你的时间和帮助。我是一个她顺便说一句:)
MOV AX,[SI+18]
MOV DX,[SI+20]