China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-29 10:07
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » With everyone's effort, batch files can say goodbye to choice DigestI View 15,156 Replies 45
Floor 16 Posted 2008-12-10 08:32 ·  中国 福建 泉州 移动
初级用户
★★
Credits 134
Posts 54
Joined 2008-11-19 11:47
17-year member
UID 131429
Gender Male
Status Offline
Originally posted by s11ss at 2008-12-9 22:48:


By no keypress, do you mean directly pressing Enter? If only function 0 is used, then al is 0d



No keypress means not touching the keyboard at all.
Floor 17 Posted 2008-12-10 14:00 ·  中国 福建 三明 电信
中级用户
★★
Credits 458
Posts 211
Joined 2006-07-26 19:42
19-year member
UID 59307
Status Offline
Really powerful. People like me who don't understand assembly can only sigh in admiration.
┌───────┐
├→学习→实践→┤
└───────┘
Floor 18 Posted 2008-12-10 14:31 ·  中国 江苏 苏州 电信
银牌会员
★★★
Credits 2,227
Posts 790
Joined 2005-01-27 00:00
21-year member
UID 35703
Gender Male
Status Offline
In the program above, mov ax,0 is 3 bytes long. Changing it to mov ah,0 or xor ah,ah or sub ah,ah saves 1 byte.

Actually, the shortest program of this kind only needs 8 bytes.

DEBUG
a
mov ah,0
int 16h
mov ah,4Ch
int 21h

rcx
8
nkeycode.com
w
q
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
s11ss +7 2008-12-10 14:53
my major is english----my love is dos----my teacher is the buddha----my friends--how about U
Floor 19 Posted 2008-12-10 14:55 ·  中国 北京 联通
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
<!Originally posted by 本是 at 2008-12-10 02:31 PM:
In the program above, mov ax,0 is 3 bytes long. Changing it to mov ah,0 or xor ah,ah or sub ah,ah saves 1 byte.

Actually, the shortest program of this kind only needs 8 bytes.

DEBUG
a
mov ah,0
int 16h
mov ah,4Ch
...

What I mean is not using function 1 of int 16h, and it seems it still works~

Actually it seems you don't need to write a com either, you can call it directly with debug :)]>
Floor 20 Posted 2008-12-10 15:32 ·  中国 福建 泉州 移动
初级用户
★★
Credits 134
Posts 54
Joined 2008-11-19 11:47
17-year member
UID 131429
Gender Male
Status Offline
Originally posted by 本是 at 2008-12-10 14:31:
In the program above, mov ax,0 is 3 bytes long. Changing it to mov ah,0 or xor ah,ah or sub ah,ah saves 1 byte.

Actually, the shortest program of this kind only needs 8 bytes.

DEBUG
a
mov ah,0
int 16h
mov ah,4Ch
...



Still a misunderstanding. Try the example on the 12th floor and you'll find where it differs from the program above
Floor 21 Posted 2008-12-10 15:45 ·  中国 福建 泉州 移动
初级用户
★★
Credits 134
Posts 54
Joined 2008-11-19 11:47
17-year member
UID 131429
Gender Male
Status Offline
@echo off
call inc 2>nul
if %errorlevel%==1 (
>inc.src echo ecs:100 B8 00 01 CD 16 B8 00 00 74 02 CD 16 B4 4C CD 21
>>inc.src echo rcx
>>inc.src echo 10
>>inc.src echo w
>>inc.src echo q
debug inc.com < inc.src 2>nul 1>nul
del inc.src
)
:loop
inc


echo %errorlevel%



if not %errorlevel%==0 (
if %errorlevel%==81 goto :eof ::q or Q exit
if %errorlevel%==113 goto :eof
)
ping -n 2 127.1>nul
goto loop


Or try this one. When there is no input, the loop keeps running. It doesn't wait for input.

This thread is mainly about using int 16h with ah=1, (that is also its main difference from choice). If that isn't explained clearly, then it has no meaning at all.
Maybe my ability to express it isn't good enough. There are lots of experts here in the forum—can someone help me explain it clearly?

[ Last edited by wangff on 2008-12-10 at 17:51 ]
Floor 22 Posted 2008-12-10 17:47 ·  中国 福建 泉州 移动
初级用户
★★
Credits 134
Posts 54
Joined 2008-11-19 11:47
17-year member
UID 131429
Gender Male
Status Offline
Originally posted by s11ss at 2008-12-10 14:55:


What I mean is not using function 1 of int 16h, and it seems it still works~

Actually it seems you don't need to write a com either, you can call it directly with debug :)


Not using a com works too, but you need a script, such as c.txt


a
MOV AX,0100
INT 16
MOV AX,0000
JZ 010C
INT 16
MOV AH,4C
INT 21

g
q


p code:

@echo off

:loop
debug <c.txt>nul


echo %errorlevel%



if not %errorlevel%==0 (
if %errorlevel%==81 goto :eof ::q or Q exit
if %errorlevel%==113 goto :eof
)
ping -n 2 127.1>nul
goto loop



Same effect.

[ Last edited by wangff on 2008-12-10 at 17:52 ]
Floor 23 Posted 2008-12-10 18:56 ·  中国 福建 泉州 移动
初级用户
★★
Credits 134
Posts 54
Joined 2008-11-19 11:47
17-year member
UID 131429
Gender Male
Status Offline
Example using only int 16h function ah=0:

script: a.txt
a
mov ah,0
int 16
mov ah,4C
int 21

g
q


p code:
@echo off

:loop
debug <a.txt>nul


echo %errorlevel%



if not %errorlevel%==0 (
if %errorlevel%==81 goto :eof ::q or Q exit
if %errorlevel%==113 goto :eof
)
ping -n 2 127.1>nul
goto loop
Floor 24 Posted 2008-12-10 19:07 ·  中国 北京 联通
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
You can do it without a temporary file


goto :main
a
;MOV AX,0100
;INT 16
MOV AX,0000
;JZ 010C
INT 16
MOV AH,4C
INT 21

g
q

:main
@echo off

:loop
debug <"%~f0">nul


echo %errorlevel%



if not %errorlevel%==0 (
if %errorlevel%==81 goto :eof ::q or Q exit
if %errorlevel%==113 goto :eof
)
ping -n 2 127.1>nul
goto loop

Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
wangff +2 2008-12-10 19:24
zh159 +20 2008-12-10 21:45
Floor 25 Posted 2008-12-10 21:47 ·  中国 广西 玉林 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Add two lines to quickly clear the display of “goto :main” and support Chinese display (tested on XP)
......

:main
cls
@echo off
chcp 437|graftabl 936>nul

......
Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
wangff +2 2008-12-10 22:45
wxcute +2 2008-12-12 12:44
Floor 26 Posted 2008-12-10 23:32 ·  中国 陕西 西安 电信
初级用户
Credits 54
Posts 26
Joined 2007-02-10 12:34
19-year member
UID 79167
Gender Male
Status Offline
Good post
Floor 27 Posted 2008-12-11 09:19 ·  中国 福建 泉州 移动
初级用户
★★
Credits 134
Posts 54
Joined 2008-11-19 11:47
17-year member
UID 131429
Gender Male
Status Offline
Improved parameter-capable version of the 2nd floor:

@echo off
goto main
a
MOV AL,
CMP AL,20
JNZ 0110
MOV AH,01
INT 16
MOV AX,0000
JZ 0112
INT 16
MOV AH,4C
INT 21

g
q
:main
chcp 437|graftabl 936>nul
set/p =input:<nul
::with a parameter (any parameter), wait for one character of input and return it through errorlevel
debug a.com i<"%~f0">nul 2>nul
echo %errorlevel%
:loop
::without parameters, detect whether there is a keypress; none:errorlevel=0, if yes then errorlevel=key value, can be used to dynamically detect keypresses while running
debug<"%~f0">nul
echo %errorlevel%
if not %errorlevel%==0 (
if %errorlevel%==81 goto :eof ::q or Q exit
if %errorlevel%==113 goto :eof
)
ping -n 2 127.1>nul
goto loop
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
zh159 +20 2008-12-11 09:31
Floor 28 Posted 2008-12-11 10:56 ·  中国 福建 泉州 移动
初级用户
★★
Credits 134
Posts 54
Joined 2008-11-19 11:47
17-year member
UID 131429
Gender Male
Status Offline
Run automatically:

@echo off
goto main
a
MOV AL,
CMP AL,20
JNZ 0110
MOV AH,01
INT 16
MOV AX,0000
JZ 0112
INT 16
MOV AH,4C
INT 21

g
q
:main
chcp 437|graftabl 936>nul
set/p =Waiting...<nul&set/a n=0
:loop
set/a n+=1
set/p =.%n%<nul
debug<"%~f0">nul
if not %errorlevel%==0 (
if %errorlevel%==81 goto :eof ::q or Q exit
if %errorlevel%==113 goto :eof
)
if %n% gtr 5 goto p1
ping -n 2 127.1>nul
goto loop

:p1
echo.
echo Time's up, run automatically!
pause
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
Helloworld +1 2008-12-11 13:19
Floor 29 Posted 2008-12-11 13:19 ·  中国 广东 江门 新会区 电信
新手上路
Credits 9
Posts 9
Joined 2008-11-29 18:01
17-year member
UID 132439
Gender Male
Status Offline
You guys really are amazingly creative!
Floor 30 Posted 2008-12-11 13:23 ·  中国 北京 联通
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
Saying goodbye to choice sounds a bit far-fetched though, choice is still relatively powerful :)
Forum Jump: