简体   繁体   English

带“ base 10” EMU8086的减法组件

[英]Subtraction assembly with “base 10” EMU8086

Hello I'm making a base 10 calculator in assembler that can take number with max length of 5 dig... so there is two numbers after the input was taken one of the five dig number is stored in ax and bl for example 您好,我正在用汇编器制作一个以10为基数的计算器,该计算器可以接受最大5位数长度的数字...因此,在获取输入后有两个数字,例如,五个位数中的一个存储在ax和bl中

AX - 23 45
BX - 00 01

So the value of the input is 12345 And the other is for example is 23243 and it's stored on CX and DX with the same idea of the first number (that stored in AX and BX ...) Now, I have made the addition code, but I can't figure out how making the Subtraction code with all the neg problem... 所以输入的值是12345 ,另一个是例如23243 ,它以与第一个数字相同的方式(存储在AXBX )存储在CXDX 。现在,我做了加法代码,但我不知道如何制作带有所有小问题的减法代码...

So what I thought to do is to, for example, take bh (that I'm not using because the number can't be longer than 6 digs...) and if the number is negative Ill put 1 and if its positive I'll put 0 so this problem is solved, Now the problem is that I dont know how to make the code work like with all the sub part and the carry and every thing ...(in the addition i used commands like adc,daa...) 所以我想做的是,例如,取bh(我不使用,因为该数字不能超过6个数字...),如果该数字为负,则输入1,如果其为正, '将0置为0,因此此问题得以解决,现在的问题是,我不知道如何使代码像所有sub部分,进位和所有东西一样工作……(此外,我使用了诸如adc,daa之类的命令...)

last example: value is: 12345 and its positive 最后一个示例:值是:12345及其正数

AX - 23 45  
BX - 00 01 
(if Bh is 0 the number is positive if 1 its negative...)

Now the value is : 23243 and its positive CX - 32 43 DX - 00 02 现在的值为:23243及其正CX-32 43 DX-00 02

Calculation 12345-23243(= -10898) 计算12345-23243(= -10898)

lets say the answer goes to CX AND DX so it will look like that: 可以说答案去了CX AND DX,所以看起来像这样:

CX - 08 98
DX - 01 01

answer: (-10898) 答案:(-10898)

Can someone please help me/give me an example code that I'll know how to do it ? 有人可以帮我/给我一个我会做的示例代码吗?

Sorry if I'm little bit Confused... 对不起,如果我有点困惑...

Thx. 谢谢。 EDIT: here is the addition code that you ask for: 编辑:这是您要求的附加代码:

proc Add_two_numbers;2 values useing stack...
    pop [150]
    pop dx
    pop cx
    pop bx
    pop ax
    add al,cl
    daa 
    mov cl,al
    mov al,ah
    adc al,ch
    daa
    mov ch,al
    mov al,bl
    adc al,dl
    daa
    mov dl,al
    push cx
    push dx
    push [150]
    ret
endp Add_two_numbers  

2nd edit: I figure out how making it Negative so I just need algorithms that sub 2 number it does not need to work with numbers like 1000-2000 please make it work only on positive values like 2000-1000 第二编辑:我想出如何使其为负数,所以我只需要sub 2数字的算法,它不需要与1000-2000之类的数字一起使用,请使其仅对正数值(如2000-1000)起作用

Answering your comment, this is one way you can convert from decimal and back using C as an example. 回答您的评论,这是您可以使用C作为示例从十进制转换回去的一种方法。 I leave you to code it in asm! 我让你在asm中编码!

#include <conio.h>

#define MAX  100000000

// input a signed decimal number
int inp_num(void) {
    int number=0, neg=0, key;
    while (number < MAX) {
        key = _getche();
        if (key == '-') {
            if (number==0)
                neg = 1;        // else ignore
        }
        else if (key >= '0' && key <= '9')
            number = number * 10 + key - '0';
        else
            break;
    }
    if (neg)
        number = -number;
    _putch('\n');
    return number;
}

// output a signed number as decimal
void out_num(int number) {
    int digit, suppress0, d;
    suppress0 = 1;              // zero-suppression on
    if (number < 0) {
        _putch('-');
        number =-number;
    }
    for (d=MAX; d>0; d/=10) {
        digit = number / d;
        if (digit)              // if non-0
            suppress0 = 0;      // cancel zero-suppression
        if (!suppress0)
            _putch('0' + digit);
        number -= digit * d;
    }    
}

int main(void) { 
    int number;
    number = inp_num();
    out_num(number);
    return 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM