输入一个正数,该数减去递增奇数(从1开始)直至小于等于零为止,计算该数减去奇数的个数
程序运行:

代码:
datas segmentNUM      dw 17ANS      dw 0NUM_string        db  0ffh, 0 ,100 dup(?)inputNUM          db 'input NUM=$'error_number    db 0dh,0ah,'error number$'outputANS         db 0dh,0ah,'ANS=$'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,inputNUMmov ah,9int 21h;输入alea dx,NUM_stringmov ah,10int 21h;a转成十进制数lea si,NUM_string+1call translate_to_numbermov NUM,ax;mov ax,NUMmov bx,1 mov cx,0 s:sub ax,bx            ;减去奇数inc cx add bx,2             ;奇数加2cmp ax,0             ;判断ax是否大于0jg s                  ;若大于0,循环继续mov ANS,cx	  lea dx,outputANS           ;输出ANSmov ah,9int 21hmov ax,ANScall 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 endp
codes endsend main