ClioSport.net

Register a free account today to become a member!
Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

  • When you purchase through links on our site, we may earn an affiliate commission. Read more here.

any good assembly programmers on here?



  Cam'd Arctic FF 182
I did a module in it last year at Uni, can't say I'm an expert but I might be able to help you with some basic stuff :)
 
  185lb/ft dCi
a couple of questions...

when using a dos function 08h to be exact (take input character without echo), when the user inputs a character, does it automatically get stored on the stack?

also when popping off the stack, what is the default location the value will be stored in?

How do you address a certain string in memory, as i'm wanting to compare a string already declared with input the user gives, but I have to do it character by character so I need to know how to offset to the exact character in the string.

any help would be greatly appreciated!
 

sn00p

ClioSport Club Member
  A blue one.
Int 21 returns the scan code in register AL.

There is no default "pop" location on 80x86, it's not an accumulator style instruction set, you need to explicitly say where you want to pop the value to.

PUSH 20
POP AX

would put the value 20 into AX via the stack.

And your final question I have no idea what you're asking, the only way to compare values in memory is byte, word or double word at a time.

Code:
lea si, string_a
lea di, string_b
compare:
mov al, [si]
mov ah, [di]
sub al,ah
jnz different
cmp al,0
je same
inc si
inc di
jmp compare
different:
...
same:
...

Assuming you have zero terminated strings.
 
  185lb/ft dCi
alright mate, thanks for the reply. i'm now at the point of comparison, i am not sure what is the correct syntax. I have my password string, which is HELL, and this will be compared with the users input as to whether they will be granted access or not. So i get the users input then push that onto the stack, i have to take the users 4 characters so if the user inputs HELL, on the stack it will look like LLEH. So therefore I need to be able to address my password correctly so i can compare L with L and so on. Working backwards I know but this is the way I have to do it.

here is the code

Code:
;password.asm
.MODEL SMALL
.STACK 100h
.DATA
    
    pass DB 'HELL','$'
    prompt DB 0Ah, 0Dh,'Enter Password:','$'
    tries DB 'Number of tries left:','$'
    wrongpass DB 'Sorry that was incorrect, please try again','$'
    notriesleft DB 'Sorry, you have used up all your tries','$'
    correct DB 'Correct, access granted','$'


.CODE
    mov ax,@data               ; points to data segment in memory
    mov ds,ax                     ; moves ax to ds register
    mov ah,09h                   ; move print instruction to ah
    mov dx,OFFSET prompt        ; move OFFSET of prompt to dx register
    int 21h                          ; check data segment address then get offset address to display mesg
    
    
    mov ch,3            ; set counter for number of tries

    inputloop:
    
    cmp ch, 0            ; is number of tries value zero?
    je fail                ; if yes jump to end
    
    
    mov cl, 4            ; set counter for number of characters
    
    mov ah,08h            ; take character input without echo function
    int 21h                ; execute input character function
    push ax                ; push inputted character onto stack

    mov ah, 2Ah            ; move asterix(*) into ah
    int 21h                ; display asterix
    dec cl                ; decrement number of characters counter
    cmp cl, 0            ; test to see if user has inputted 4 characters
    je checkpass            ; if 4 characters have been inputted jump to test
    jne inputloop            ; if 4 characters have not been inputted jump back to start of loop


    checkpass:

    dec ch                ; decrement the number of tries counter by 1

    pop bx                ; move inputted character from stack to bx

    cmp [pass+3], bx        ; compare memory location 'L' with value in bx
    jne inputloop            ; if not equal jump back to inputloop start
    
    pop bx                ; move inputted character from stack to bx

    cmp [pass+2], bx        ; compare memory location 'L' with value in bx
    jne inputloop            ; if not equal jump back to inputloop start
    
    pop bx                ; move inputted character from stack to bx

    cmp [pass+1], bx        ; compare memory location 'E' with value in bx
    jne inputloop            ; if not equal jump back to inputloop start    

    pop bx                ; move inputted character from stack to bx

    cmp [pass+0], bx        ; compare memory location 'H' with value in bx
    jne inputloop            ; if not equal jump back to inputloop start
    
    jmp success            ; if all compares match, password is correct, jump to success message

    
    fail:
    mov ah,09h                        ; move dos function display into ah
    mov dx, OFFSET notriesleft    ; move offset of incorrect to dx register
    int 21h                               ; execute function and display fail message
    jmp finish                           ; jump to end of program

    success:                            ; success jump start
    mov ah,09h                         ; move print function into ah
    mov dx, OFFSET correct        ; move message into dx register
    int 21h                               ; execute DOS function to display message


    finish:
    mov ah,4ch            ; end the program
    int 21h                ; same as above
END

any help appreciated
 


Top