GunnerInc's Profile User Rating: *****

Reputation: 897 Master
Group:
Moderators
Active Posts:
2,469 (1.69 per day)
Joined:
28-March 11
Profile Views:
58,441
Last Active:
User is online 25 minutes ago
Currently:
Viewing Board Index

Previous Fields

Country:
US
OS Preference:
Linux
Favorite Browser:
Opera
Favorite Processor:
AMD
Favorite Gaming Platform:
Classic
Your Car:
Who Cares
Dream Kudos:
1650
Expert In:
Assembly

Latest Visitors

Icon   GunnerInc Please don't bother PM'ing me for help!! Post your questions in the correct forum for all to benifit from!!!

Posts I've Made

  1. In Topic: 8086 RET Not working

    Posted 25 Mar 2015

    Quote

    The 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
    17
    18 CMP AL, 13
    19 JE END_INPUT
    20
    21 MOV [SI], AL
    22 ADD SI, 1
    23 JMP INPUT
    24 END_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
    29
    30 CHECK_STRING:
    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
    
    
  2. In Topic: Code keeps crashing

    Posted 13 Mar 2015

    On 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.
  3. In Topic: -bash: main: command not found

    Posted 12 Mar 2015

    Shouldn't it be: ./nameofexe
  4. In Topic: Assembly Code - How to comment properly?

    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
  5. In Topic: How to use arrays

    Posted 7 Mar 2015

    Unlike 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?

My Information

Member Title:
"Hurry up and wait"
Age:
40 years old
Birthday:
June 30, 1974
Gender:
Location:
In my head
Interests:
Assembly
Forum Leader:
Assembly
Full Name:
Rob
Years Programming:
25
Programming Languages:
x86 Win32 Assembly (MASM, FASM, NASM)

Contact Information

E-mail:
Click here to e-mail me
Website URL:
Website URL  http://www.gunnerinc.com
Skype:
Skype  gunner.inc
Facebook:
http://www.facebook.com/gunnerinc

Comments

Page 1 of 1
  1. Photo

    BenignDesign Icon

    06 May 2013 - 06:44
    How goes things, sunshine?
  2. Photo

    BenignDesign Icon

    02 Nov 2012 - 20:34
    :)
  3. Photo

    codeprada Icon

    25 Jun 2012 - 07:11
    Congratz on Mod status. Seems like I'm really late to this party. Better late than never right. =D
  4. Photo

    GunnerInc Icon

    26 May 2012 - 18:21
    Thanks No2, it was totally unexpected! Honored really!
  5. Photo

    no2pencil Icon

    26 May 2012 - 18:12
    Welcome to the team!
  6. Photo

    DimitriV Icon

    20 Nov 2011 - 19:22
    Good on you man, you are a DIC ++. That's skilled.
  7. Photo

    ishkabible Icon

    17 Oct 2011 - 13:33
    congratz!! if you get 15 rep this month(only 5 away!!) you can also get the assembly award!
  8. Photo

    Gungnir Icon

    17 Oct 2011 - 06:42
    Congratulations on becoming an expert!!
  9. Photo

    ishkabible Icon

    12 Oct 2011 - 18:36
    hey, i was about tell you how good a job you were doing then i saw i already had :P
  10. Photo

    GunnerInc Icon

    08 Oct 2011 - 08:04
    HeHe, thanks!
  11. Photo

    ishkabible Icon

    07 Oct 2011 - 21:05
    keep up the awesome work in the assembly forums! you're really doing an awesome job!
Page 1 of 1