TITLE MONTH(EXE)
DATASEG SEGMENT PARA 'DATA';PARA 'DATA'表示DATA段边界XXX0H开始
THREE DB 3
MONIN DB 3, 4 DUP(?);应该在4与DUP之间有空格才行!
ALFMONTH DB '???','$'
MONTHTAB DB 'JAN','FEB','MAR','APR','MAY','JUN'
DB 'JUL','AUG','SEP','OCT','NOV','DEC'
DATASEG ENDS
CODESEG SEGMENT PARA 'CODE'
ASSUME DS:DATASEG,CS:CODESEG,ES:DATASEG ;这样写DATA:DATASEG,CODE:CODESEG,EDATA:DATASEG错误!
;不能是中文的分号否则有错--------------------------------------------------------------
MAIN PROC FAR;顺序弄错了,不是FAR PROC,而是 PROC FAR;
PUSH DS
SUB AX,AX
PUSH AX
MOV AX,DATASEG;指向数据段;
MOV DS,AX
MOV ES,AX
CALL INPUT
CALL LOCATE
CALL DISP
RET
MAIN ENDP
;----------------------------------------------------------------------
INPUT PROC NEAR
PUSH DX
MOV AH,0AH;带缓冲区的键盘输入;
LEA DX,MONIN
INT 21H;第一个字节是键入的最大字符数,第二个DOS填入实际键入的字符数;
MOV AH,MONIN+2;第三个字节之后才是键盘输入的字符;
MOV AL,MONIN+3
XOR AX,3030H;ascii码转换成十进制;clear ASCII 3's
CMP AH,00H ;moth 01~09?
JZ RETURN ;如果在1~9月之间就return;
SUB AH,AH ;no,clear AH
ADD AL,10;如果AH大于1,表示月份大于9,所以加十;
RETURN:
POP DX
RET
INPUT ENDP
;------------------------------------------------------------------------
LOCATE PROC NEAR
PUSH SI
PUSH DI
PUSH CX
LEA SI,MONTHTAB
DEC AL ;月份存放在AL当中,(AL-1)*3刚好指向表格首地址
MUL THREE ;3 chars for each month
ADD SI,AX ;应该存放在SI当中,因为MOVSB是将DS:SI的数据存放到ES:DI当中;
LEA DI,ALFMONTH
MOV CX,3 ;init3 chars move
CLD ;置方向标志为up或者down;
REP MOVSB
POP CX;restore registers
POP DI
POP SI
RET
LOCATE ENDP
;-------------------------------------------------------------------------
DISP PROC NEAR
PUSH DX
LEA DX,ALFMONTH;address of output buffer
MOV AH,09H ;display function
INT 21H
POP DX ;忘记弹出DX寄存器
RET
DISP ENDP
;------------------------------------------------------------------------------
CODESEG ENDS;codeseg写错不能生成目标文件.obj
END MAIN
键盘输入一个二位十进制的月份数,然后显示出相应的英文缩写名;
最新推荐文章于 2021-09-14 14:24:05 发布