|
主题 : : 需求动力,快疯了(课设二的子程序之一) [待解决] |
回复[ 3次 ]
点击[ 457次 ] | |
|
|
|
|
[帖 主]
[ 发表时间:2010-08-31 22:26 ]
[引用]
[回复]
[ top ] | |
荣誉值:16
信誉值:0
注册日期:2010-07-09 09:48 |
;修改日期,时间,只做了一半的工作,还不能改变时间和日期。
;目前只能实现限定输入2个数字,不等于2个就报错。
assume cs:code
code segment
table dw charpush,charpop,charshow
top dw 0,0;top[0]=字符栈顶,top[2]暂存di的值
time dw year,month,day,hour,minuter,second
year: db 'Please input the year:',0
month: db 'month:',0
day: db 'day:',0
hour: db 'hour:',0
minuter: db 'minuter:',0
second: db 'second:',0
cuowu: db 'ERROR:the wrong number.',0
;-------------------------------------------
;-----------sub program
;-------------------------------------------
charstack:
push bx
push dx
push es
push di
cmp ah,2
ja sret
mov bl,ah
mov bh,0
add bx,bx
jmp word ptr table[bx]
charpush:
mov bx,top
mov [si][bx],al
inc top;
jmp sret
charpop:
cmp top,0
je sret
dec top;cs[top]指向字符栈顶,cs[top-1]指向当前字符。cs[top]的值是未知的。
mov bx,top
mov al,byte ptr [si][top]
jmp sret
charshow:
mov bx,0
charshows:
cmp bx,top
jne noempty
mov byte ptr es:[di],' ';清屏
jmp sret
noempty:
mov al,[si][bx]
mov es:[di],al
inc bx
add di,2
jmp charshows
sret:
mov top[2],di
pop di
pop es
pop dx
pop bx
ret
;-------------------------------------
;------------main program
;-------------------------------------
start:
mov ax,0
mov ds,ax
mov ax,0b800h
mov es,ax
mov di,0
mov si,0
mov cx,6
mov bx,0
times:
push si
push bx
mov bx,time[bx]
times1:
mov ah,cs:[bx+si]
cmp ah,0
jz timesok
mov es:[di],ah
add di,2
inc si
jmp short times1
timesok:
mov si,200
call getstr
mov di,top[2];di的值是延续的。
add di,2
mov byte ptr es:[di],' '
pop bx
add bx,2
pop si
loop times
mov ax,4c00h
int 21h
getstr:
push ax
getstrs:
mov ah,0
int 16h
cmp al,20h
jb nochar
cmp al,30h;0
jb getstrs
cmp al,39h;9
ja getstrs
mov ah,0
call charstack
mov ah,2
call charstack
jmp getstrs
nochar:
cmp ah,0eh;backspace
je backspace
cmp ah,1ch;enter
je enters
jmp getstrs
backspace:
mov ah,1
call charstack
mov ah,2
call charstack
jmp getstrs
enters:
mov ah,2
call charstack
cmp top,2
jne errors
mov ax,0
mov top,ax;将栈顶置0
pop ax
ret
;---------------------------------
;---------error program
;---------------------------------
errors:
push di
mov bx,offset cuowu
mov di,1800
errors1:
mov al,cs:[bx]
cmp al,0
jz errorsend
mov es:[di],al
add di,2
inc bx
jmp errors1
errorsend:
pop di
pop ax
pop bx;FOCUS:保持栈平衡,取代ret,这里的bx取值无关紧要。
jmp near ptr timesok
code ends
end start | | |
|
|
|
|
[第1楼]
[ 回复时间:2010-08-31 22:32 ]
[引用]
[回复]
[ top ] | |
荣誉值:16
信誉值:0
注册日期:2010-07-09 09:48 |
这个破东东想了偶2天,终于有突破的迹象了,高兴。向已经完成课设的同学们致敬! | | |
|
|
|
|
[第2楼]
[ 回复时间:2010-08-31 23:11 ]
[引用]
[回复]
[ top ] | |
荣誉值:16
信誉值:0
注册日期:2010-07-09 09:48 |
;完整的修改日期 时间程序,调试通过,没有dos环境可以用,那位帮我试下效果
assume cs:code
code segment
table dw charpush,charpop,charshow
top dw 0,0,0,0,0,0,0,0;top[0]=字符栈顶,top[2]暂存di的值
time dw year,month,day,hour,minuter,second
year: db 'Please input the year:',0
month: db 'month:',0
day: db 'day:',0
hour: db 'hour:',0
minuter: db 'minuter:',0
second: db 'second:',0
cuowu: db 'ERROR:the wrong number.',0
port: db 9,8,7,4,2,0
;-------------------------------------------
;-----------sub program
;-------------------------------------------
charstack:
push bx
push dx
push es
push di
cmp ah,2
ja sret
mov bl,ah
mov bh,0
add bx,bx
jmp word ptr table[bx]
charpush:
mov bx,top
mov [si][bx],al
inc top;
jmp sret
charpop:
cmp top,0
je sret
dec top;cs[top]指向字符栈顶,cs[top-1]指向当前字符。cs[top]的值是未知的。
mov bx,top
mov al,byte ptr [si][top]
jmp sret
charshow:
mov bx,0
charshows:
cmp bx,top
jne noempty
mov byte ptr es:[di],' ';清屏
jmp sret
noempty:
mov al,[si][bx]
mov es:[di],al
inc bx
add di,2
jmp charshows
sret:
mov top[2],di
pop di
pop es
pop dx
pop bx
ret
;-------------------------------------
;------------main program
;-------------------------------------
start:
mov ax,0
mov ds,ax
mov ax,0b800h
mov es,ax
mov di,0
mov si,0
mov cx,6
mov bx,0
times:
push si
push bx
mov bx,time[bx]
times1:
mov ah,cs:[bx+si]
cmp ah,0
jz timesok
mov es:[di],ah
add di,2
inc si
jmp short times1
timesok:
mov si,200
call getstr
pop bx
add bx,2
push bx
add bx,2
push word ptr ds:[si]
pop word ptr top[bx];将获取的数字保存到top4 6 8 10 12 14内存中。
mov di,top[2];di的值是延续的。
add di,2
mov byte ptr es:[di],' '
pop bx
pop si
loop times
mov si,offset port
mov bx,4
mov cx,6
chang:
push cx
mov al,[si]
out 70h,al
mov ax,top[bx]
sub ah,30h
sub al,30h
mov cl,4
shl ah,cl
add al,ah
out 71h,al
add bx,2
inc si
pop cx
loop chang
mov ax,4c00h
int 21h
getstr:
push ax
getstrs:
mov ah,0
int 16h
cmp al,20h
jb nochar
cmp al,30h;0
jb getstrs
cmp al,39h;9
ja getstrs
mov ah,0
call charstack
mov ah,2
call charstack
jmp getstrs
nochar:
cmp ah,0eh;backspace
je backspace
cmp ah,1ch;enter
je enters
jmp getstrs
backspace:
mov ah,1
call charstack
mov ah,2
call charstack
jmp getstrs
enters:
mov ah,2
call charstack
cmp top,2
jne errors
mov ax,0
mov top,ax;将栈顶置0
pop ax
ret
;---------------------------------
;---------error program
;---------------------------------
errors:
push di
mov bx,offset cuowu
mov di,1800
errors1:
mov al,cs:[bx]
cmp al,0
jz errorsend
mov es:[di],al
add di,2
inc bx
jmp errors1
errorsend:
pop di
pop ax
pop bx;FOCUS:保持栈平衡,取代ret,这里的bx取值无关紧要。
jmp near ptr timesok
code ends
end start | | |
|
|
|
|
[第3楼]
[ 回复时间:2010-09-01 10:11 ]
[引用]
[回复]
[ top ] | |
荣誉值:16
信誉值:0
注册日期:2010-07-09 09:48 |
本想做一个检测程序检验输入的时间 日期格式是否正确,太复杂了,月份是1~12,日期是1-31,小时是0-24,分秒是0-60,靠,竟然有4种格式,最少需要4个检测子程序,还是算了吧。不知有没其他方法可以校验格式的方法,望高手指点一二。 | | |
|