Reputation: 899 Master
- Active Posts:
- 2,473 (1.65 per day)
- 28-March 11
- Profile Views:
- Last Active:
- 57 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 2 May 2015It's almost 1 am, I will write a good reply that should help you, in about 9 or so hours.
Posted 2 May 2015That is because you are using the same buffer (address) for all of the reads. There are a few ways to do this, how do you thing it can be done using a different buffer address for each new ReadString? Then do the same thing for WriteString.
Posted 24 Apr 2015Your variables num1 and num2 are declared wrong. Your declaring them as WORDS (DW = Define WORD), instead you should define them as doublewords (DD = Define DOUBLEWORD).
Posted 31 Mar 2015First off a 64 bit System has well, 64 bit libraries. Since the calling conventions and other things are different, you will need to install the 32bit libraries. Not at a computer so can't gives you my links, but search for and install gcc-multiarch (I think that is what it is called)
Next, it really isn't an exe without a loader, since you are using ld instead of gcc, you need to tell ld what loader to use. (search for ld 32bit loader on 64 bit Linux)
Don't use start as your entry point, just use main and make it global.
Your variables and externs should not be in the text section!
Lines 3 and 5 should be in the .data section
Line 4 should be in the .bss section
Lines 6 and 7 should not be in any archon.
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
- 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)