Stack Segment
- From: "Ted" <spamtrap@xxxxxxxxxx>
- Date: Thu, 31 Mar 2005 03:34:18 +0000 (UTC)
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.
.
- Follow-Ups:
- Re: Stack Segment
- From: repete
- Re: Stack Segment
- From: spamtrap
- Re: Stack Segment
- Prev by Date: Re: Emulating DOS/x86 Protected Mode: AIIEE! THE TENTACLES!
- Next by Date: Re: Stack Segment
- Previous by thread: Re: Emulating DOS/x86 Protected Mode: AIIEE! THE TENTACLES!
- Next by thread: Re: Stack Segment
- Index(es):
Relevant Pages
|