Assignment No.4 1
Assignment No.4 1
Assignment No.4 1
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.
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
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-