0% found this document useful (0 votes)
3 views3 pages

Prac 2

This document contains an assembly language program written for X86/64 architecture that accepts a string input from the user and displays its length. It includes sections for data, BSS, and text, and utilizes system calls for input and output operations. The program also includes a function to convert the length from integer to string format for display.

Uploaded by

Paras Kamble
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)
3 views3 pages

Prac 2

This document contains an assembly language program written for X86/64 architecture that accepts a string input from the user and displays its length. It includes sections for data, BSS, and text, and utilizes system calls for input and output operations. The program also includes a function to convert the length from integer to string format for display.

Uploaded by

Paras Kamble
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/ 3

PRACTICAL NO.

02

Name:- Swapnil
Suryavanshi
Roll No:- S213074
Div:- C
Batch:- C2

Problem Statement:-
Write an X86/64 ALP to accept a string and to display its length.

Program:-
section .data
msg1 db "Enter a string: ", 0
len1 equ $ -msg1
newline db 10,0
msg2 db "Length of string: ", 0
len2 equ $ -msg2

section .bss
input resb 128
len_result resb 40

section .text
global _start
_start:
mov rax, 01
mov rdi, 01
mov rsi, msg1
mov rdx, len1
syscall

mov rax, 00
mov rdi, 00
mov rsi, input
mov rdx, 128
syscall

mov rcx, rax


dec rax
lea rsi, [len_result]
call int_to_str
mov rax, 01
mov rdi, 01
mov rsi, msg2
mov rdx, len2
syscall
mov rax, 01
mov rdi, 01

mov rsi, len_result


mov rdx, rdi
syscall
mov rax, 01
mov rdi, 01
mov rsi, newline
mov rdx, 1
syscall
mov rax, 60
xor rdi,rdi
syscall

int_to_str:
xor rbx, rbx
mov rdi, 10
convert_loop:
xor rdx, rdx
div rdi
add dl, '0'
push rdx
inc rbx
test rax,rax
jnz convert_loop
write_digits:
pop rax
mov byte[rsi],al
inc rsi
dec rbx
jnz write_digits
mov byte[rsi],0
ret
Output:-

You might also like