概述
- BCD码实现
data segment
a db 5
db ?
db 5 dup(0)
b db 5,?,5 dup(0)
data ends
stack segment para stack
db 10 dup(0)
stack ends
code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
lea dx,a
mov ah,0ah
int 21h
lea dx,b
mov ah,0ah
int 21h
mov si,5
mov cx,5
mov a[1],0
mov b[1],0
clc
lop: mov al,a[si]
adc al,b[si]
aaa
mov a[si],al
dec si
loop lop
mov si,1
mov cx,5
lop1: add a[si],30h
inc si
loop lop1
mov a[si],"$"
mov si,0
mov cx,5
lop2: inc si
cmp a[si],30h
loopz lop2
cmp cx,0
jz over
next: lea dx,a[si]
mov ah,9
int 21h
over: mov ah,4ch
int 21h
code ends
end start
- 十六进制与ASCII码转换
data segment
asc1 db 5
db ?
db 5 dup(0)
asc2 db 5
db ?
db 5 dup(0)
org 10h
num1 dw 0
num2 dw 0
org 20h
ans dw 0
org 30h
output db 5 dup(0),"$"
org 40h
weight dw 10000,1000,100,10,1
error db "input error!$"
swp db 0dh,0ah,"$"
data ends
stack segment para stack
dw 10 dup(0)
stack ends
code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
lea dx,asc1
mov ah,0ah
int 21h
lea si,asc1+2
call check
jc err_1
lea dx,asc2
mov ah,0ah
int 21h
lea si,asc2+2
call check
jc err_1
mov si,offset asc1+2
mov di,offset num1
mov bx,offset weight+2
mov cx,4
call AscToNum
mov si,offset asc2+2
mov di,offset num2
call AscToNum
mov ax,num1
add ax,num2
mov ans,ax
call NumToAsc
lea dx,swp
mov ah,9
int 21h
lea si,output
mov cx,5
lop3: cmp byte ptr [si],"0"
jnz outp
inc si
loop lop3
dec si
outp: mov dx,si
mov ah,9
int 21h
jmp over
err_1: lea dx,error
mov ah,9
int 21h
over: mov ah,4ch
int 21h
check proc
push si
push cx
mov cx,4
lop0: cmp byte ptr [si],"0"
jb err
cmp byte ptr [si],"9"
ja err
inc si
loop lop0
clc
jmp return
err: stc
return: pop cx
pop si
ret
check endp
AscToNum proc
push si
push bx
push cx
push ax
mov ax,0
lop1: sub byte ptr [si],30h
mov al,[si]
mul word ptr [bx]
add word ptr[di],ax
mov ax,0
inc si
inc bx
inc bx
loop lop1
pop ax
pop cx
pop bx
pop si
ret
AscToNum endp
NumToAsc proc
push si
push bx
push ax
push dx
push cx
mov cx,5
lea bx,weight
lea si,output
mov dx,0
lop2: mov ax,ans
div word ptr [bx]
add al,30h
mov [si],al
mov ah,0
mov ans,dx
mov dx,0
inc bx
inc bx
inc si
loop lop2
pop cx
pop dx
pop ax
pop bx
pop si
ret
NumToAsc endp
code ends
end start
最后
以上就是沉默便当为你收集整理的(汇编语言)从键盘输入2个4位10进制数,求其和,将结果以10进制数的形式在屏幕输出。的全部内容,希望文章能够帮你解决(汇编语言)从键盘输入2个4位10进制数,求其和,将结果以10进制数的形式在屏幕输出。所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复