0

Basically I am trying to compare two strings in assembly, see code below:

global _start
section .data
    hello: db "Enter Message> ", 15
    pass: db "password", 8
section .bss
    input:  resq 100

section .text
    mov eax, 4
    mov ecx, hello
    mov edx, 15
    int 0x80

    mov eax, 3
    mov ecx, input
    mov edx, 100
    int 0x80

    mov esi, input
    mov edi, pass
    cmp esi, edi
    jne nprinting
    je  printing

printing:
    mov eax, 4
    mov ecx, input
    mov edx, 100
    int 0x80    

    mov eax, 1
    int 0x80

nprinting:
    mov eax, 1
    int 0x80    

either way if I enter incorrect or password in my input prompt, the program exits without prompting me anything. I also tried something like:

mov bh, "a"
mov bl, "a"
cmp bh, bl
je  printing
jne nprinting

but still didn't get to print me my input value. not sure if the problem is null-terminated or something else.

I am using Kali-Linux x64: Linux kali 4.19.0-kali3-amd64 #1 SMP Debian 4.19.20-1kali1 (2019-02-14) x86_64 GNU/Linux.

And compile the program as following: nasm -f elf64 -g ./hello.asm && ld -s -o hello ./hello.o Appreciate a little help.

1201ProgramAlarm
  • 32,384
  • 7
  • 42
  • 56
creepy
  • 39
  • 5
  • 2
    You are comparing the pointers, that will never work. You will need to loop and compare char-by-char (or use `repe cmpsb`). Your second try with comparing `a` to `a` should have worked though. PS: see also [What happens if you use the 32-bit int 0x80 Linux ABI in 64-bit code?](https://stackoverflow.com/questions/46087730/what-happens-if-you-use-the-32-bit-int-0x80-linux-abi-in-64-bit-code) PPS: you forgot to define `_start`. – Jester Feb 03 '20 at 01:08
  • @jester can you tell how to use `repe cmpsb`? – creepy Feb 03 '20 at 01:18
  • 2
    Since it seems you are just starting out, you should probably just write the loop instead of using an advanced instruction like repe cmpsb. – Raymond Chen Feb 03 '20 at 04:37

0 Answers0