汇编语言数组求和
答案:1 悬赏:30 手机版
解决时间 2021-02-22 01:01
- 提问者网友:活着好累
- 2021-02-21 12:31
汇编语言数组求和
最佳答案
- 五星知识达人网友:鸠书
- 2021-02-21 13:29
DATAS SEGMENT
num DB 22,33,44,55,66
sum DW 5 dup(0)
DATAS ENDS
STACKS SEGMENT
;此处输入堆栈段代码
STACKS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
lea si,num
call add_sub
mov [sum],ax
call disp_sub
MOV AH,4CH
INT 21H
add_sub proc ;求和子程序
mov cx, 5
mov al,0
mov ah,0
lp: add al,[si]
adc ah,0
inc si
loop lp
ret
add_sub endp
disp_sub proc near ;显示字程序
;mov ax,sum
mov bl,10
mov di,0
s:
mov dx,0
cmp ax,0
jz r
mov ah,0
div bl ;商在al, 余数在ah
mov dl,ah
push dx ;保存余数(个位数)
inc di
loop s
r:
mov cx,di
mov ah,02H
s1: pop dx
add dl,30H
int 21H ;显示位数
loop s1
ret
disp_sub endp
CODES ENDS
END START
num DB 22,33,44,55,66
sum DW 5 dup(0)
DATAS ENDS
STACKS SEGMENT
;此处输入堆栈段代码
STACKS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
lea si,num
call add_sub
mov [sum],ax
call disp_sub
MOV AH,4CH
INT 21H
add_sub proc ;求和子程序
mov cx, 5
mov al,0
mov ah,0
lp: add al,[si]
adc ah,0
inc si
loop lp
ret
add_sub endp
disp_sub proc near ;显示字程序
;mov ax,sum
mov bl,10
mov di,0
s:
mov dx,0
cmp ax,0
jz r
mov ah,0
div bl ;商在al, 余数在ah
mov dl,ah
push dx ;保存余数(个位数)
inc di
loop s
r:
mov cx,di
mov ah,02H
s1: pop dx
add dl,30H
int 21H ;显示位数
loop s1
ret
disp_sub endp
CODES ENDS
END START
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯