0% found this document useful (0 votes)
9 views4 pages

MPL 6

The document is an assembly language program that implements a menu-driven code conversion tool for converting between hexadecimal and BCD (Binary-Coded Decimal) formats. It includes procedures for displaying messages, accepting user input, and performing the conversions. The program allows users to choose between converting Hex to BCD, BCD to Hex, or exiting the application.
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)
9 views4 pages

MPL 6

The document is an assembly language program that implements a menu-driven code conversion tool for converting between hexadecimal and BCD (Binary-Coded Decimal) formats. It includes procedures for displaying messages, accepting user input, and performing the conversions. The program allows users to choose between converting Hex to BCD, BCD to Hex, or exiting the application.
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/ 4

Assignment 6

section .data
msg1 db 10,10,'###### Menu for Code Conversion######',10,'1: Hex to
BCD',10,'2: BCD to Hex',10,'3: Exit',10,10,'Enter Choice:'
msg1length equ $-msg1
msg2 db 10,10,'Enter 4 digit hex number:',10
msg2length equ $-msg2
msg3 db 10,10,'BCD Equivalent:',10
msg3length equ $-msg3
msg4 db 10,10,'Enter 5 digit BCD number:',10
msg4length equ $-msg4
msg5 db 10,10,'Wrong Choice Entered....Please try again!!!',10,10
msg5length equ $-msg5
msg6 db 10,10,'Hex Equivalent:',10
msg6length equ $-msg6
cnt db 0

section .bss
arr resb 06 ; buffer for choice, hex, and bcd input
dispbuff resb 08 ; buffer to display results
ans resb 01 ; buffer to store individual answers (BCD digit or
HEX)

%macro disp 2
mov rax,01
mov rdi,01
mov rsi,%1
mov rdx,%2
syscall
%endmacro

%macro accept 2
mov rax,0
mov rdi,0
mov rsi,%1
mov rdx,%2
syscall
%endmacro

section .text
global _start

_start:
menu:
disp msg1,msg1length
accept arr,2 ; choice (1,2,3 + Enter)
cmp byte [arr],'1'
jne l1
call hex2bcd_proc
jmp menu

l1:
cmp byte [arr],'2'
jne l2
call bcd2hex_proc
jmp menu

l2:
cmp byte [arr],'3'
je exit
disp msg5,msg5length
jmp menu

exit:
mov rax,60 ; syscall number for exit
mov rbx,0 ; exit code 0
syscall

hex2bcd_proc:
disp msg2,msg2length
accept arr,5 ; Accept 4 digits (HEX) + Enter
call conversion
mov rcx,0
mov ax,bx
mov bx,10 ; Base of Decimal No. system (10 for decimal)

l33:
mov dx,0
div bx ; Divide AX by BX (HEX -> BCD)
push rdx ; Push remainder (BCD digit) onto stack
inc rcx
inc byte [cnt]
cmp ax,0
jne l33

disp msg3,msg3length

l44:
pop rdx ; Pop remainder (BCD digit) from stack
add dl,30h ; Convert digit to ASCII
mov [ans],dl
disp ans,1
dec byte [cnt]
jnz l44
ret

bcd2hex_proc:
disp msg4,msg4length
accept arr,6 ; Accept 5 digits (BCD) + Enter
disp msg6,msg6length
mov rsi,arr
mov rcx,05
mov rax,0
mov ebx,0ah ; Base of Decimal system

l55:
mov rdx,0
mul ebx ; Multiply EBX with EAX (resulting in EDX:EAX)
mov dl,[rsi]
sub dl,30h ; Convert ASCII to BCD
add rax,rdx ; Add BCD digit to result
inc rsi
dec rcx
jnz l55

mov ebx,eax ; Store the result in EBX


call disp32_num
ret

conversion:
mov bx,0
mov ecx,04
mov esi,arr
up1:
rol bx,04
mov al,[esi]

cmp al,39h
jbe l22
sub al,07h
l22: sub al,30h
add bl,al
inc esi
loop up1
ret

disp32_num:
mov rdi,dispbuff
mov rcx,08 ; Since the number is 32-bit, we need 8 digits
l77:
rol ebx,4
mov dl,bl
and dl,0fh
add dl,30h
cmp dl,39h
jbe l66
add dl,07h
l66:
mov [rdi],dl
inc rdi
dec rcx
jnz l77

disp dispbuff+3,5 ; Display only lower 5 digits (upper 3 are '0')


ret

You might also like