I'm currently learning Assembly (Intel x64) for my machine (Ubuntu if that matters). (Mind you, it isn't NASM).
For the life of me, I can't find a way to compare a register to a char. Here's my code:
.global _start
.intel_syntax noprefix
_start:
// Print Question
mov rax, 1
mov rdi, 1
lea rsi, [.the_ask]
mov rdx, 28
syscall
// Load Input into memory
mov rax, 0
sub rsp, 8
mov rdi, 0
lea rsi, [rsp]
mov rdx, 1
syscall
// Print Newline
mov rax, 1
mov rdi, 1
lea rsi, [.newline]
mov rdx, 2
syscall
// Comparison (hopefully)
lea r8, [.dogletter]
lea r9, [.catletter]
cmp rsp, r9
je _docatstuff
cmp rsp, r8
je _dodogstuff
// Exit
mov rax, 60
mov rdi, 1
syscall
_docatstuff:
// meow at user
mov rax, 1
mov rdi, 1
lea rsi, [.catstuff]
mov rdx, 4
syscall
// newline
mov rdx, 2
lea rsi, [.newline]
syscall
// exit
mov rax, 60
mov rdi, 0
syscall
_dodogstuff:
// bark at user
mov rax, 1
mov rdi, 1
lea rsi, [.dogstuff]
mov rdx, 4
syscall
//newline
mov rdx, 2
lea rsi, [.newline]
syscall
//exit
mov rax, 60
mov rdi, 0
syscall
.the_ask:
.asciz "Please Enter: (c)at, (d)og: "
.newline:
.asciz "\n"
.catletter:
.asciz "c"
.dogletter:
.asciz "d"
.catstuff:
.asciz "meow"
.dogstuff:
.asciz "woof"
I already know my implementation is wrong, I want to know how to implement this correctly please.
Any help would be greatly appreciated!
What I've Tried: Comparing like: cmp rsp, "c"
, Comparing rsp
to the ASCII value of the letter: cmp rsp, 67
, and I have lastly tried the attempt that you see in my current source code.