I am new to x86 assembly. I am trying to write a function for multiplication, using the rax, rdi, rsi, and rcx registers. However, I have noticed that it is not working. For 2 * 3, if I increment the right operand by 1, the result goes up by 8. And to begin with, 2 * 3 yielded 26. There is probably something to do with counting a byte wrong here. However, apart from that, I feel like I am in the dark. Does anyone understand what is wrong with my code? This is how I am assembling it: gcc -O0 -g -mstackrealign -masm=intel -o test test.asm
.global _main
.text
end:
mov rax, rdi
ret
plus:
add rdi, rsi
jmp end
minus:
sub rdi, rsi
jmp end
multiply:
add rdi, rcx
sub rsi, 1
cmp rsi, 0
je end
jmp multiply
eq:
cmp rdi, rsi
je true
jmp false
true:
mov rax, 1
ret
false:
mov rax, 0
ret
_main:
push 2
push 4
pop rsi
pop rdi
mov rcx, rsi
call multiply
push rax
mov rdi, rax
mov rax, 0x2000001
syscall