输入三个数,计算相等数的个数
程序运行:
代码:
datas segmenta db 0ffh, 0 ,100 dup(?)b db 0ffh, 0 ,100 dup(?)d db 0ffh, 0 ,100 dup(?) ARRAY dw 1,2,2inputA db 'input a=$'inputB db 0dh,0ah,'input b=$'inputD db 0dh,0ah,'input d=$'output db 0dh,0ah,'result=$'error_number db 0dh,0ah,'error number$'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,amov ah,10int 21h;a转成十进制数lea si,a+1call translate_to_numbermov ARRAY[0],ax;输入b提示lea dx,inputBmov ah,9int 21h;输入blea dx,bmov ah,10int 21h;b转成十进制数lea si,b+1call translate_to_numbermov ARRAY[2],ax;输入d提示lea dx,inputDmov ah,9int 21h;输入dlea dx,dmov ah,10int 21h;a转成十进制数lea si,d+1call translate_to_numbermov ARRAY[4],axlea dx,outputmov ah,9int 21hmov ax,ARRAY[0]mov bx,ARRAY[2]cmp ax,bx ;判断ARRAY[0]与ARRAY[2]是否相等jnz able_two ;若不相等,跳转cmp ax,ARRAY[4] ;判断ARRAY[0]与ARRAY[4]是否相等 jnz two ;若不等,跳转mov dl,'2' ;输出三个数相等的结果mov ah,2int 21hjmp exitable_two:cmp ax,ARRAY[4] ;判断ARRAY[0]与ARRAY[4]是否相等 jz two ;若相等,跳转cmp bx,ARRAY[4] ;若不等,比较ARRAY[2]与ARRAY[4]jz two ;若相等,跳转mov dl,'0' ;若不等,输出三个数不等的结果mov ah,2int 21hjmp exittwo:mov dl,'1' ;输出两个数相等的结果mov ah,2int 21hexit: retmain 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 endp;输出十进制数
decimal proc near push axpush cxpush dxpush bxmov bx,ax cmp ax,0jge plusmov dl,'-'mov ah,2int 21hneg bx mov ax,bx plus:mov cx,0mov bx,10 de:xor dx,dx div bx push dx inc cx cmp ax,0hjnz de de1:pop dx add dl,30hmov ah,2 int 21hloop de1 pop bx pop dx pop cx pop ax retdecimal endpcodes endsend main