Stack Segment



Hello--

I'm trying to write a 16-bit DOS console app with MASM32 that converts
a decimal to binary for me. It seems I need a STACK segment for the
16-bit to work, however, but when I put .stack, it doesn't seem to
work. I'm using ml.exe to assemble and Microsoft's 16-bit linker to
link. Here's the code:

; Converts a decimal digit input to binary and then display it
;
«««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
..model small
..486
option casemap:none
;
«««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
..stack
db 1024 dup ("?") ;default stack is 1k...I NEED HELP HERE
;
«««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
..data
DIGIT_MESS db "Type one decimal digit: $",0
BINARY_MESS db 0AH,0DH,"Binary value us: $",0
;
«««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
..code
START:
;Display message stored in the data segment using DOS service #9,
INT 21H.
;The message must end in a $ sign
lea dx,DIGIT_MESS ;set dx to message test
mov ah,9 ;service request number
int 21h ;transfer control to MS-DOS
;The program uses service number 0, INT 16H to wait until a key is
pressed
;This service has no entry requirement
mov ah,0 ;service request number
int 16h ;transfer control to BIOS
;service number 0 of interrupt 16H returns in AL the ASCII code for
the
;key pressed
;This program assumes the key was a number between 0 and 9
;The ASCII value is converted to binary by subtracting 30H
sub al,30H ;subtract 30h from keystroke
;AL holds the binary value of the user's input. This register is
saved on
;the stack
push ax ;save al in the stack
;Display message
lea dx,BINARY_MESS ;set DX to message text
mov ah,9 ;service request number
int 21h ;transfer control to MS-DOS
pop ax ;recover binary from stack
;Bits are examined from left to right. If the bit is set a 1 is
displayed
;If not, a 0 is displayed
mov ah,al ;bits to AH. AL is needed to hold characters
to be
;be displayed
mov cx,4 ;set up loop counter for 4 bits
TEST_LEFT_BIT:
test ah,00001000b ;test ah bit 3
jnz LEFT_BIT_SET ;jump is taken if bit 3 is set
;At this point, bit 3 is not set. display a 0
mov al,"0" ;character to be displayed
call TTY ;local procedure to display
jmp NEXT_BIT ;go to shift and continue
LEFT_BIT_SET:
mov al,"1" ;character to be displayed
call TTY ;local procedure to display
NEXT_BIT:
shl ah,1 ;bits in ah are shifted left one position
loop TEST_LEFT_BIT ;continue until CX=0
;Exit to DOS
DOS_EXIT:
mov ah,76 ;DOS service request code
mov al,0 ;No error code returned
int 21h ;exit to DOS
;
-------------------------------------------------------------------------
;Procedures...
TTY PROC NEAR
;local procedure to display a character using BIOS teleype
service 14, int 10h
;on entry: AL=ASCII character to be displayed
;on exit: nothing...AX is preserved
push ax ;save AX in stack
mov ah,14 ;service request number
mov bx,0 ;display page is usually 0
int 10h ;BIOS video service interrupt
pop ax ;restore AX from stack
ret ;end procedure
TTY ENDP
end START
;
«««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

I assemble w/ the following line:
ml /c /Bl /IC:\masm32\include convert.asm

Anyone know why the lines in the .stack segment aren't being
recognized, if this is even the problem?

Thanks a lot.

.



Relevant Pages

  • Re: A Brief Look at History
    ... Get an xt, display its name, display the stack, wait for a keystroke. ... bottom of its command window. ... I remember a Forth that put that in a vertical window that covered up ...
    (comp.lang.forth)
  • Re: A Brief Look at History
    ... separate window and show whenever it got updated. ... and work out how to debug it, you design the Forth animator and then ... and return stack, in a stack of views of in unsigned, signed and, if ... merrily around the source code display screen. ...
    (comp.lang.forth)
  • Re: Just started ASM...
    ... The simplest Windows program I know of uses the stack to pass parameters... ... You might want to learn how the stack works, how "call" and "ret" work, *before* you have to use 'em to access your OS. ... I'd agree that it isn't worth spending a lot of time learning the complete workings of dos. ... File I/O routines can be used to get/print from/to the keyboard/screen, as well as disk files - might want to learn them. ...
    (alt.lang.asm)
  • Re: Detailed Stack Information Patch [1/3]
    ... +#ifdef CONFIG_PROC_STACK ... the whole "display where the stack is" thing is ...
    (Linux-Kernel)
  • Re: CAsyncSocket behaving multithreaded
    ... > Examine the debugger stack display when the unexpected OnReceive is hit. ... > an access violation or assert error, ... the unpredictable CAsyncSocket. ...
    (microsoft.public.vc.mfc)