输入身份证前十七位数字,输入18位身份证
程序运行:
代码:
datas segmentw db 7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2y db '1','0','X','9','8','7','6','5','4','3','2'ID_max_length db 18ID db 0, 19 dup(?)input db 'input 17-bit digital code=$'output db 0dh,0ah,'output ID=$'output_error db 0dh,0ah,'input error$'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;输入提示lea dx,inputmov ah,9int 21h;输入Nlea dx,ID_max_lengthmov ah,10 int 21hlea si,IDmov cl,[si] ;设置循环次数cmp cl,17 ;判断长度是否合法jnz errxor ch,ch inc si mov dx,0 s:mov al,17sub al,cl lea bx,wxlat ;获取Wimov bl,[si]cmp bl,'0' ;判断字符是否合法jb errcmp bl,'9'ja errsub bl,30h ;获取Aimul bl ;乘积add dx,ax ;累加求和inc siloop s mov ax,dxmov bl,11 ;和对11求余数div blmov al,ah lea bx,yxlat ;获得第一位字符mov ID+1+17,al ;设置输出字符串mov ID+1+18,'$'lea dx,output ;输出提示mov ah,9int 21hlea dx,ID+1 ;输出身份证号码mov ah,9int 21hjmp exiterr:lea dx,output_error ;若错误,输出错误提示mov ah,9int 21h exit:retmain endp
codes endsend main