Function 如何在汇编8086中打印数字?

Function 如何在汇编8086中打印数字?,function,assembly,x86,x86-16,Function,Assembly,X86,X86 16,我正在尝试编写一个函数,该函数接收一个数字(我之前推过),并将其打印出来。我怎么做 到目前为止,我所拥有的: org 100h push 10 call print_num print_num: push bp mov bp, sp mov ax, [bp+2*2] mov bx, cs mov es, bx mov dx, string mov di, dx stosw mov ah, 09h int 21h pop bp ret string: 您在string地址中放置的是一个数

我正在尝试编写一个函数,该函数接收一个数字(我之前推过),并将其打印出来。我怎么做

到目前为止,我所拥有的:

org 100h

push 10
call print_num

print_num:

push bp
mov bp, sp
mov ax, [bp+2*2]
mov bx, cs
mov es, bx
mov dx, string
mov di, dx
stosw
mov ah, 09h
int 21h
pop bp
ret

string:

您在
string
地址中放置的是一个数值,而不是该值的字符串表示形式

值12和字符串“12”是两个独立的东西。作为16位十六进制值,12将是0x000C,而“12”将是0x3231(0x32='2',0x31='1')

您需要将数值转换为其字符串表示形式,然后打印结果字符串。
我将展示一种简单的方法,说明如何在C中完成此操作,这应该足以让您将8086实现建立在以下基础上:

char string[8], *stringptr;
short num = 123;

string[7] = '$';  // DOS string terminator    

// The string will be filled up backwards
stringptr = string + 6;

while (stringptr >= string) {
    *stringptr = '0' + (num % 10);  // '3' on the first iteration, '2' on the second, etc
    num /= 10;  // 123 => 12 => 1 => 0
    if (num == 0) break;
    stringptr--;
}        

到目前为止,你有什么不起作用的?我将用它更新问题