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

In principal you have the idea. If you plan on doing a lot of ASM, you may want to consider this example. This is a generic input routine not unlike function 10 in INT 21H. Even though 64 bit Linux, the principal is the same not matter the platform.

Here I have three simple conditions;

  • Did operator enter anything? ZF = 1
  • Is there room for another entry in buffer? RCX = 0
  • Did this entry overflow buffer? SF = 1

Now you have the opportunity to handle different combinations of condition handling, that might be an error, as a null entry is not always a problem, especially if your program ask for e-mail address and the person doesn't have one.

  00:   55                      push   rbp
  01:   48 89 e5                mov    rbp, rsp

  04:   57                      push   rdi
  05:   56                      push   rsi
  06:   52                      push   rdx
  07:   51                      push   rcx

        This is like function 10 of INT 21

  08:   8b 55 18                mov    edx, [rbp+0x18]  Maximum characters
  0b:   48 8b 75 10             mov    rsi, [rbp+0x10]  Pointer to input buffer
  0f:   31 c0                   xor    eax, eax         like mov ax, 0x0a
  11:   89 c7                   mov    edi, eax
  13:   0f 05                   syscall                 like INT 21

        Where all the calculattion is done

  15:   29 c2                   sub    edx, eax
  17:   89 55 18                mov    [rbp+0x18], edx
  1a:   ff c8                   dec    eax
  1c:   50                      push   rax
  1d:   48 89 f7                mov    rdi, rsi
  20:   48 01 c7                add    rdi, rax
  23:   b0 00                   mov    al, 0x0
  25:   80 3f 0a                cmp    [rdi], LF
  28:   74 09                   je     33

  2a:   48 ff c7                inc    rdi
  2d:   58                      pop    rax
  2e:   48 f7 d8                neg    rax
  31:   eb 04                   jmp    37

  33:   aa                      stosb
  34:   58                      pop    rax
  35:   09 c0                   or     eax, eax

  37:   48 89 7d 10             mov    [rbp+0x10], rdi

  3b:   59                      pop    rcx
  3c:   5a                      pop    rdx
  3d:   5e                      pop    rsi
  3e:   5f                      pop    rdi
  3f:   c9                      leave  
  40:   c3                      ret    

This is an example of how I would handle buffer overflow.

.Again:
    call    GetS
    jl  .Exit
    cmp word [rsp+8], 0
    jnz .Again
.Exit

If you like, I could show you how this works in detail in Linux, but to the user it would look exactly as your example, but with the flexibility condition handling not being in input function.

uhmm i am sorry but i do not understand your code. i only understand assembly in a very basic manner, and only understand TASM.

anyway i was able to find out how to fix my problem of error handling.
but i want the userinput to be only letters. however the letters from capital and small letters have characters in between.
how could i address them?

here is the part of the code:

          cmp [SINPUT+2], 41h           ;because 21h starts characters
          JS Erroring               ; jump if something below 21h is entered

          jmp Prnt                  ; skip error and print user entered value     

however this allows all characters starting from letter A how could make it from
A-Z and a-z only ?

sorry for double post ...
and thanks for your reply

Usually it's better to catch input character by character when only a subset is required, especially a case the caps only

    push    dx
GetCh:
    mov     al, 1
    int     21H
    cmp     al, 13      ; Carriage return
    jz      Done

    and     al, 5FH ; Convert to upper case
    cmp     al, 'A'
    jb      Error
    cmp     al, 'Z'
    ja      Error

    mov     dx, al
    inc     dx
    jmp     GetCh

Error:
    ; Put whatever message you want in here
    jmp     Exit

Done:
    mov     dx, '$'     ; That way contents of DX can be printed
    pop     dx          ; Point to beginning of buffer again
    ; Code to print would go here

Exit:
    mov     ah, 4CH
    int     21H

This is kind of an example. It's been 31 yrs since I've used DOS, so I'm digging pretty deep. An alternate way is once done, scan through the entire buffer pointed to by DX, but that's kind of unconventional.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.