RhetoricalRuvim said:
I have to see your code first. We're not supposed to do homework for people on this forum (I posted the .com file to show that it is possible). If you need help with coding it, we'll try to help, but it might not help you too much, unless you try it yourself.
I could, however, tell you how the program I made works.
It has three functions: puts(), gets(), and strcmp();
puts() does something like this:
step 1: take the address of the string, passed to puts() as a parameter, and store it in a register
step 2: get a byte from the memory location of the address from that register
step 3: compare that byte to 0 (0, not '0')
step 4: if it is 0, go to step 7
step 5: output that byte to the screen using int 21h ah= 2
step 6: increment the register with the memory address and go to step 2
step 7: return
gets() does something like this:
step 1: take the function parameter (the address of the string to write to) and store it in two registers (one for pointing and one for checking the other)
step 2: input a character from the keyboard using int 21h ah= 1
step 3: compare that character to 13 (return character)
step 4: if it is equal, go to step 12
step 5: compare that character to 8 (backspace character)
step 6: if it is not equal, go to step 10
step 7: compare the register with the pointer to the other register with the address of the string to write to
step 8: if greater than, decrement the register with the pointer
step 9: go to step 2
step 10: move that character to the memory location at the address pointed to by the register with the address of the string
step 11: increment the pointer register and go to step 2
step 12: return from the function
strcmp() works something like this:
step 1: get the address of the first string and put it into a register
step 2: get the address of the second string and put it into a register
step 3: move a byte from the memory location at the address pointed to by the register with the first-string address to a register
step 4: compare that byte to 0, and if equal then go to step 10
step 5: subtract the byte at the memory location at the address pointed to by the register with the second-string address from the register with the byte from step 3
step 6: if not zero (the JNZ instruction), go to step 9
step 7: increment both registers that contain the pointers to the strings
step 8: go to step 3
step 9: return whatever's in the register that you just subtracted from
step 10: return 0
These steps do not exactly match the actual code from the program I made, but this is very close.
I think you can figure out the parts of the program that call these functions.
Once again, if you need help figuring these steps out or if something's wrong with your code, you can post on this forum and ask about it.
Edit: By the way, I forgot to include a step in the .com file I posted earlier; I re-uploaded the .zip folder to the earlier post. The thing I forgot to include, earlier - in the .com file - , is the part from steps 7 and 8 of the gets() function. So yeah, I forget things too.
.model small
.stack 100h
.data
promptmsg db 0ah, 0dh,'Enter Pin Code: $'
promptvalid db 0ah, 0dh,'Pin Code Accepted!$'
promptinvalid db 0ah, 0dh,'Pin Code Incorrect!$'
prompttimeout db 0ah, 0dh,'3rd attempt..Session terminated!$'
promptretry db 0ah, 0dh,'Do you want to try again? [ y / n ]: $'
.code
main proc
mov cx, 3 ;initialize counters of 3
start:
mov ax,@data ;initialize data
mov ds, ax
lea dx, promptmsg ;display data
call endpar
call readfirst ;read 1st digit input
call readsecond ;read 2nd digit input
call readthird ;read 3rd digit input
call readfourth ;read 4th digit input
call readfifth ;read 5th digit input
cmp bh, 49 ;compare BH to Decimal Number 1
je second ;if compare is equal to 1 then goto second
jne invalid ;if compare is not equal to 1 then goto invalid
second:
cmp ch, 50 ;compare BH to Decimal Number 2
je third ;if compare is equal to 2 then goto third
jne invalid ;if compare is not equal to 2 then goto invalid
third:
cmp dh, 51 ;compare DH to Decimal Number 3
je fourth ;if compare is equal to 3 then goto fourth
jne invalid ;if compare is not equal to 3 then goto invalid
fourth:
cmp bl, 52 ;compare BL to Decimal Number 4
je fifth ;if compare is equal to 4 then goto fifth
jne invalid ;if compare is not equal to 4 then goto invalid
fifth:
cmp cl, 53 ;compare CL to Decimal Number 5
je accepted ;if compare is equal to 5 then goto accepted
jne invalid ;if compare is not equal to 5 then goto invalid
invalid:
lea dx, promptinvalid ;print pincode is not correct
call endpar
jmp exit
retry:
dec cx ;decrement counter CX
je timeout ;if CX is equal to zero, read attempt aborted
lea dx, promptretry ;print retry statement
call endpar
mov ah, 1 ;read input data
int 21h
mov bh, al ;save AL to BH
cmp bh, 121 ; if user keyboard press small letter 'y' key
je start
jmp exit
timeout:
lea dx, prompttimeout ;print session terminated
call endpar
jmp exit
accepted:
lea dx, promptvalid ;print pincode is correct
call endpar
jmp exit
endpar:
mov ah, 9
int 21h
ret
readfirst:
mov ah,1 ;read input
int 21h
mov bh,al ;save 1st AL to BH register
ret
readsecond:
mov ah,1 ;read input
int 21h
mov ch,al ;save 2nd AL to CH register
ret
readthird:
mov ah,1 ;read input
int 21h
mov dh,al ;save 3rd AL to DH register
ret
readfourth:
mov ah,1 ;read input
int 21h
mov bl,al ;save 4th AL to BL register
ret
readfifth:
mov ah,1 ;read input
int 21h
mov cl,al ;save 5th AL to CL register
ret
exit:
mov ah, 4ch ;exit DOS
int 21h
main endp
end main
Im having a problem with this codes, just because it does not meet the thrice attempt..it should exit the program if the 3rd attempt to input pass is wrong..