3 Replies - 1398 Views - Last Post: 30 June 2012 - 06:56 AM

#1 minsu44  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 29-June 11

Error handling for null input[question]

Posted 30 June 2012 - 03:52 AM

Well this is not so much of a need, but i really want to learn how to do error handling assembly language[TASM]
Basically if the user just types or presses enter the code will go back to the same question with probably a message box or writing stating that they must put at least one letter.

Example:
Enter string: (user just presses enter)
(message box or ill just print error message)[cuz im not sure if there is message box in ASM or not haha]
Enter string: A [this is still considered string so its accepted]
you entered: A

         TITLE error handling
         DOSSEG
         .model SMALL
         .stack 100h
         .data

PINPUT   db "Enter String: $"
SINPUT   db 14 dup("$")
CRLF     db 13,10,"$"
PENTER   db "You Entered: $"
UERROR   db "Error must enter something! $"
         .code

BEGIN:    mov ax, @data
          mov ds, ax
          mov es, ax
		  

          mov al, 03h    		 		; clear screen
          mov ah, 00h
          int 10h

		 
names:	  mov dx, OFFSET PINPUT			; Print Enter String: 
          mov ah, 09h					; DOS screen output function call
          int 21h						; universal DOS function call
		  
		
          mov byte ptr SINPUT, 11
          mov dx, OFFSET SINPUT			; scan Input	
          mov ah, 0Ah 					
		  int 21h


		  cmp SINPUT, 21h			;because 21h starts characters
		  jl Erroring				; jump if something below 21h is entered
		  
		  jmp Prnt					; skip error and print user entered value
		  
Erroring: 
		  mov dx, OFFSET UERROR 		; print error message
          mov ah, 09h
          int 21h
		  
		  mov dx, OFFSET CRLF 			; print \n
          mov ah, 09h
          int 21h
		  
		  jmp names
		  
Prnt:     
		  mov dx, OFFSET CRLF 			; print \n
          mov ah, 09h
          int 21h
		  
		  mov dx, OFFSET PENTER			; print You entered:
          mov ah, 09h
          int 21h		 		  
		 
		  
		  mov SI, 0002
          lea DX, SINPUT[SI]  			; Print string entered
          mov ah, 09h
		  int 21h
		  
		
          mov ah, 4ch
          int 21h
          end BEGIN



Is This A Good Question/Topic? 0
  • +

Replies To: Error handling for null input[question]

#2 minsu44  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 29-June 11

Re: Error handling for null input[question]

Posted 30 June 2012 - 04:22 AM

i seriously think i dont know how to use CMP and jump functions.
i know my error lies in there. could some one help?

thank you for reading :flowers:
Was This Post Helpful? 0
  • +
  • -

#3 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,279
  • Joined: 28-March 11

Re: Error handling for null input[question]

Posted 30 June 2012 - 06:20 AM

Well, your not going to have a message box like in windows. Your using DOS and that is outdated and doesn't have the "cool" features of windows. You could create your own window or something.

Where is the code I showed you? It returns the string entered length. If that is zero, do your stuff for missing input.

What is this cmp SINPUT, 21h? That is saying is the address of SINPUT the same as 33. The length of the string entered is at [SINPUT + 1]

Do you want the BOX, or whats in the [BOX] ?
Was This Post Helpful? 0
  • +
  • -

#4 minsu44  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 29-June 11

Re: Error handling for null input[question]

Posted 30 June 2012 - 06:56 AM

yes yes i re read things and stuff even from your previous example. And i was able to make it work.

but unfortunately i encountered a new problem
[code]
cmp [SINPUT+2], 41h ; Because 41h starts letters
JS Erroring ; Jump if something below 41h

jmp ScnID ; Skip Erroring

View Postminsu44, on 30 June 2012 - 06:54 AM, said:

yes yes i re read things and stuff even from your previous example. And i was able to make it work.

but unfortunately i encountered a new problem
[code]
cmp [SINPUT+2], 41h ; Because 41h starts letters
JS Erroring ; Jump if something below 41h

jmp ScnID ; Skip Erroring



gahh i accidentally pressed enter
anyway its not jmp SCNID (thats from my other code)
its supposedly jmp Prnt

and it works !
but the problem is there are some characters between capital and small letters which i dont know how to handle, may you guide or give a tip?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1