用汇编语言编写程序实现S=(X2+Y2)/Z的值,并将结果放入RESULT单元
2个回答
展开全部
;通过地址表传参p204 求两之和,并显示
;PROADD_2_EX6_4_2
;*************************************
PROG_SEG SEGMENT
org 100h
assume cs:prog_seg,ds:prog_seg,ss:prog_seg
main proc near
;
mov ax,prog_seg
mov ds,ax
call decibin
mov num1,bx
call crlf
call decibin
mov num2,bx
call crlf
call addnew
mov bx,result
call binidec
mov bx,[result+2]
call binidec
;exit:;COM格式中不能同时出现同名标记!
; mov ax,4c00h
; int 21h
ret;
main endp
;---------------------------------------------------------
;--------------------------------------------
decibin proc near
mov bx,0
;
newchar:
mov ah,1
int 21h
sub al,30h
jl exit
cmp al,9d
jg exit
cbw
xchg ax,bx
mov cx,10d
mul cx
xchg ax,bx
;
add bx,ax
jmp newchar
exit:
ret
;返回值在BX内
decibin endp
;-------------------------------------------
;---------------------------------------
crlf proc near
mov dl,0dh
mov ah,2
int 21h
mov dl,0ah
mov ah,2
int 21h
ret
crlf endp
;--------------------------------------
binidec proc near
;subroutine to conbert binary number in bx
;to decimal on console screen
mov cx,10000d
call dec_div
mov cx,1000d
call dec_div
mov cx,100d
call dec_div
mov cx,10d
call dec_div
mov cx,1d
call dec_div
ret
binidec endp
;----------------------------------------------
dec_div proc near
;subroutine to divide number in bx by number in cx
;print quotient on screen
;(numberator in DX+AX,denom in CX)
mov ax,bx
mov dx,0
div cx
mov bx,dx
mov dl,al
;print to contents of DL on screen
sub dl,0
jz exit1
add dl,30h
mov ah,2h
int 21h
exit1:
ret
dec_div endp
;-----------------------------------------
;-----------------------------------------
addnew proc near
mov ax,num1
mov dx,0
mov cx,num2
mov bx,0
add ax,cx
adc dx,bx
mov result,ax
mov [result+2],dx
ret
addnew endp
;-----------------------------------------
;----------------------------------------------------------
num1 dw ?
num2 dw ?
result dw 2 dup(?)
table2 dw 4 dup(?)
;______________________________________________________
prog_seg ends
end main
;PROADD_2_EX6_4_2
;*************************************
PROG_SEG SEGMENT
org 100h
assume cs:prog_seg,ds:prog_seg,ss:prog_seg
main proc near
;
mov ax,prog_seg
mov ds,ax
call decibin
mov num1,bx
call crlf
call decibin
mov num2,bx
call crlf
call addnew
mov bx,result
call binidec
mov bx,[result+2]
call binidec
;exit:;COM格式中不能同时出现同名标记!
; mov ax,4c00h
; int 21h
ret;
main endp
;---------------------------------------------------------
;--------------------------------------------
decibin proc near
mov bx,0
;
newchar:
mov ah,1
int 21h
sub al,30h
jl exit
cmp al,9d
jg exit
cbw
xchg ax,bx
mov cx,10d
mul cx
xchg ax,bx
;
add bx,ax
jmp newchar
exit:
ret
;返回值在BX内
decibin endp
;-------------------------------------------
;---------------------------------------
crlf proc near
mov dl,0dh
mov ah,2
int 21h
mov dl,0ah
mov ah,2
int 21h
ret
crlf endp
;--------------------------------------
binidec proc near
;subroutine to conbert binary number in bx
;to decimal on console screen
mov cx,10000d
call dec_div
mov cx,1000d
call dec_div
mov cx,100d
call dec_div
mov cx,10d
call dec_div
mov cx,1d
call dec_div
ret
binidec endp
;----------------------------------------------
dec_div proc near
;subroutine to divide number in bx by number in cx
;print quotient on screen
;(numberator in DX+AX,denom in CX)
mov ax,bx
mov dx,0
div cx
mov bx,dx
mov dl,al
;print to contents of DL on screen
sub dl,0
jz exit1
add dl,30h
mov ah,2h
int 21h
exit1:
ret
dec_div endp
;-----------------------------------------
;-----------------------------------------
addnew proc near
mov ax,num1
mov dx,0
mov cx,num2
mov bx,0
add ax,cx
adc dx,bx
mov result,ax
mov [result+2],dx
ret
addnew endp
;-----------------------------------------
;----------------------------------------------------------
num1 dw ?
num2 dw ?
result dw 2 dup(?)
table2 dw 4 dup(?)
;______________________________________________________
prog_seg ends
end main
展开全部
小写变大写
DATA SEGMENT
RESULT DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AH,1H
INT 21H
CMP AL,61H
JB NEXT
CMP AL,7AH
JA NEXT
SUB AL,20H
MOV DL,AL
MOV AH,2
INT 21H
NEXT: MOV AH,4CH
INT 21H
CODE ENDS
END START
计算
DATA SEGMENT
RESULT DB ?
X2 DB 30
Y2 DB 30
Z DB 20
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AL,X2
ADD AL,Y2
MUL Z
MOV RESULT,AL
MOV AH,4CH
INT 21H
CODE ENDS
END START
DATA SEGMENT
RESULT DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AH,1H
INT 21H
CMP AL,61H
JB NEXT
CMP AL,7AH
JA NEXT
SUB AL,20H
MOV DL,AL
MOV AH,2
INT 21H
NEXT: MOV AH,4CH
INT 21H
CODE ENDS
END START
计算
DATA SEGMENT
RESULT DB ?
X2 DB 30
Y2 DB 30
Z DB 20
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AL,X2
ADD AL,Y2
MUL Z
MOV RESULT,AL
MOV AH,4CH
INT 21H
CODE ENDS
END START
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询