如何打印在大会8086多少? [英] How to print a number in Assembly 8086?

查看:134
本文介绍了如何打印在大会8086多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个接收数​​字(我提前了),并打印的功能。我该怎么办呢?

我到目前为止有:

 组织100H推10
调用print_numprint_num:推基点
MOV BP,SP
MOV AX,[BP + 2 * 2]
MOV BX,CS
MOV ES,BX
MOV DX,串
MOV DI,DX
STOSW
MOV啊,09H
INT 21H
流行基点
RET串:


解决方案

你在字符串的地址将是什么数值,​​而不是字符串重新$该值的对$ psentation。

的值12和字符串12是两个不同的事情。看作是一个16位的十六进制值,12是0x000C而12是0x3231(0x32 =='2',0X31 =='1')。

您需要的数值转换成它的字符串重新presentation,然后打印生成的字符串。结果而不是仅仅粘贴完成的解决方案,我将展示如何这可以在C做了一个简单的方法,这应该是够你在基地8086实现:

 字符字符串[8],* stringptr;
短NUM = 123;字符串[7] =$; // DOS字符串结束//字符串会倒着填满
stringptr =字符串+ 6;而(stringptr> =字符串){
    * stringptr ='0'+(NUM%10);在第一次循环//'3','2'在第二,等等
    NUM / = 10; // 123 => 12 => 1 => 0
    如果(NUM == 0)打破;
    stringptr--;
}

I'm trying to write a function that receives a number (which I pushed earlier), and prints it. How can I do it?

What I have so far:

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:

解决方案

What you're placing at the address of string is a numerical value, not the string representation of that value.

The value 12 and the string "12" are two separate things. Seen as a 16-bit hexadecimal value, 12 would be 0x000C while "12" would be 0x3231 (0x32 == '2', 0x31 == '1').

You need to convert the numerical value into its string representation and then print the resulting string.
Rather than just pasting a finished solution I'll show a simple way of how this could be done in C, which should be enough for you to base an 8086 implementation on:

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--;
}        

这篇关于如何打印在大会8086多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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