输入A、B、C三个数,如果存在一个数为0,则全部清零,否则求和输出
程序运行:
代码:
datas segmentA dw 1B dw 0D dw 3S dw 0a_string db 0ffh, 0 ,100 dup(?)b_string db 0ffh, 0 ,100 dup(?)d_string db 0ffh, 0 ,100 dup(?) inputA db 'input A=$'inputB db 0dh,0ah,'input B=$'inputD db 0dh,0ah,'input D=$'error_number db 0dh,0ah,'error number$'outputA db 0dh,0ah,'A=$'outputB db 0dh,0ah,'B=$'outputD db 0dh,0ah,'D=$'outputS db 0dh,0ah,'S=$'datas endsstacks segment stackdb 100h dup(?)stacks endscodes segmentassume cs:codes,ds:datas,ss:stacks
main proc far
start:push dsmov ax,0hpush axmov ax,datas ;初始化dsmov ds,ax;输入a提示lea dx,inputAmov ah,9int 21h;输入alea dx,a_stringmov ah,10int 21h;a转成十进制数lea si,a_string+1call translate_to_numbermov A,ax;输入b提示lea dx,inputBmov ah,9int 21h;输入blea dx,b_stringmov ah,10int 21h;b转成十进制数lea si,b_string+1call translate_to_numbermov B,ax;输入d提示lea dx,inputDmov ah,9int 21h;输入dlea dx,d_stringmov ah,10int 21h;d转成十进制数lea si,d_string+1call translate_to_numbermov D,axmov ax,Acmp ax,0 ;判断A是否为0jz clear ;若为0,则清零mov bx,Bcmp bx,0 ;判断B是否为0jz clear ;若为0,则清零mov dx,Dcmp dx,0 ;判断D是否为0jz clear ;若为0,则清零add ax,bx ;求和add ax,dxmov S,ax ;把求和保存在Sjmp exitclear:mov ax,0 ;清零mov A,axmov B,axmov D,axexit:lea dx,outputA ;输出A、B、D、Smov ah,9int 21hmov ax,Acall decimallea dx,outputBmov ah,9int 21hmov ax,Bcall decimallea dx,outputDmov ah,9int 21hmov ax,Dcall decimallea dx,outputSmov ah,9int 21hmov ax,Scall decimalretmain endp;字符串转换为十进制数
translate_to_number proc near ;si:lenght firstpush cx push dx push bx push si push di mov di,10mov ax,0mov cl,[si]mov ch,0 cmp cx,0 jz errinc sitran:mov bl,[si]inc sicmp bl,'0'jb errcmp bl,'9'ja err sub bl,30hxor bh,bh mul di add ax,bx loop tranjmp exiterr:lea dx,error_numbermov ah,9int 21h mov ax,4c00hint 21hexit:pop di pop si pop bx pop dxpop cx ret
translate_to_number endpdecimal proc nearpush axpush cxpush dxpush bxcmp ax,0jge plusmov bx,axmov dl,'-'mov ah,2int 21hneg bxmov ax,bxplus:mov cx,0mov bx,10de:xor dx,dxdiv bxpush dxinc cxcmp ax,0jnz dede1:pop dxadd dl,30hmov ah,2 int 21h loop de1 pop bxpop dxpop cxpop axret decimal endpcodes endsend main