如何在微处理器8086中以汇编语言添加两个16位数字 [英] How can I add two 16 bit numbers in assembly language in microprocessor 8086

查看:129
本文介绍了如何在微处理器8086中以汇编语言添加两个16位数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我正在使用7 x86窗口.我想添加两个16位数字.

Hey I am using window 7 x86. I want to add two 16 bit numbers.

当我添加3+3时,其答案是正确的,但是当我添加7+7时,它不起作用.我想加上两个数字,例如75+75,其答案应为150.

When I add 3+3 its answer is correct but when I add 7+7 it's not working. And I want to add two numbers like 75+75 its answer should be 150.

请告诉我它的程序是什么.提前感谢

What is its procedure please tell me. Thanx in advance

.model small
.stack 100h
.data
num db 9 dup(0)
result dw 9 dup (0)
.code
main proc
mov ax,@data
mov ds,ax

mov ah, 1
int 21h    ; get input from user
mov num, al    ; store in the array 

int 21h              ;get 2nd number from user
mov num+1, al        ;store in the array at num[1] index

mov al, num          ;mov number into al
add dl, num+1        ;add num[1] in the num which is in dl

sub dl, 48           ; subract from assci so it become number 0 ~ 9

mov ah, 2            ; output
int 21h

mov ah, 4ch
int 21h
main endp
end main

推荐答案

以下是在8086上添加2个16位数字的代码:

Here is the code to add 2 16-bit numbers on 8086:

.model small
.data
a db "Enter the first number$"
b db "Enter the second number$"
c db "The sum is: $"
d db 00h

.code
start:
mov ax,@data
mov ds,ax
mov dx,offset a
mov ah,09h
int 21h

mov ah,01h
int 21h
mov bh,al
mov ah,01h
int 21h
mov bl,al

mov dx,offset b
mov ah,09h
int 21h
mov ah,01h
int 21h
mov ch,al
mov ah,01h
int 21h  
mov cl,al
add al,bl
mov ah,00h
aaa
add bh,ah
add bh,ch
mov d,al
mov al,bh
mov ah,00h
aaa
mov bx,ax
add bx,3030h

mov dx,offset c
mov ah,09h
int 21h

mov dl,bh
mov ah,02h
int 21h
mov dl,bl
mov ah,02h
int 21h
mov dl,d
add dl,30h
mov ah,02h
int 21h
end start

这里的窍门在于使用"aaa"命令解包数字.

The trick here lies in using 'aaa' command to unpack the digits.

这篇关于如何在微处理器8086中以汇编语言添加两个16位数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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