I have a c funtion that receives a character and an integer as parameter and shift that character using the integer. So let's say the character is "a" and the integer is 2 it will return "c". What I need to do is to get the string and the number of shifts from the user in assembly. Then call my function and return the encrypted word. So if the word is Love and the number of shifts is 2 the word will become Nqxg.
I am having the worst time doing this. No idea what to do I have tried so many things already.
When I run just come the first Letter. So at least something is working. I am sure is about the size, I am very new to assembly and still trying to understand how the register work. I also don't know how to append my characters to my string
Can anyone please try to fix my shift subroutine? Thank you
That's what I have:
extern printf, scanf
extern encrypt
global _start
section .data
format db '%ld',0
format3 db "%s ",0
message1: db "1. Input New Message",10,0
message2: db "Enter a number of shift:",10,0
section .bss
getMessage: resq 1
shiftNum resq 1
encrypted resq 1
len: equ $ - getMessage
base: equ getMessage - 4
section .text
global main
main:
mov rdx, message1
call print
call scanMessage
mov rdx, message2
call print
call scanChoice
mov rdx, getMessage
call print
mov r8, getMessage
mov rbx, [shiftNum]
mov rdx, len
call shift
mov rdx, encrypted
call print
ret
; end main
scanChoice: ;getting the year from user
mov rdi, format
mov rsi, shiftNum
mov rax, 0 ;no xmm registers
call scanf ;calling c function to get input from user
ret
scanMessage:
mov rax, 0
mov rdi, 0
mov rsi, getMessage
mov rdx, len
syscall
ret \
print:
mov rdi,format3
mov rsi,rdx
mov rax,0
call printf
ret
shift:
mov rcx, 0
loop: cmp rcx, rdx ;comparing string length with rcx
jge done
mov rdi, [r8+ rcx*4]
mov rsi, rbx ;number of shifts
call encrypt
mov [encrypted+rcx*4], rax ;appending to string
inc rcx
jmp loop
done:
ret
My output:
1. Input New Message
Hello
Enter a number of shift:
4
Hello
L
->that's what is coming instead of Lipps which would be each letter from Hello shifted 4 times