Click to See Complete Forum and Search --> : Need help with 16bit assembly code :(


MrDoomMaster
March 29th, 2004, 09:53 AM
Hey guys, for some reason I'm having trouble out of the Scroll Screen (For clearing the screen) function. After the first coding of the scroll screen, the other two crash the program mysteriously. The first one works though.

I have run this executable through DEBUG, yet I found nothing that looked abnormal. If someone could be patient enough to flip through this code and maybe find a problem, I would appreciate it. Thanks guys!

The following code is in 16BIT Conventional assembly format.


PAGE 60,132
TITLE L11RCD (EXE) LAB 11 PROG
;---------------------------------------------------------------------
STACK SEGMENT PARA STACK 'Stack'
DB 32 DUP (0)
STACK ENDS
;---------------------------------------------------------------------
DATASEG SEGMENT PARA 'Data'
INST DB ' THIS IS A TYPING TEST. ON THE NEXT SCREEN THERE WILL BE A SENTENCE',0DH,0AH
DB ' DISPLAYED AT THE TOP. YOU ARE TO TYPE THE SENTENCE EXACTLY AS IT IS',0DH,0AH
DB ' SHOWN, IN ITS ENTIRETY. IF YOU MAKE A MISTAKE YOUR TEST WILL BE',0DH,0AH
DB ' TERMINATED AND YOU WILL FAIL.',0DH,0AH,0AH
DB ' GOOD LUCK',0DH,0AH,0AH
DB ' PRESS ',027H,'ENTER',027H,' WHEN YOU ARE READY TO BEGIN THE TEST.$'

FAIL DB ' YOU HAVE FAILED THE TYPING TEST! PRESS ENTER TO TRY AGAIN, OR ESC TO EXIT$'

SUCES DB ' CONGRATULATIONS! YOU HAVE PASSED THE TEST!',0DH,0AH
DB ' PRESS ENTER TO TRY AGAIN, OR ESC TO EXIT$'

SENT DB 15 DUP (020H),0DAH,44 DUP (0C4H),0BFH,0DH,0AH
DB 15 DUP (020H),0B3H,'The quick brown fox jumps over the lazy dog.',0B3H,0DH,0AH
DB 15 DUP (020H),0C0H,44 DUP (0C4H),0D9H,'$'

ANSW DB 'The quick brown fox jumps over the lazy dog.'
ANSC DB 0H
TEMP DB ?

DATASEG ENDS
;---------------------------------------------------------------------
;---------------------------------------------------------------------
CODESEG SEGMENT PARA 'Code'
MAIN PROC FAR
ASSUME SS:STACK,DS:DATASEG,CS:CODESEG
MOV AX,DATASEG
MOV DS,AX
MOV ES,AX

MOV AX,0003H
INT 10H ;SET RESOLUTION

MOV AH,02H
MOV BH,00H
MOV DH,08H
MOV DL,00H
INT 10H ;POSITION CURSOR FOR PROGRAM INSTRUCTIONS

MOV AH,09H
LEA DX,[INST]
INT 21H ;DISPLAY INSTRUCTIONS

;---------------
ENTERK: MOV AH,10H
INT 16H ;REQUEST SINGLE INPUT

CMP AL,0DH ;CHECK IF ENTER WAS PRESSED
JNE ENTERK ;IF NOT, REQUEST INPUT UNTIL TRUE
;---------------

MOV AX,0700H
MOV CX,0000H
MOV BH,07H
MOV DX,184FH
INT 10H ;SCROLL SCREEN::CLEAR

MOV AH,02H
MOV BH,00H
MOV DH,05H
MOV DL,00H
INT 10H ;POSITION CURSOR FOR SENTENCE

MOV AH,09H
LEA DX,[SENT]
INT 21H ;DISPLAY SENTENCE TO TYPE

MOV AH,02H
MOV BH,00H
MOV DH,09H
MOV DL,10H
INT 10H ;POSITION CURSOR FOR INPUT

MOV BX,0H ;SET STRING OFFSET COUNTER TO 0
CALL ILOOP

MOV AX,4C00H
INT 21H
MAIN ENDP
;---------------------------------------------------------------------
; INPUT LOOP FOR SENTENCE
;---------------------------------------------------------------------
ILOOP PROC NEAR
MOV AH,0CH
MOV AL,01H
INT 21H ;REQUEST INPUT OF SINGLE CHARACTER
MOV TEMP,AL

LEA DI,[TEMP]
LEA SI,[ANSW+BX] ;CHECK IF INPUT CHARACTER MATCHES THAT IN THE CORRECT SENTENCE
CMPSB
JNE IERROR ;IF NOT, THEN JUMP TO IERROR PROCEEDURE

INC BX ;INCREMENT STRING OFFSET

CMP BX,02CH ;CHECK IF END OF INPUT STRING
JNE ILOOP ;IF NOT, THEN REPEAT THIS PROCEEDURE

MOV AX,0700H
MOV CX,0000H
MOV BH,07H
MOV DX,184FH
INT 10H ;SCROLL SCREEN::CLEAR

MOV AH,02H
MOV BH,00H
MOV DH,08H
MOV DL,00H
INT 10H ;POSITION CURSOR FOR SENTENCE

MOV AH,09H
LEA DX,[SUCES]
INT 21H ;DISPLAY SUCCESS MESSAGE

MOV AH,01H
MOV CX,0100H
INT 10H ;HIDE CURSOR

EXIT3: MOV AH,10H
INT 16H ;REQUEST SINGLE INPUT

CMP AL,0DH ;CHECK IF ENTER WAS PRESSED
JE MAIN ;IF TRUE, REPEAT ENTIRE PROGRAM
CMP AH,01BH ;CHECK IF ESC KEY PRESSED
JNE EXIT3 ;IF FALSE, INPUT AGAIN UNTIL ENTER/ESC PRESSED

MOV AX,4C00H
INT 21H ;PROGRAM TERMINATION
ILOOP ENDP
;---------------------------------------------------------------------
; IF INPUT INCORRECT, THIS PROCEEDURE IS EXECUTED
;---------------------------------------------------------------------
IERROR PROC NEAR
MOV AX,0700H
MOV CX,0000H
MOV BH,07H
MOV DX,184FH
INT 10H ;SCROLL SCREEN::CLEAR

MOV AH,02H
MOV BH,00H
MOV DH,08H
MOV DL,00H
INT 10H ;POSITION CURSOR FOR SENTENCE

MOV AH,09H
LEA DX,[FAIL]
INT 21H ;DISPLAY FAILURE MESSAGE

MOV AH,01H
MOV CX,0100H
INT 10H ;HIDE CURSOR

EXIT1: MOV AH,10H
INT 16H ;REQUEST SINGLE INPUT

CMP AL,0DH ;CHECK IF ENTER WAS PRESSED
JE MAIN ;IF TRUE, REPEAT ENTIRE PROGRAM
CMP AH,01BH ;CHECK IF ESC KEY WAS PRESSED
JNE EXIT1 ;IF NOT, REQUEST INPUT UNTIL ENTER OR ESC PRESSED

MOV AX,4C00H
INT 21H ;PROGRAM TERMINATION
IERROR ENDP
;---------------------------------------------------------------------
CODESEG ENDS
END MAIN

Sam Hobbs
March 29th, 2004, 05:14 PM
If you are programming in assembler, you must know how to use the debugger. You need to be familiar with the call stack and how to use it for debugging. You need to know how to determine where in your code an error occurs. You must know how to single-step through the code.

When answering questions, we are frequently frustrated by people saying things like "crash the program" without details.

MrDoomMaster
March 29th, 2004, 09:43 PM
I think I knew all of this. Anyone else care to lecture me?

I know how to use debugger, and because I am human I fail to be perfect and recognize EVERY error. I realize my code is lengthy but there are a few people out there willing to actually help me out with a solution rather than lecture me to death about "how to do it right".

I don't mean to be rude but I'm a bit frustrated when I get lectured. So, nothing personal.

Anyway forget the program, don't need help anymore. Thanks everyone for at least trying to help :)

Sam Hobbs
March 29th, 2004, 09:57 PM
I am confident that most people here that could help would say that you need to say more than "crash the program mysteriously"; especially the "mysteriously" part. Most people here that could help would say that you need to be able to be more clear about where the problem is.

Of course, up to this point, everyone else has ignored this thread, and you seem to be saying you would prefer that than to be provided with feedback about what you need to provide us with to get help.

Sam Hobbs
March 29th, 2004, 10:39 PM
From MAIN, you call ILOOP. At the bottom of ILOOP is a jump (JE) to MAIN; I don't see a return. As best as I can remember, that will be a problem eventually. I don't know if it is the problem but it probably is a problem. There might be similar problems elsewhere.