WinAsm Studio, The Assembly IDE - Free Downloads, Source Code
Sponsors
Articles
Programming Quick Start
32-bit Assembler is Easy
Porting Iczelion tutorials
What is FASM
Hard Drive Recovery
Wiring your own LAN
Personal menu
Welcome Guest
User:
Pass:
Register!
Resend Validation Email
 
Forum
 

Return value to command prompt, how do you guys a return a value from assembly code to DOS command prompt?

guyenWinasm
Quote Post


Active Member
***

Group: Members
Posts: 47
Member No.: 1386
Joined: 22-July 05


Hi,

How do you guys a return a value from assembly code to DOS command prompt?

I know it must terminate by int 21h (4ch) but i needed to return exit status code so that it can be used by the DOS ERRORLEVEL script function.

I tried putting the exit code in AL as like following:

mov ax, 4c00h
int 21h

or

mo ax 4c01h
int 21h

But errorlevel does not seem to be capturing the exit value.
Thanks!
PMEmail Poster
Top
shoorick
Quote Post


Extremely Active Member
******

Group: Admins
Posts: 2301
Member No.: 160
Joined: 22-June 04


give us more info: how do you run application and how do you check errorlevel. there are situations when errorlevel may be lost, say, if you call command interpereter to run application, you will get success - it means cmd or command.com was executed sucessfully not depending on return of target application.

regards!
PMEmail PosterUsers Website
Top
guyenWinasm
Quote Post


Active Member
***

Group: Members
Posts: 47
Member No.: 1386
Joined: 22-July 05


hi shoorick
my batch files something looks like below. The script is running from MSDOS real mode and would call test.exe. Test.exe will simply return whatever the parameter on the command line typed on the (2 in this example). Source code is pasted after the batch file content. I thought the script will capture that returned value at errorlevel 2 and goto err2 label. That is my expectation.

I know the errorlevel statements are correct because if I replace test.exe 2 call with choice /c:1234 menu than it correctly captures the keyboard input and goes to the correct label.
Thanks!

===========
batch file content
===========

test.exe 2
if errorlevel 4 goto err4
if errorlevel 3 goto err3
if errorlevel 2 goto err2
if errorlevel 1 goto err1

:err4
:goto end

:err3
:goto end

:err2
:goto end

:err1
:goto end

:end

===========
test.exe source.
===========

ASSUME CS:CODE, DS:DATA, SS:STACK, ES:NOTHING
Main PROC NEAR

; Initialize segment registers.

mov ax, ds
mov es, ax ; (ES) = save PSP in ES.

mov ax, DATA
mov ds, ax
ASSUME DS:DATA

mov ax, STACK
mov ss, ax
ASSUME SS:STACK

; Grab a command line switch from PSP.

mov bp, 82h
mov al, byte ptr es:[bp]
mov ah, 04ch ; (AH) = terminate process fcn code.
int 21h
ret
Main ENDP
PMEmail Poster
Top
guyenWinasm
Quote Post


Active Member
***

Group: Members
Posts: 47
Member No.: 1386
Joined: 22-July 05


ok guys i finally got it working, somehow the return value was being lost for some reason. dO YOU see what the problem in hte above code is? Thanks!
PMEmail Poster
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

Topic Options Reply to this topicStart new topicStart Poll

 

Sponsors
Computer Science

Internet
C/C++
Hardware & PC maintenance

HiEditor

General Discussions
Suggestions/Bug Reports
WinAsm Studio

General Discussions
Suggestions/Bug Reports
WinAsm Studio FAQ
Multilingual User Interface
Add-Ins
Assembly Programming

Main
Newbies
Projects
Custom Controls
Snippets
Announcements & Rules

Announcements

General

Online Degrees - Distance Learning
The Heap
Russian
Google