|
-
Nov 19th, 2006, 10:32 AM
#1
Thread Starter
New Member
[RESOLVED] One little glitch
Hi, I am new to this forum and needing some help from the gurus. I am sure this will be an easy one. I am studying assembly for the first time and I need some help with an assignment, which is working fine except for 1 thing. This assignment has a main program and a subprogram. The main is TestYes and the subprog is YesNo. The problem is when the user enters a character other than y/Y or n/N the program goes to "(Y or N)?"... which is GOOD, that's ok so far. But, coming out of that with an n/N directs the program to "Do you want to continue (Y or N)? instead of "Really Stop".
Anyway, like I said, I am pretty green as far as assembly language is concerned and I am probably overwriting alot of code, but that's just where we are in the book/process, so bear with me there, since we have just left learning about jumps and moving on to subprograms now. The codes for each are below. Thanks.
MLB
;;YesNo.asm
INCLUDE PCMAC.INC
.MODEL SMALL
.586
.STACK 100h
.DATA
Prompt1 DB '(Y or N)? $'
Prompt2 DB 13, 10, '$'
.CODE
EXTRN PutDec: Near
PUBLIC YesNo
YesNo PROC
_Begin
_PutStr Prompt1 ;Prompt to enter y or n
_GetCh
mov bl, al
_PutStr Prompt2
cmp bl, 121 ;ascii for 'y'
je ItsaY ;positive for a y/Y
cmp bl, 89
je ItsaY ;positive for a y/Y
cmp bl, 110 ;ascii for 'n'
je ItsaN ;positive for n/N
cmp bl, 78 ;ascii for'N'
je ItsaN ;positive for n/N
call YesNo ;Start over
ItsaY:
mov bx, 1 ;makes bx = 1
ret
ItsaN:
mov bx, 0 ;makes bx = 0
ret
YesNo ENDP
END YesNo
Subprogram....
;;TestYes.asm
INCLUDE PCMAC.INC
.MODEL SMALL
.586
.STACK 100h
.DATA
Prompt1 DB 'Do you want to continue $'
Prompt2 DB 'Really Stop $'
Prompt3 DB 13, 10, 'Done $'
Prompt4 DB 13, 10, '$'
.CODE
EXTRN YesNo : Near
PUBLIC testyes
TestYes PROC
_Begin
_PutStr Prompt1
call YesNo
cmp bx, 0
jne EntryofY
_PutStr Prompt2
_GetCh
mov bl, al
cmp bl, 121 ;equals y
je EntryofN ;done
cmp bl, 89 ;equals y
je EntryofN ;done
_PutStr Prompt4
call TestYes
EntryofY:
call TestYes
EntryofN:
_PutStr Prompt3
jmp Finish
Finish:
_Exit
TestYes ENDP
END TestYes
-
Nov 23rd, 2006, 05:03 PM
#2
Member
Re: One little glitch
If you are studying assembly for the first time, why are you using this macro stuff? Why are you studying 16 bit assembly? Go for win32 assembly instead or 64 bit assembly.
OK, I can't really follow your code since I don't know the macros you are using. I have tryed to write it in pure asm code instead. Perhaps you can solve your problem this way.
Code:
.model small
assume cs:cseg, ds:dseg, ss:sseg
; data
dseg segment byte
Prompt1 db '(Y or N)? $'
Prompt2 db 13, 10, '$'
Prompt11 DB 'Do you want to continue $'
Prompt12 DB 'Really Stop $'
Prompt13 DB 13, 10, 'Done $'
Prompt14 DB 13, 10, '$'
dseg ends
; stack
sseg segment stack
db 100h dup(?)
sseg ends
; code
cseg segment
start:
YesNo:
; _Begin
; _PutStr Prompt1 '(Y or N)? $'
mov ax, dseg
mov ds, ax
mov dx, offset Prompt1
mov ah, 09h
int 21h
; _GetCh
mov ah, 01h
int 21h
mov bl, al
; _PutStr Prompt2 13, 10, '$'
mov ax, dseg
mov ds, ax
mov dx, offset Prompt2 ;new line
mov ah, 09h
int 21h
cmp bl, 121 ;ascii for 'y'
je ItsaY ;positive for a y/Y
cmp bl, 89
je ItsaY ;positive for a y/Y
cmp bl, 110 ;ascii for 'n'
je ItsaN ;positive for n/N
cmp bl, 78 ;ascii for'N'
je ItsaN ;positive for n/N
ItsaY:
mov bx, 1 ;makes bx = 1
jmp @F
ItsaN:
mov bx, 0 ;makes bx = 0
@@:
TestYes:
; _Begin
cmp bx, 1
jne EntryofN
; _PutStr Prompt11 'Do you want to continue $'
mov ax, dseg
mov ds, ax
mov dx, offset Prompt11
mov ah, 09h
int 21h
jmp YesNo
EntryofN:
; _PutStr Prompt12 'Really Stop $'
mov ax, dseg
mov ds, ax
mov dx, offset Prompt12
mov ah, 09h
int 21h
; _PutStr Prompt1 '(Y or N)? $'debu
mov ax, dseg
mov ds, ax
mov dx, offset Prompt1
mov ah, 09h
int 21h
; _GetCh
mov ah, 01h
int 21h
mov bl, al
; _PutStr Prompt14 13, 10, '$'
mov ax, dseg
mov ds, ax
mov dx, offset Prompt14
mov ah, 09h
int 21h
cmp bl, 121 ;equals Y
je @F
cmp bl, 89 ;equals y
je @F
jmp YesNo
@@:
; _PutStr Prompt13 13, 10, 'Done $'
mov ax, dseg
mov ds, ax
mov dx, offset Prompt13
mov ah, 09h
int 21h
mov ax, 4C00h ;exit to dos
int 21h
;Finish:
; _Exit
cseg ends
end start
-
Nov 24th, 2006, 06:37 PM
#3
Thread Starter
New Member
Re: One little glitch
Thanks, I got it to work by adding a dx value pretty much like you did. Cool...
mlb
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|