6

まず、これは宿題です。

レジスタ bx に 5 桁の数字を読み込もうとしています。数値は 65535 (16 ビット) 以下であると想定されます。以下は、私がそうしようとしている方法です。

ただし、番号を印刷しようとすると、入力された最後の数字しか印刷されません。これにより、別の数値を bx に追加すると、前の数値が上書きされると推測されますが、問題はわかりません。何か助けていただければ幸いです。私が見落としている小さなものであることはほぼ確実です:-/

mov cx,0x05 ; loop 5 times
    mov bx,0    ; clear the register we are going to store our result in
    mov dx,10   ; set our divisor to 10

read:
    mov ah,0x01     ; read a character function
    int 0x21        ; store the character in al
    sub al,0x30     ; convert ascii number to its decimal equivalent
    and ax,0x000F   ; set higher bits of ax to 0, so we are left with the decimal
    push ax         ; store the number on the stack, this is the single digit that was typed
    ; at this point we have read the char, converted it to decimal, and pushed it onto the stack
    mov ax,bx       ; move our total into ax
    mul dx          ; multiply our total by 10, to shift it right 1
    pop bx          ; pop our single digit into bx
    add bx,ax       ; add our total to bx
    loop read       ; read another char
4

1 に答える 1

4

MUL オペコードを使用すると、次の 3 つの異なる結果が得られます。

  • 8 ビット - 結果は ax に格納されます
  • 16 ビット - 結果は dx:ax に保存されます
  • 32 ビット - 結果は edx:eax に保存されます

したがって、乗算を実行すると、命令は dx をゼロで上書きします。これは、以降の mul オペコードの使用ごとにゼロが乗算されることを意味します。

于 2011-04-03T23:23:48.893 に答える