Skip to main content

Bin to hex converter in 16-bit DOS assembly

Just a quick code like putting your keyboard where your brain is. There should be another way of doing this. I hate this code.



start:
xor al, al
xor bl, bl
xor cl, cl
mov dl, 4 ; use dl as counter

input:
mov ah, 00
int 16h
cmp ah, 1ch
je exit
cmp al, '0'
jb input
cmp al, '1'
ja input

convert:
mov cl, dl
dec cl ; dl - 1
sub al, 30h ; get original value
shl al, cl ; place in the appropriate bit position
or bl, al ; save in bl
dec dl ; prepare for the next bit
jnz input ; must be 4 bits
cmp bl, 9
ja letter
jbe number

letter:
add bl, 37h ; because 'A' - 37h is 0Ah
jmp here

number:
add bl, 30h ; because '0' - 30h is 00h

here:
call display
jmp start

display:
mov ah, 02h
mov dl, bl
int 21h
ret

exit:
int 20h

Try this out, get the assembler here.

Comments

Popular posts from this blog

Architecture Complexity

Here are the items to consider: Coding to an interface Service Oriented Architecture Automated Testing Domain Driven Design Custom Data Access Layer Layered architecture Complexity is relatively equal the number of lines of code. Note that complexity is not bad. It must be justified.

Repair Windows 7 System Files

8 out of 10 average PC users have their box’s system files altered by malwares, viruses, etc. We usually reinstall the OS if the antivirus and anti malware software did not perform their job well. Here’s one way to fix the corrupted system files without the need of restarting your Windows 7 box. 1. Run the Command Prompt as Administrator 2. Type the following command C:\Windows\system32\> sfc /scannow 3. After the verification phase, you will receive a message about your system files’ integrity Windows Resource Protection did not find any integrity violations.