Assignment No.5 1
Assignment No.5 1
ASSIGNMENT NO.5
TITLE: Write 64-bit ALP to convert HEX 4-digit input to BCD 5-digit
output.
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. _start: This is the entry point of the program, where the
program execution begins.
11. rax, rdi, rsi, rdx, rbx: These are general-purpose registers used
for various purposes, such as storing data, addresses, or parameters
for system calls.
12. cmp, jl, jle: These are conditional jump instructions used for
comparison and branching based on the comparison result.
13. add, sub, mul, inc: These are arithmetic instructions used for
addition, subtraction, multiplication, and incrementing.
section .data
m1 db "Enter 4 digit HEX Number:", 10 ,13
l1 equ $-m1
section .bss
buff resb 6
digitcount resb 1
char_ans resb 4
section .text
global _start
_start:
scall 1,1,m1,l1
scall 0,0,buff,5
call acc_proc
mov ax,bx
call h2bproc
;==========================Exit========================
mov rax,60
mov rdi,0
syscall
h2bproc:
mov rbx,0Ah
back:
xor rdx,rdx
div rbx
push dx
inc byte[digitcount]
cmp rax,0h
jne back
scall 1,1,m2,l2
print_bcd:
pop dx
add dl,30h
mov [char_ans],dl
scall 1,1,char_ans,1
dec byte[digitcount]
jnz print_bcd
ret
acc_proc:
xor bx,bx
mov rcx,4
mov rsi,buff
next_digit:
shl bx, 4
mov al,[rsi]
cmp al,39h
jbe label1
sub al,07h
label1:
sub al,30h
add bx,ax
inc rsi
loop next_digit
ret
• SCREENSHOT OF OUTPUT-