0% found this document useful (0 votes)
13 views4 pages

4085 Cao Ass6

The document provides instructions for writing a 64-bit assembly language program to perform string operations including calculating the length of a string and reversing a string, describing the code sections, variables, functions used, and providing the full code with comments explaining each step. It takes user input of a string, calculates the length, converts the length to hexadecimal and reverses it, reverses the original string by copying characters in reverse order, and exits the program displaying the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views4 pages

4085 Cao Ass6

The document provides instructions for writing a 64-bit assembly language program to perform string operations including calculating the length of a string and reversing a string, describing the code sections, variables, functions used, and providing the full code with comments explaining each step. It takes user input of a string, calculates the length, converts the length to hexadecimal and reverses it, reverses the original string by copying characters in reverse order, and exits the program displaying the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Assignment-06

Name : Manasi bharati


Roll no. : 224085
PRN NO : 22320136
Class : Comp SY-D2
Subject : Computer Architecture and Organization

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


i) Length of String
ii)Reverse of String
Theory:

1.Description of Instructions used in this code.


In this code:
1. The strlen function calculates the length of the input string.
2. The reverse_string function reverses the input string and stores the result in the
output_string variable.
3. The program uses call to call these functions, and the results are stored in the len variable
for the length and output_string for the reversed string.
Make sure to replace the input_string with your desired string. To assemble and run the program,
you would typically use an assembly language development environment and a suitable linker
and loader, as well as a 64-bit capable operating system.
a. Macro scall:
Defines a macro to simplify system calls by setting up the registers rax, rdi, rsi, and rdx
with provided arguments before invoking a syscall.

b. .data Section:
Contains several strings used for user prompts and messages.
m1 prompts the user to enter a string.
m2 is for displaying the length of the string.
m3 will be used for displaying the reversed string.

c. .bss Section:
Reserves memory for various variables and buffers.
string is allocated 50 bytes to store the user's input string.
string2 is allocated 50 bytes to store the reversed string.
length is allocated 16 bytes for storing the length of the input string.
answer is allocated 16 bytes for displaying results.

d. .text Section:
The main code section.
global _start:
Declares the _start label as the entry point for the program.

e. Accept String:
Prompts the user to enter a string and stores it in the string buffer.
Calculates the length of the string and stores it in the length variable.

f. Display Procedure:
Converts the length of the string to its hexadecimal representation and stores it in the
answer buffer.
Reverses the hexadecimal representation in place.

g. Reverse String:
Reverses the original string by copying characters from string to string2 in reverse order.

h. Exit the Program:


Uses a system call to exit the program with a status of 0.

2) 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: "
l1 equ $-m1
m2 db 10d,"Length of String: "
l2 equ $-m2
m3 db 10d,"Reversed String: "
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

3) Screen shot of output.

You might also like