0% found this document useful (0 votes)
28 views5 pages

Assignment No.6 1

This document contains an assignment to write a 64-bit assembly language program to perform string operations - calculating the length of a string and reversing a string. It includes the title, theory section explaining the instructions used, code with comments, and expected output. The code takes a string as input, calculates its length and stores it in the length variable, then prints the length and reverses the characters in the string before printing the reversed string.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views5 pages

Assignment No.6 1

This document contains an assignment to write a 64-bit assembly language program to perform string operations - calculating the length of a string and reversing a string. It includes the title, theory section explaining the instructions used, code with comments, and expected output. The code takes a string as input, calculates its length and stores it in the length variable, then prints the length and reverses the characters in the string before printing the reversed string.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Name: Kiran Suryakant Khamkar

PRN No.: 22210084


Roll No.: 221035
Class: SY-A (A2)
Subject: CAO

ASSIGNMENT NO.6

TITLE: Write 64-bit ALP to perform following string operations


i) Length of String
ii)Reverse of String

THEORY:
• DESCRIPTION OF INSTRUCTIONS USED IN THIS CODE –
1. section .data: This section is used for declaring initialized data that
will not be modified.
2. section .bss: This section is used for declaring uninitialized data that
will be modified during the execution of the program.
3. section .text: This section is used for writing the actual code of the
program.
4. global _start: This line makes the entry point of the program labeled
as _start globally visible.
5. mov: This instruction is used to move data between registers and
memory.
6. syscall: This instruction is used to make a system call to the
operating system.
7. db: This directive is used to declare a byte in the data section.
8. resb: This directive is used to reserve space for a specified number
of bytes in the bss section.
9. equ: This directive is used to define a constant.
10. xor: This instruction is used for bitwise XOR operation.
11. cmp, je, inc, jmp, jb: These are conditional and unconditional
jump instructions used for comparison and branching based on the
comparison result.

• CODE WITH COMMENTS-


%macro print 2
mov rax,1 ; Function 1 - write
mov rdi,1 ; To stdout
mov rsi,%1 ; String address
mov rdx,%2 ; String size
syscall ; invoke operating system to WRITE
%endmacro

%macro read 2
mov rax,0 ; Function 0 - Read
mov rdi,0 ; from stdin
mov rsi,%1 ; buffer address
mov rdx,%2 ; buffer size
syscall ; invoke operating system to READ
%endmacro

section .data
m1 db 10d,"Enter String",10d,13d
l1 equ $-m1

m2 db 10d,"Length of String is",10d,13d


l2 equ $-m2

m3 db 10d,"Reversed String",10d,13d
l3 equ $-m3

section .bss
string resb 50
string2 resb 50
length resb 16
answer resb 16
section .text
global _start
_start:

print m1,l1
read string,50
;length is returned in rax
;decrement once to remove count of Enter character
;dec rax

mov [length],rax
print m2,l2
mov rax,[length]
mov rsi,answer+15
mov rcx,16

loop1: mov rdx,0


mov rbx,16
div rbx
cmp dl,09h
jbe skip1
add dl,07h

skip1: add dl,30h


mov [rsi],dl
dec rsi
dec rcx
jnz loop1
print answer,16

mov rsi,string
mov rdi,string2
mov rcx,[length]
add rdi,rcx
dec rdi
loop2:
mov al,[rsi]
mov [rdi],al
dec rdi
inc rsi
loop loop2
print m3,l3
print string2,[length]
mov rax,60
mov rdx,0
syscall

• SCREENSHOT OF OUTPUT-

You might also like