0% found this document useful (0 votes)
31 views6 pages

Assignment No.4 1

This document contains an assignment to write a 64-bit assembly language program (ALP) that accepts two numbers from the user and displays the addition result. It includes the name, student details, title, theory explaining the instructions used, and the code with comments. The code accepts the two numbers as input, converts them from ASCII to hexadecimal, performs addition, converts the result back to ASCII, and displays it.
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)
31 views6 pages

Assignment No.4 1

This document contains an assignment to write a 64-bit assembly language program (ALP) that accepts two numbers from the user and displays the addition result. It includes the name, student details, title, theory explaining the instructions used, and the code with comments. The code accepts the two numbers as input, converts them from ASCII to hexadecimal, performs addition, converts the result back to ASCII, and displays it.
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/ 6

Name: Kiran Suryakant Khamkar

PRN No.: 22210084


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

ASSIGNMENT NO.4

TITLE: Write 64-bit ALP to accept the numbers from user and
perform addition of 2 numbers and display the result on screen.
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. db: This directive is used to declare a byte in the data section.
3. section .bss: This section is used for declaring uninitialized data that
will be modified during the execution of the program.
4. resq: This directive is used to reserve space for a quadword (64 bits)
in the bss section.
5. section .text: This section is used for writing the actual code of the
program.
6. global _start: This line makes the entry point of the program labeled
as _start globally visible.
7. mov: This instruction is used to move data between registers and
memory.
8. syscall: This instruction is used to make a system call to the
operating system.
9. equ: This directive is used to define a constant.
10. _start: This is the entry point of the program, where the
program execution begins.
11. rax, rdi, rsi, rdx: These are general-purpose registers used for
various purposes, such as storing data, addresses, or parameters for
system calls.
12. xor: This instruction is used for bitwise XOR operation.
13. resb: This directive is used to reserve space for a specified
number of bytes in the bss section.
14. 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-


section .data
msg db "Enter two digit Number: ",10
msg_len equ $-msg
res db 10,"Addition of numbers is: "
res_len equ $-res

section .bss
num resb 03
num1 resb 01
result resb 04

section .text

%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

global _start

_start:
xor rax,rax
xor rbx,rbx
xor rcx,rcx
xor rdx,rdx
mov byte[result],0
mov byte[num],0
mov byte[num1],0
print msg, msg_len
read num,3
call convert
mov [num1],bl
print msg, msg_len
read num,3
call convert
xor rcx,rcx
xor rax,rax
mov rax,[num1]
add rax, rbx
mov [result],rax
print res, res_len
mov rbx,[result]
call display
mov rax,60
mov rdi,0
syscall

convert: ; ASCII to Hex conversion


xor rbx,rbx
xor rcx,rcx
xor rax,rax
mov rcx,02
mov rsi,num
up1:
rol bl,04
mov al,[rsi]
cmp al,39h
jbe p1
sub al,07h
jmp p2
p1: sub al,30h
p2: add bl,al
inc rsi
loop up1
ret

display: ; Hex to ASCII conversion


mov rcx,4
mov rdi,result
dup1:
rol bx,4

mov al,bl
and al,0fh
cmp al,09h
jbe p3
add al,07h
jmp p4
p3: add al,30h
p4:mov [rdi],al
inc rdi
loop dup1

print result,4
ret

• SCREENSHOT OF OUTPUT-

You might also like