data segment?
num1 db 0;3 dup(?)?
num2 db 0;3 dup(?)?
data ends
code segment 'code'
assume cs:code,ds:data
start:?
mov ax,data
mov ds,ax?
mov si,offset num1?
输入一组数?
mov ah,01h?
int 21h?
sub al,'0';;
mov dl,al
mov cl,3
shl al,cl
shl dl,1
add al,dl
mov [si],al
mov ah,01h?
int 21h?
sub al,'0'
add [si],al?
mov ah,01h
int 21h
mov bx,offset num2?
再输入一组数
mov ah,01h?
int 21h?
sub al,'0'
mov dl,al
mov cl,3
shl al,cl
shl dl,1
add al,dl
mov [bx],al?
mov ah,01h?
int 21h?
sub al,'0'
add [bx],al?
mov ah,02h
mov dl,0dh
int 21h
mov dl,0ah
int 21h
把两组数求和?
mov al,[bx]
add al,[si];al=sum
xor ah,ah
mov cl,100
div cl
mov bx,ax
test al,al
jz? @f
add al,'0'
mov dl,al
mov ah,02h
int 21h
@@:
mov al,bh
xor ah,ah
mov cl,10
div cl
mov bx,ax
add al,'0'
mov dl,al
mov ah,02h
int 21h
add bh,'0'
mov dl,bh
mov ah,02h
int 21h
mov ah,4ch?
int 21h?
code ends?
end start
input example:
12 34<Enter>
or
02 08<Enter>
扩展资料:
十进制转二进制代码:
void dectobin( int n ){
int result=0,k=1,i,temp;
temp = n;
while(temp){
i = temp%2;
result = k * i + result;
k = k*10;
temp = temp/2;
}
printf("%dn", result);
}
算法分析:
在实现模2取余后需要逆序输出,这个地方通过不断乘以10来实现后一位比前一位的位数多10,不需要再通过数组或者逆序函数来实现。