0

我是学习汇编的初学者。我在 Windows 7 64bit 下使用 DOSBOX。我想知道如何在汇编中显示寄存器的值。例如,我编写了以下代码:

mov ax,20 ; ax will be 20
mov cx,10 ; cx will be 10
sub ax,cx ; ax will be 10 (ax-cx,20-10)

如何显示 ax 寄存器的内容(应该是 10)?

4

1 回答 1

2

您尚未指定目标操作系统或汇编程序,但如果我们假设 DOS 和 NASM(应该不难适应 TASM/MASM):

org 100h
section .text

mov ax,123

mov byte [buffer+9],'$'     ; Insert string terminator
lea si,[buffer+9]

; create a string representation of the value in AX
mov bx,10
itoa:
    xor dx,dx       ; clear dx, since we'll divide dx:ax by bx
    div bx          ; ax = dx:ax / 10, dx = dx:ax % 10 
    add dl,'0'      ; add '0' to the remainder to get a character in the range '0'..'9'
    dec si
    mov [si],dl     ; store it in the buffer
    cmp ax,0
    jnz itoa

mov ah,9            ; print string
mov dx,si
int 21h

mov ax,4Ch          ; exit to DOS
int 21h

buffer: resb 10
于 2013-06-14T19:42:18.823 回答