Reputation: 897 Master
- Active Posts:
- 2,469 (1.69 per day)
- 28-March 11
- Profile Views:
- Last Active:
- 25 minutes ago
- Viewing Board Index
- OS Preference:
- Favorite Browser:
- Favorite Processor:
- Favorite Gaming Platform:
- Your Car:
- Who Cares
- Dream Kudos:
- Expert In:
Posts I've Made
Posted 25 Mar 2015
QuoteThe program works fine
No, you cannot say it works fine if there are issues with it.
Let me see if I understand what you want to do. You want to take the user input until the carriage return is pressed, and store each character entered? Then, loop through each character of the entered password, and the password that is hard coded into the program and see if they are the same?
I need to ask, why are you learning ancient 16 bit DOS Assembly?
Also, please learn to comment your code!
Let's walk through your code and see what is going on...
15 MOV AH, 01H
16 INT 21H
18 CMP AL, 13
19 JE END_INPUT
21 MOV [SI], AL
22 ADD SI, 1
23 JMP INPUT
I am not going to check to see if this is the correct interrupt for this task, I will take your word for it.
So, you get a character typed and check to see if it is a return, if it is, we jump to end_input. If it is not, then we move this character into a buffer pointer to by si and then increment this pointer by 1. WAIT!!!! You have not initialized si with a pointer to a buffer! I am surprised your program did not bomb here.
Explain what you are doing here:
26 ADD SI, 1
27 MOV [SI], 24H
28 MOV SI, 0
What you think it is doing and what it is doing are 2 different things.
What it is doing is:
On line 26, you are incrementing the imaginary pointer.
On line 27 you are moving the $ character into the end of this buffer pointed to by si.
On line 28, you basically zeroed out the pointer.
Look at this:
28 MOV SI, 0
31 MOV AL, PASSWORD[SI]
32 CMP AL, [SI]
Look at it very carefully. Out loud, say to yourself what the code is doing.
On line 28 I am zeroing out si
On line 31, I am taking a character from the PASSWORD array indexed by si
On line 32, I am comparing that character in al, with whatever pointer is in si, which is none.
Oh hell, I will just give you an example. No, not an example that will finish your homework, but it should guide you in the right direction. It will be from this century and using Linux and NASM.
%include "../../include/syscalls64.inc" ;%define INPUT_LEN 12 section .data szPassword db "HELLO HUMAN" INPUT_LEN equ $ - szPassword szEqual db `String is OK!\n` szEqual_Len equ $ - szEqual szNotEqual db `String not OK!!!\n` szNotEqual_Len equ $ - szNotEqual section .bss lpBuffer resb INPUT_LEN + 1 global main section .text main: .GetInput: mov r15, 0 ; zero loop counter mov r14, lpBuffer ; buffer to store input .GetChar: mov rdx, 1 ; read 1 character lea rsi, [rsp] ; use stack as temp char buffer mov rdi, stdin ; mov rax, sys_read ; syscall ; cmp byte [rsp], 10 ; input done? je .EndInput ; yes mov al, byte [rsp] ; store char mov [r14 + r15], al ; to our buffer add r15, 1 ; increament our loop counter jmp .GetChar .EndInput: mov r15, 0 ; zero counter/pointer index mov r13, szPassword ; get pointer to password string .Compare: mov al, [r13 + r15] ; get char from password string cmp [r14 + r15], al ; compare it with char from entered string jne .NoMatch ; if no equal, quit loop and inform user add r15, 1 ; increament counter cmp r15, INPUT_LEN - 1 ; make sure we don't read past our buffer end jle .Compare mov rdx, szEqual_Len mov rsi, szEqual jmp done .NoMatch: mov rdx, szNotEqual_Len mov rsi, szNotEqual done: mov rdi, stdout mov rax, sys_write syscall mov rdi, 0 mov rax, sys_exit syscall
Posted 13 Mar 2015On line 30, your using ebp as an index into your array. You never initialize ebp with any value, so your indexing your array out of bounds. Why are you using ebp anyway? It is a special register.
Posted 12 Mar 2015Shouldn't it be: ./nameofexe
Posted 9 Mar 2015*** moved to Assembly ***
Over commenting is just as bad as no comments.
We know that [il] push ecx[il] saves a value to the stack, what is in ecx that we want to save and why are we saving it?
What is at the pointer on eax that we are moving into dl?
Why are we rolling dl to the right 4 times?
Stuff like that etc... Unless those comments are there and I cannot see them on my cell phone, comments describe what the code is doing and why. This helps others when the look at your code, and so you can look at your code in the future and know how and why it was done, also for debugging
Posted 7 Mar 2015Unlike C code, Assembly is OS and CPU dependent. What CPU architecture is this code for?
When it comes to displaying something on screen, the OS is important as system calls on *nix won't work on Windows and vise versa. What OS are you using?
Another important thing is syntax, what Assembler are you using?
- Member Title:
- "Hurry up and wait"
- 40 years old
- June 30, 1974
- In my head
- Forum Leader:
- Full Name:
- Years Programming:
- Programming Languages:
- x86 Win32 Assembly (MASM, FASM, NASM)