在 x86 程序集中打印寄存器值的简单方法

发布于 2024-08-29 20:07:38 字数 163 浏览 1 评论 0原文

我需要在 8086 Assembly 中编写一个程序,接收来自用户的数据,进行一些数学计算并在屏幕上打印答案,我已经编写了程序的所有部分并且一切正常,但我不知道如何打印号码显示到屏幕上。

在我所有计算结束时,答案是 AX,它被视为无符号 16 位整数。如何打印 AX 寄存器的十进制(无符号)值?

I need to write a program in 8086 Assembly that receives data from the user, does some mathematical calculations and prints the answer on the screen, I have written all parts of the program and all work fine but I don't know how to print the number to the screen.

At the end of all my calculation the answer is AX and it is treated as an unsigned 16 bit integer. How do I print the decimal (unsigned) value of the AX register?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

滥情哥ㄟ 2024-09-05 20:07:38

你可以使用 C 库函数 itoa,
实现它并不难,基本上,你可以这样做:

while (x){
    buff[n]==x % 10;
    x/=10;
    n++;
}

然后反转缓冲区(或向后打印字符)

void print_number(int x);

print_number:
  buff db 15 dup(0)
  mov ax,[esp+4]
  mov bx,0
itoa_w1:

  mov cx, ax
  mod cx,10
  add cx,30h;'0'
  div ax,10
  mov buff[bx],cl
  cmp ax,0
  jnz itoa_w1

itoa_w2:
  push buff[bx]
  call putchar
  pop  ax
  cmp  bx,0
  jnz itoa_w2

ret

you could use the C-library function itoa,
implementing it isn't that hard, basicaly, you do:

while (x){
    buff[n]==x % 10;
    x/=10;
    n++;
}

and then invert the buffer (or print character-wise backwards)

void print_number(int x);

print_number:
  buff db 15 dup(0)
  mov ax,[esp+4]
  mov bx,0
itoa_w1:

  mov cx, ax
  mod cx,10
  add cx,30h;'0'
  div ax,10
  mov buff[bx],cl
  cmp ax,0
  jnz itoa_w1

itoa_w2:
  push buff[bx]
  call putchar
  pop  ax
  cmp  bx,0
  jnz itoa_w2

ret
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文