Assembler Developer

Moderators: None (Apply to moderate this forum)
Number of threads: 1030
Number of posts: 1826

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
8086, hex to decimal program Posted by jamespond8 on 31 Mar 2009 at 1:28 PM
Hi im trying to make a program to the following specifications:

0) initialise a temporary numerical value to 00H, base value to 10H and count value to 00H
1) Read in a character
2) Apply series of checks against ‘0’-‘9’ and ‘A’-‘F’ and convert the digit to a numerical value as described above
3) multiply our temporary numerical value by the base (10H) – remember that mul multiplies the src with what is in AL or AX so we need to make sure that the temporary numerical value is moved into AX before we multiply and since AL contains our digit numerical value we will need to push AX to save it for use later - use version b) of mul i.e. src is 16 bit, result in high word in DX (we will discard this) and low word in AX (which we will use). We can safely multiply by the base the first time round as the temporary numerical value will start out as initilised to 0.
5) pop AX so we can get the new numerical digit value and add it to the temporary numerical value
6) increment count of digits converted and go back to 1)

Note – you will also need to echo the digit characters input, but you should ignore i.e. not echo, the non-hex digit termination character.


Using the above write the code to input a hex number of up to a word in size as a subroutine called GetHex in Stdio.asm.
The return numerical value should be in DX and the count of the number of digits converted should be in CX.

You can use the subroutine Getch to read the characters. You should echo the character typed in using Putch, but since Putch expects the character to be output in DL, you may need to save DX onto the stack before using Putch and pop DX after using Putch. Do not echo the termination character – simply discard it.

You can check this works by calling GetHex from your main code and then checking the result using debug.




and well my problem is that im finding it hard to convert the number to hex. I have got the read character , echo character and the if statements to ensure that the character is a hex number valid.


MOV BL, 10h ; sets the base value to 10h

	Number:    		   
	    sub al, 30h
	    mov ch,al                
		JGE Continue ;jump to Continue , if true
		
	Letter: 
	    sub al, 31h
		mul,BL ; bl*AL  so 16*al
		JGE Continue ;jump to Continue , if true	

	Continue: 
		inc cx ; CX counts the amount of converted 



the code above atm gets the decimal value for instance if the character 'A' has been input it would get to the Letter label and then have 31h taking from it (41-31=10) so it converts the character to decimal. if '1' is input it goes to the number label and takes 30h from it (31h-30=1). :) what i am stuck with is then converting the decimal values back into hex because im meant to allow up to 4 hex characters to be input soo i could have '1F2A' how could i convert that to hexadecimal because i know you use powers and stuff to convert dec to hex.. I have been trying for about 5 hours to get this to work i just cant get my head around it . can you guys help me please

thanks soo much






Report
Re: 8086, hex to decimal program Posted by fangxi on 2 Apr 2009 at 11:12 AM
for decimal to hex you can just divide your number by 16 until it is 0, the remainder is the value of hex
ex: our decimal is 32
 
32/16 = 2 R 0
2/ 16 = 0 R 2
0/16 = 0 R 0

your hex is 020

the general format is base * digit ^ n-1 (n is the the position ones digits= 1 , tens digit = 2...etc)

which you can use to check your conversion





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.