Labels

Monday 7 November 2016

Write X86/64 ALP for the following operations on the string entered by the user. (use of 64-bit registers is expected).

Write X86/64 ALP for the following operations on the string entered by the user. (use of 64-bit registers is
expected)
a) Calculate Length of the string b) Reverse the string
c) Check whether the string is palindrome
OR
Make your program user friendly by providing MENU like:
(a) Enter the string b) Calculate length of string c) Reverse string d) Check palindrome e) Exit
Display appropriate messages to prompt the user while accepting the input and displaying the result.

section .data
msg1 db "welcome to string operations",10
len1: equ $-msg1

msg2 db "Enter your choice",10
len2: equ $-msg2

msg3 db "1.Input a string",10,"2.calculate length of string",10,"3.Reverse input string",10,"4.to check string is palindrom ",10,"5.exit",10
len3: equ $-msg3

def db 10,"=================================================",10
ledef: equ $-def

msgask db 10,"Do you want to continue?(press 1 for yes)",10
lenask: equ $-msgask

inp db "Enter the string",10
inplen: equ $-inp

msg4 db "Length of string is:",10
len4: equ $-msg4

msg5 db "Reverce string is:",10
len5: equ $-msg5

msg6 db "Given string is palindrom",10
len6: equ $-msg6

msg7 db "Given string is not palindrom",10
len7: equ $-msg7

msglast db"Thank You for using string operation",10
lenlast: equ $-msglast


section .bss

n resb 2
ask resb 2
len resb 3
leng resb 1
arr1 resb 20
arr2 resb 20
arr3 resb 20

%macro disp 2
mov rax,01
mov rdi,01
mov rsi,%1
mov rdx,%2
syscall
%endmacro

%macro inn 2
mov rax,00
mov rdi,00
mov rsi,%1
mov rdx,%2
syscall
%endmacro


section .text
global _start
_start:

disp msg1,len1
again:
disp def,ledef
disp msg2,len2
disp msg3,len3
inn n,02

cmp byte[n],31h
jne op2
call procinp
disp msgask,lenask
inn ask,02
mov rsi,ask
cmp byte[rsi],31H
jz again

op2:
cmp byte[n],32h
jne op3
call procal
disp msgask,lenask
inn ask,02
mov rsi,ask
cmp byte[rsi],31H
jz again

op3:
cmp byte[n],33h
jne op4
call procrev
disp msg5,len5
mov rax,01
mov rdi,01
mov rsi,arr2
xor rdx,rdx
mov dl,[leng]
syscall
disp msgask,lenask
inn ask,02
mov rsi,ask
cmp byte[rsi],31H
jz again

op4:
cmp byte[n],34h
jne op5
call procrev
call procpalin
disp msgask,lenask
inn ask,02
mov rsi,ask
cmp byte[rsi],31H
jz again

op5:
disp msglast,lenlast
mov rax,3ch
mov rdi,00
syscall


procinp:
disp inp,inplen
inn arr1,20
mov rsi,len
mov cl,04
mov ch,02
dec al
mov [leng],al
s1:
rol al,cl
mov bl,al
and bl,0fH
cmp bl,09h
jng skip1
add bl,07h
skip1:
add bl,30h
mov [rsi],bl
inc rsi
dec ch
jnz s1
mov byte[rsi],'H'
ret

procal:
disp msg4,len4
disp len,03
ret

procrev:
mov ch,[leng]
mov rsi,arr1
mov rdi,arr2-1
xor rbx,rbx
mov bl,[leng]
add rdi,rbx

up3:
mov al,[rsi]
mov [rdi],al
inc rsi
dec rdi
dec ch
jnz up3
ret


procpalin:

xor rcx,rcx

mov rsi,arr1
mov rdi,arr2
cld
mov cl,[leng]
repe cmpsb
je y
disp msg6,len6
jmp x
y:
disp msg7,len7

x:
ret



No comments:

Post a Comment