简单的方法来在x86汇编寄存器的值打印 [英] Simple way to print value of a register in x86 assembly

查看:719
本文介绍了简单的方法来在x86汇编寄存器的值打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要写在8086大会,从用户接收数据的程序,做一些数学计算,并在屏幕上的答案,我已经写了程序的所有部分和所有工作正常,但我不知道如何打印数到屏幕上。

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.

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

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?

推荐答案

您可以使用C-库函数itoa,
实现它并不难,basicaly,你做的:

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)

无效print_number(INT X);

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

这篇关于简单的方法来在x86汇编寄存器的值打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆