0

だから私は画面に9より大きい数字を書くための小さなプログラムを書きました。しかし、値をスタックにプッシュするとすぐに、スタックが空になるまで物を印刷できません。これを回避する方法はありますか?

コードは次のとおりです。

print_int:          ; Breaks number in ax register to print it
    mov cx, 10
    mov bx, 0
    break_num_to_pics:
        cmp ax, 0
        je print_all_pics
        div cx
        push dx
        inc bx
        jmp break_num_to_pics
    print_all_pics:
        cmp bx, 0       ; tests if bx is already null
        je f_end
        pop ax
        add ax, 30h
        call print_char
        dec bx
        jmp print_all_pics

print_char:             ; Function to print single character to      screen
        mov ah, 0eh     ; Prepare registers to print the character
        int 10h         ; Call BIOS interrupt
        ret

f_end:              ; Return back upon function completion
    ret
4

1 に答える 1

0

コードには2つのバグがあります。

dx1つ目は、前にゼロにしないことですdiv cx

print_int:          ; Breaks number in ax register to print it
    mov cx, 10
    mov bx, 0
    break_num_to_pics:
    cmp ax, 0
    je print_all_pics

    ; here you need to zero dx, eg. xor dx,dx

    xor dx,dx       ; add this line to your code.

    div cx          ; dx:ax/cx, quotient in ax, remainder in dx.
    push dx         ; push remainder into stack.
    inc bx          ; increment counter.
    jmp break_num_to_pics

dx問題は、除算の前にゼロにしないことです。初めてdiv cxdxは初期化されていません。次にdiv cx到達する時間はでremainder:quotient除算されますが10、それはあまり意味がありません。

もう1つはここにあります:

print_char:         ; Function to print single character to      screen
    mov ah, 0eh     ; Prepare registers to print the character
    int 10h         ; Call BIOS interrupt
    ret

の入力レジスタであっても、 blとに意味のある値を設定しないでください(ラルフブラウンの割り込みリストを参照) 。bhmov ah,0ehint 10h

INT 10 - VIDEO - TELETYPE OUTPUT
     AH = 0Eh
     AL = character to write
     BH = page number
     BL = foreground color (graphics modes only)

カウンターとして使用する場合はbx、内部または外部に保管する必要がありますprint_char。たとえば、bx内部に保存しprint_charます。

print_char:         ; Function to print single character to      screen
    mov ah, 0eh     ; Prepare registers to print the character

    push bx         ; store bx into stack
    xor bh,bh       ; page number <- check this, if I remember correctly 0
                    ; is the default page.
    mov bl,0fh      ; foreground color (graphics modes only)

    int 10h         ; Call BIOS interrupt

    pop bx          ; pop bx from stack
    ret
于 2013-03-11T21:30:03.227 に答える