Untitled
unknown
plain_text
3 months ago
5.5 kB
6
Indexable
section .data
m1 db 10,"Equivalent decimal number is: "
m1len equ $- m1
newline db 10,10
newlinelength equ $-newline
hex dw 0ffffh
section .bss
buf resb 6
buf_len equ $-buf
digitcount resb 1
ans resw 1
char_ans resb 4
%macro display 2
mov rax,1
mov rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endmacro
section .text
global _start
_start:
mov rax,[hex]
mov rbx,10 ; rbx is loades with 10decimal , which is divisor
back: xor rdx,rdx ; make rdx=0
div rbx ; divide rdx:rax by rbx
push dx ; Remainder in dx is stored in stack
inc byte[digitcount] ; keep count of remainder digits
cmp rax,0h ; compare quotient in rax with 0
jne back ; as long as, it is not zero , repeat
; else go to next instruction
display m1, m1len ; display message "Equivalent decimal number is: "
display_decimal: ; part of program which displays decimal number
pop dx ; take a BCD digit stored in stack & copy in dx
add dl,30h ; possible BCD digits are 0-9 so add 30H only
mov [char_ans],dl ; store character in char_ans
display char_ans,1 ; print on screen in reverse order ( last remainder is
; displayed first
dec byte[digitcount] ; repeat till all BCD digits are not displayed
jnz display_decimal
display newline , newlinelength
mov rax, 60 ; system call 60 is exit
mov rdi,0
syscall )Editor is loading...
Leave a Comment