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

Assignment No.5 1

This document contains an assignment to write a 64-bit assembly language program (ALP) to convert a 4-digit hexadecimal input into a 5-digit binary coded decimal (BCD) output. It includes the title, theory explaining the instructions used, and the code with comments to perform the conversion. The code accepts the hex input, calls procedures to process it and convert to BCD, and exits the program.
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)
68 views6 pages

Assignment No.5 1

This document contains an assignment to write a 64-bit assembly language program (ALP) to convert a 4-digit hexadecimal input into a 5-digit binary coded decimal (BCD) output. It includes the title, theory explaining the instructions used, and the code with comments to perform the conversion. The code accepts the hex input, calls procedures to process it and convert to BCD, and exits the program.
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.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.

• CODE WITH COMMENTS-


%macro scall 4
mov rax,%1
mov rdi,%2
mov rsi,%3
mov rdx,%4
syscall
%endmacro

section .data
m1 db "Enter 4 digit HEX Number:", 10 ,13
l1 equ $-m1

m2 db "Corresponding BCD is:", 10 ,13


l2 equ $-m2

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

;================HEX TO BCD PROCEDURE===============

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

;==================== ACCEPT PROCEDURE =================

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-

You might also like