汇编语言:从键盘输入有符号十进制数的子程序

data segment
count =0ah
array dw count dup(0)
over db ‘read over’,’$’
data ends

code segment;
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
xor ax,ax
mov cx,0ah
mov bx,offset array
again: call read
mov [bx],ax
inc bx
inc bx
call dpcrlf
loop again
mov dx,offset over
mov ah,09h
int 21h
mov ah,4ch
int 21h
read proc
push bx
push cx
push dx
xor bx,bx
xor cx,cx
mov ah,01h;al=输入字符的ASCII码
int 21h
cmp al,’+’
jz read1
cmp al,’-‘
jnz read2
mov cx,-1
read1: mov ah,01h;read1 再次输入
int 21h
read2: cmp al,’0’;判断输入的是否为0-9,是就乘以十,不是则输入结束
jb read3
cmp al,’9’
ja read3
sub al,30h
shl bx,1
mov dx,bx
shl bx,1
shl bx,1
add bx,dx
mov ah,0
add bx,ax
jmp read1;继续输入字符
read3: cmp cx,0
jz read4
neg bx
read4: mov ax,bx
pop dx
pop cx
pop bx
ret
read endp
dpcrlf proc;使光标回车换行
push ax
push dx
mov ah,02h
mov dl,0dh
int 21h
mov ah,02h
mov dl,0ah
int 21h
pop dx
pop ax
ret
dpcrlf endp

code ends
end start
avatar

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值